Skip to content

Commit c87bc60

Browse files
committedJun 10, 2013
Support cyclic references in luacontroller memory tables, prohibit usage of goto statement (bugs reported by Nore).
1 parent 8ea71a9 commit c87bc60

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed
 

‎mesecons_luacontroller/init.lua

+9-4
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ end
127127

128128
local code_prohibited = function(code)
129129
-- Clean code
130-
local prohibited = {"while", "for", "repeat", "until", "function"}
130+
local prohibited = {"while", "for", "repeat", "until", "function", "goto"}
131131
for _, p in ipairs(prohibited) do
132132
if string.find(code, p) then
133133
return "Prohibited command: "..p
@@ -139,13 +139,18 @@ local safe_print = function(param)
139139
print(dump(param))
140140
end
141141

142-
deep_copy = function(original) --deep copy that removes functions
142+
deep_copy = function(original, visited) --deep copy that removes functions
143+
visited = visited or {}
144+
if visited[original] ~= nil then --already visited this node
145+
return visited[original]
146+
end
143147
if type(original) == 'table' then --nested table
144148
local copy = {}
149+
visited[original] = copy
145150
for key, value in next, original, nil do
146-
copy[deep_copy(key)] = deep_copy(value)
151+
copy[deep_copy(key, visited)] = deep_copy(value, visited)
147152
end
148-
setmetatable(copy, deep_copy(getmetatable(original)))
153+
setmetatable(copy, deep_copy(getmetatable(original), visited))
149154
return copy
150155
elseif type(original) == 'function' then --ignore functions
151156
return nil

0 commit comments

Comments
 (0)
Please sign in to comment.