forked from hhrhhr/Lua-utils-for-Rebel-Galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlua2txt.lua
More file actions
48 lines (36 loc) · 998 Bytes
/
Copy pathlua2txt.lua
File metadata and controls
48 lines (36 loc) · 998 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
assert("Lua 5.3" == _VERSION)
local in_file = assert(arg[1], "no input")
local out_file = arg[2]
local out = io.stdout
if out_file then
out = assert(io.open(out_file, "w+"))
end
local function tab(level)
out:write((" "):rep(2 * level))
end
local L, content
local function read_tag(t, l)
tab(l)
out:write("[" .. t.n .. "]")
out:write(" ; vars=" .. (t.vars and #t.vars or 0))
out:write(" tags=" .. (t.tags and #t.tags or 0) .. "\n")
if t.vars then
for k, v in ipairs(t.vars) do
local value = v.v
if v.t == "TRANSLATE" or v.t == "STRING" then
value = L[value][2]
end
tab(l+1)
out:write("<"..v.t..">"..v.n..":"..tostring(value).."\n")
end
end
if t.tags then
for k, v in ipairs(t.tags) do
read_tag(v, l+1)
end
end
tab(l)
out:write("[/" .. t.n .. "]\n")
end
L, content = dofile(in_file)
read_tag(content, 0)