-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGlobalVarScope.lua
More file actions
51 lines (50 loc) · 1.37 KB
/
GlobalVarScope.lua
File metadata and controls
51 lines (50 loc) · 1.37 KB
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
49
50
51
function DebugScope()
local inf = io.open("scope.in", "rb");
if (not inf) then
return;
end
inf:close();
local outs = "";
for val in io.lines("scope.in") do
local tbl = Split(val, "%.");
if (_G[tbl[1]] ~= nil) then
if (table.getn(tbl) > 1) then
local tmp = _G[tbl[1]];
tbl[1] = nil;
for _, child in pairs(tbl) do
tmp = tmp[child];
end
outs = outs..val.." - "..tostring(tmp).."\n";
else
outs = outs..val.." - "..tostring(_G[val]).."\n";
end
else
outs = outs..val.." - nil\n";
end
end
local outf = assert(io.open("scope.out", "w"));
outf:write(outs);
outf:close();
end
function Split(s, delimiter, asName)
local result = {}
local from = 1
local delim_from, delim_to = string.find(s, delimiter, from)
while delim_from do
local str = string.sub(s, from, delim_from-1)
if (asName) then
result[str] = true
else
table.insert(result, str)
end
from = delim_to + 1
delim_from, delim_to = string.find(s, delimiter, from)
end
local str = string.sub(s, from)
if (asName) then
result[str] = true
else
table.insert(result, str)
end
return result
end