Skip to content

Commit 58ae854

Browse files
committed
API v1 to v2 shim: follow spec with shallow copy
1 parent 1fe4b32 commit 58ae854

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

technic/machines/compat/api.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,28 @@ local S = technic.getter
33
-- Registration compatibility shim to transform Technic 1.x arguments to 2.x
44
-- This could be made stricter for new style API by utilizing `assert`
55

6+
local function shallow_copy(t)
7+
local result = {}
8+
for k, v in pairs(t) do
9+
result[k] = v
10+
end
11+
return setmetatable(result, getmetatable(t))
12+
end
13+
614
function technic.register_compat_v1_to_v2(name, data, default_name)
715
local modname = minetest.get_current_modname()
816
local colon, def
917
if type(name) == "table" then
1018
-- Log old API usage, swap name to def and set name from def table
1119
local msg = "Deprecated Technic registration API call: %s (%s)"
12-
def = table.copy(name)
20+
def = shallow_copy(name)
1321
name = def.machine_name or default_name
1422
def.machine_name = nil
1523
def.description = def.machine_desc
1624
def.machine_desc = nil
1725
minetest.log("warning", msg:format(tostring(name), tostring(modname)))
1826
else
19-
def = table.copy(data)
27+
def = shallow_copy(data)
2028
end
2129
-- Input name can be "modname:nodename", ":modname:nodename" or "nodename".
2230
-- If name is presented as "nodename" then check for old def.modname field.

0 commit comments

Comments
 (0)