From 22df267ff0926a3dd14dd1cc5cbf31f16086c5b7 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Wed, 26 Mar 2014 16:58:58 +1000 Subject: Change Thing to being fully a proxy table, coz __newindex() only works for nil valued table elements. --- ClientHamr/GuiLua/skang.lua | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'ClientHamr/GuiLua/skang.lua') diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index c9a58ff..f88ff1c 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua @@ -237,15 +237,8 @@ Thing.hasCrashed = 0 -- How many times this Thing has crashed. Thing.__index = function (table, key) -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist. local thing = things[key] - -- First see if this is a Thing. - if thing then - local result = nil - if key ~= thing.names[1] then - result = table[thing.names[1] ] -- This might be recursive. - end - return result or thing.default - end + if thing then return thing.value or thing.default end -- Then see if we can inherit it from Thing. thing = Thing[key] @@ -256,11 +249,13 @@ Thing.__index = function (table, key) end Thing.__newindex = function (table, key, value) + -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist. local thing = things[key] if thing then local name = thing.names[1] - rawset(table, name, value) -- Only stuff it under the first name, the rest are left as nil. + -- This is a proxy table, the values never exist in the real table. + thing.value = value if 'function' == type(value) then thing.func = value local types = '' -- cgit v1.1