Only create one alias metatable

This commit is contained in:
ShadowNinja 2013-12-04 13:39:57 -05:00
parent e51ad5337f
commit 000da6b25d
1 changed files with 9 additions and 11 deletions

View File

@ -24,17 +24,15 @@ minetest.registered_aliases = {}
-- For tables that are indexed by item name: -- For tables that are indexed by item name:
-- If table[X] does not exist, default to table[minetest.registered_aliases[X]] -- If table[X] does not exist, default to table[minetest.registered_aliases[X]]
local function set_alias_metatable(table) local alias_metatable = {
setmetatable(table, { __index = function(t, name)
__index = function(name) return rawget(t, minetest.registered_aliases[name])
return rawget(table, minetest.registered_aliases[name]) end
end }
}) setmetatable(minetest.registered_items, alias_metatable)
end setmetatable(minetest.registered_nodes, alias_metatable)
set_alias_metatable(minetest.registered_items) setmetatable(minetest.registered_craftitems, alias_metatable)
set_alias_metatable(minetest.registered_nodes) setmetatable(minetest.registered_tools, alias_metatable)
set_alias_metatable(minetest.registered_craftitems)
set_alias_metatable(minetest.registered_tools)
-- These item names may not be used because they would interfere -- These item names may not be used because they would interfere
-- with legacy itemstrings -- with legacy itemstrings