diff options
author | cheapie <no-email-for-you@example.com> | 2022-01-01 19:11:08 -0600 |
---|---|---|
committer | cheapie <no-email-for-you@example.com> | 2022-01-01 19:54:46 -0600 |
commit | 2bb646d98e250dd48bf2770f1d00acc8ae503504 (patch) | |
tree | 63333f1e130b2f3b6fa9f7ccfebbf9a7f5dffb32 /mesecons | |
parent | ecea0a2896d488f82f34505eb608ab5f527f50ec (diff) | |
download | mesecons-2bb646d98e250dd48bf2770f1d00acc8ae503504.tar mesecons-2bb646d98e250dd48bf2770f1d00acc8ae503504.tar.gz mesecons-2bb646d98e250dd48bf2770f1d00acc8ae503504.tar.bz2 mesecons-2bb646d98e250dd48bf2770f1d00acc8ae503504.tar.xz mesecons-2bb646d98e250dd48bf2770f1d00acc8ae503504.zip |
Add Luacontroller library support
Fixes upstream #557
Diffstat (limited to 'mesecons')
-rw-r--r-- | mesecons/util.lua | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/mesecons/util.lua b/mesecons/util.lua index 7fb95cc..a89d234 100644 --- a/mesecons/util.lua +++ b/mesecons/util.lua @@ -474,3 +474,21 @@ function mesecon.execute_autoconnect_hooks_queue(pos, node) mesecon.queue:add_action(pos, "autoconnect_hook_"..name, {node}) end end + +-- Performs a deep copy of a table, changing the environment of any functions. +-- Adapted from the builtin table.copy() function. +function mesecon.tablecopy_change_env(t, env, seen) + local n = {} + seen = seen or {} + seen[t] = n + for k, v in pairs(t) do + if type(v) == "function" then + setfenv(v, env) + n[(type(k) == "table" and (seen[k] or mesecon.tablecopy_change_env(k, env, seen))) or k] = v + else + n[(type(k) == "table" and (seen[k] or mesecon.tablecopy_change_env(k, env, seen))) or k] = + (type(v) == "table" and (seen[v] or mesecon.tablecopy_change_env(v, env, seen))) or v + end + end + return n +end |