This looks like you're running Lua in a console and not in Toribash. I am not too familliar with that.
What the error means is that the variable output doesn't exist. One reason could be that out.txt doesn't exist and cannot be created (Lua usually creates files if you try to open non existing files with write access). The other reason could be that local variables don't work in the console. Try doing it without "local" infront of "output".
input = io.open("file", "r")
text = input:read("*a")
input:close()
text = string.gsub(text, "wordToReplace", "replacement")
output = io.open("file", "w")
output:write(text)
output:flush()
output:close()
gsub() replaces text so if you wanted to add "\n bar" behind "foo" you have to dotext = string.gsub(text, "foo", "foo\n bar")
equipments = {}
currentEquip = ""
for line in input:lines() do
--[[
if line contains equipment then
-- get the id
equipments[id] = {}
currentEquip = id
elseif line does not contain catalog then
equipments[currentEquip][(string between < and >)] = (string between tags)
end
]]--
end
After that, rewrite the whole file with the information you have.
first = true
-- complete saves the whole text we want to write
complete = ""
-- tmp contains one node
tmp = ""
for line in input:lines() do
--[[ pseudo code
if line containes "equipment"
-- if we find it the first time, there's no node to be saved yet
if first then first = false
else
-- attach the node
complete .. tmp .. "\n"
-- change the node to centimeter
in tmp replace meter with centimeter
in tmp replace "<size>(%d+)" with "<size>%100" -- regular expression
-- attach that part
complete .. tmp .. "\n"
-- change the node to milimeter
in tmp replace centi with mili
in tmp replace "<size>(%d+)" with "<size>%10" -- regular expression
-- attach again
complete .. tmp .. "\n"
end
-- if line is part of node attach to tmp
elseif line doesn't contain catalog and line doesn't contain xml then
tmp .. line .. "\n"
else
-- no part of node, directly attach to complete
complete .. line .. "\n"
end
]]--
end
-- output and close
input:close()
output:write(complete)
output:flush()
output:close()
This assumes that you have a input and a output variable which handle the files.