Only create one alias metatable
authorShadowNinja <shadowninja@minetest.net>
Wed, 4 Dec 2013 18:39:57 +0000 (13:39 -0500)
committerShadowNinja <shadowninja@minetest.net>
Wed, 4 Dec 2013 19:31:55 +0000 (14:31 -0500)
builtin/misc_register.lua

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