From 628987e1151d9b1639377e2dfb87b2810c8efd4c Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Tue, 1 Apr 2014 23:08:59 +1000 Subject: valueMeta -> oldMum, plus some comments. --- ClientHamr/GuiLua/skang.lua | 16 ++++++++++------ ClientHamr/GuiLua/test.lua | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'ClientHamr/GuiLua') diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index de0a0af..24f3dbc 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua @@ -572,24 +572,28 @@ __newindex = function (parent, key, value) if thingy then local name = thingy.names[1] - local valueMeta + local oldMum if 'table' == type(value) then -- Coz setting it via metaMum screws with the __index stuff somehow. local oldValue = metaMum.__values[name] if 'table' == type(oldValue) then - valueMeta = getmetatable(oldValue) - if valueMeta then + oldMum = getmetatable(oldValue) + if oldMum then + -- TODO - This SHOULD work, but doesn't. + --setmetatable(value, oldMum) + -- Instead we do this - -- TODO - This wont clear out any values in the old table that are not in the new table. Should it? for k, v in pairs(value) do - local newK = valueMeta.__self.stuff[k] + local newK = oldMum.__self.stuff[k] if newK then newK = newK.names[1] else newK = k end - valueMeta.__values[newK] = v + oldMum.__values[newK] = v end + end end end - if nil == valueMeta then metaMum.__values[name] = value end + if nil == oldMum then metaMum.__values[name] = value end -- NOTE - invalid values are still stored, this is by design. if not thingy:isValid(parent) then for i, v in ipairs(thingy.errors) do diff --git a/ClientHamr/GuiLua/test.lua b/ClientHamr/GuiLua/test.lua index 60d4200..9e3000a 100644 --- a/ClientHamr/GuiLua/test.lua +++ b/ClientHamr/GuiLua/test.lua @@ -163,7 +163,7 @@ stuff.s.sb = 22 stuff.s.b = 33 -- NOTE - This triggers isValid twice for each table element. stuff.s = {a=8, sb='9'} -stuff.s.sb = 44 +stuff.s.sb = 99 print('') --stuff.S.record0 = {} stuff.S['record0'] = {field0=0, field1='zero'} -- cgit v1.1