diff options
author | sfan5 <sfan5@live.de> | 2022-07-04 01:06:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-04 01:06:42 +0200 |
commit | fc3460470aec8d73317d2b35edf195bfeec2852c (patch) | |
tree | acfee4e29064b04726bb65b1e0cf026c82834e28 /builtin/async | |
parent | 34f15259fa5546dc9abaf974ca5385c276443697 (diff) | |
download | minetest-fc3460470aec8d73317d2b35edf195bfeec2852c.tar.gz minetest-fc3460470aec8d73317d2b35edf195bfeec2852c.tar.bz2 minetest-fc3460470aec8d73317d2b35edf195bfeec2852c.zip |
Add missing item alias metatables to async environment (#12458)
Diffstat (limited to 'builtin/async')
-rw-r--r-- | builtin/async/game.lua | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/builtin/async/game.lua b/builtin/async/game.lua index 8cb9720b6..6512f0706 100644 --- a/builtin/async/game.lua +++ b/builtin/async/game.lua @@ -25,11 +25,13 @@ do local all = assert(core.transferred_globals) core.transferred_globals = nil - -- reassemble other tables all.registered_nodes = {} all.registered_craftitems = {} all.registered_tools = {} for k, v in pairs(all.registered_items) do + -- Disable further modification + setmetatable(v, {__newindex = {}}) + -- Reassemble the other tables if v.type == "node" then all.registered_nodes[k] = v elseif v.type == "craftitem" then @@ -43,3 +45,15 @@ do core[k] = v end end + +-- For tables that are indexed by item name: +-- If table[X] does not exist, default to table[core.registered_aliases[X]] +local alias_metatable = { + __index = function(t, name) + return rawget(t, core.registered_aliases[name]) + end +} +setmetatable(core.registered_items, alias_metatable) +setmetatable(core.registered_nodes, alias_metatable) +setmetatable(core.registered_craftitems, alias_metatable) +setmetatable(core.registered_tools, alias_metatable) |