diff options
author | Anthony Zhang <azhang9@gmail.com> | 2013-06-10 16:40:34 -0400 |
---|---|---|
committer | Anthony Zhang <azhang9@gmail.com> | 2013-06-10 16:40:34 -0400 |
commit | c87bc606358f8727d69bd39b5cacb31c582bb1af (patch) | |
tree | de0b959e5c23c9c1a8c0bd2ec00577599acdda3e | |
parent | 8ea71a9036fb1070ea5478b91ecf26fc40b84e92 (diff) |
Support cyclic references in luacontroller memory tables, prohibit usage of goto statement (bugs reported by Nore).
-rw-r--r-- | mesecons_luacontroller/init.lua | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/mesecons_luacontroller/init.lua b/mesecons_luacontroller/init.lua index 9fa995f..b99b6e4 100644 --- a/mesecons_luacontroller/init.lua +++ b/mesecons_luacontroller/init.lua @@ -127,7 +127,7 @@ end local code_prohibited = function(code) -- Clean code - local prohibited = {"while", "for", "repeat", "until", "function"} + local prohibited = {"while", "for", "repeat", "until", "function", "goto"} for _, p in ipairs(prohibited) do if string.find(code, p) then return "Prohibited command: "..p @@ -139,13 +139,18 @@ local safe_print = function(param) print(dump(param)) end -deep_copy = function(original) --deep copy that removes functions +deep_copy = function(original, visited) --deep copy that removes functions + visited = visited or {} + if visited[original] ~= nil then --already visited this node + return visited[original] + end if type(original) == 'table' then --nested table local copy = {} + visited[original] = copy for key, value in next, original, nil do - copy[deep_copy(key)] = deep_copy(value) + copy[deep_copy(key, visited)] = deep_copy(value, visited) end - setmetatable(copy, deep_copy(getmetatable(original))) + setmetatable(copy, deep_copy(getmetatable(original), visited)) return copy elseif type(original) == 'function' then --ignore functions return nil |