From 012fdeec81fa0338a43f8bd9f6df98afc572c448 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sat, 22 Mar 2014 14:00:19 +1000 Subject: Much saner way to deal with aliases. B-) --- ClientHamr/GuiLua/skang.lua | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index 3825f47..d79deff 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua @@ -199,13 +199,6 @@ Thing = -- First see if this is a Thing. if thing then return thing.default end - -- Look up aliases. Very slow, but uses less memory. Would only need to be done if an alias is used, and they are mostly for shortcuts. - for k, thing in pairs(ThingSpace.things) do - for i, v in ipairs(thing.names) do - if v == key then return table[ thing.names[1] ] end - end - end - -- If all else fails, return nil. return nil end, @@ -213,16 +206,6 @@ Thing = __newindex = function (table, key, value) local thing = ThingSpace.things[key] - -- NOTE - This is really slow when setting stuff that is in the module that is NOT a Thing. Wont scale well. - if not thing then - -- Look up aliases. Very slow, but uses less memory. Would only need to be done if an alias is used, and they are mostly for shortcuts. - for k, thng in pairs(ThingSpace.things) do - for i, v in ipairs(thng.names) do - if v == key then thing = thng; break end - end - end - end - -- NOTE - A Thing is either a command or a parameter, not both. if thing then if 'function' == type(value) then @@ -344,7 +327,11 @@ thing = function (module, names, help, default, types, widget, required, acl, bo -- Set it all up. -- TODO - might want to merge into pre existing Thing instead of over writing like this. - ThingSpace.things[name] = {module = module, names = n, help = help, default = default, types = t, widget = widget, required = required, acl = acl, boss = boss, } + local thing = {module = module, names = n, help = help, default = default, types = t, widget = widget, required = required, acl = acl, boss = boss, } + -- Stash the Thing under all of it's names. + for i, v in ipairs(thing.names) do + ThingSpace.things[v] = thing + end -- This triggers the Thing.__newindex metamethod above. module[name] = default end -- cgit v1.1