diff options
Diffstat (limited to 'ClientHamr/GuiLua/skang.lua')
-rw-r--r-- | ClientHamr/GuiLua/skang.lua | 102 |
1 files changed, 55 insertions, 47 deletions
diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index 24f3dbc..e332dbb 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua | |||
@@ -529,6 +529,23 @@ Thing.remove = function (self) -- Delete this Thing. | |||
529 | end | 529 | end |
530 | 530 | ||
531 | 531 | ||
532 | getStuffed = function (parent, key) | ||
533 | local metaMum = getmetatable(parent) | ||
534 | local thingy | ||
535 | |||
536 | if metaMum and metaMum.__self then | ||
537 | thingy = metaMum.__self.stuff[key] | ||
538 | |||
539 | if not thingy then | ||
540 | -- Deal with getting a table entry. | ||
541 | if metaMum.__values[key] then | ||
542 | thingy = getmetatable(metaMum.__values[key]).__self | ||
543 | end | ||
544 | end | ||
545 | end | ||
546 | return metaMum, thingy | ||
547 | end | ||
548 | |||
532 | local Mum = | 549 | local Mum = |
533 | { | 550 | { |
534 | __index = function (parent, key) | 551 | __index = function (parent, key) |
@@ -537,13 +554,10 @@ __index = function (parent, key) | |||
537 | -- Ah, it was doing isValid() on setStufflet(). | 554 | -- Ah, it was doing isValid() on setStufflet(). |
538 | 555 | ||
539 | -- First see if this is a Thing. | 556 | -- First see if this is a Thing. |
540 | local metaMum = getmetatable(parent) | 557 | local metaMum, thingy = getStuffed(parent, key) |
541 | 558 | ||
542 | if metaMum and metaMum.__self then | 559 | if thingy then |
543 | local thingy = metaMum.__self.stuff[key] | 560 | return metaMum.__values[thingy.names[1] ] or thingy.default |
544 | if thingy then | ||
545 | return metaMum.__values[thingy.names[1] ] or thingy.default | ||
546 | end | ||
547 | end | 561 | end |
548 | 562 | ||
549 | -- Then see if we can inherit it from Thing. | 563 | -- Then see if we can inherit it from Thing. |
@@ -554,56 +568,50 @@ __newindex = function (parent, key, value) | |||
554 | -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist. | 568 | -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist. |
555 | 569 | ||
556 | -- First see if this is a Thing. | 570 | -- First see if this is a Thing. |
557 | local metaMum = getmetatable(parent) | 571 | local metaMum, thingy = getStuffed(parent, key) |
558 | 572 | ||
559 | if metaMum and metaMum.__self then | 573 | if not thingy then |
560 | local thingy = metaMum.__self.stuff[key] | 574 | if metaMum.__self.isKeyed then |
561 | |||
562 | if not thingy then | ||
563 | -- Deal with setting a new Keyed table entry. | 575 | -- Deal with setting a new Keyed table entry. |
564 | if metaMum.__self.isKeyed and (nil == metaMum.__values[key]) then | 576 | local newThing = copy(parent, key) |
565 | local newThing = copy(parent, key) | 577 | rawset(metaMum.__values, key, newThing) |
566 | rawset(metaMum.__values, key, newThing) | 578 | thingy = {names={key}, types={'table'}, parent=newThing, stuff=getmetatable(newThing).__self.stuff, } |
567 | thingy = {names={key}, types={'table'}, parent=newThing, stuff=getmetatable(newThing).__self.stuff, } | 579 | setmetatable(thingy, {__index = Thing}) -- To pick up isValid, pattern, and the other stuff by default. |
568 | setmetatable(thingy, {__index = Thing}) -- To pick up isValid, pattern, and the other stuff by default. | ||
569 | metaMum.__self.stuff[key] = thingy | ||
570 | end | ||
571 | end | 580 | end |
581 | end | ||
572 | 582 | ||
573 | if thingy then | 583 | if thingy then |
574 | local name = thingy.names[1] | 584 | local name = thingy.names[1] |
575 | local oldMum | 585 | local oldMum |
576 | 586 | ||
577 | if 'table' == type(value) then | 587 | if 'table' == type(value) then |
578 | -- Coz setting it via metaMum screws with the __index stuff somehow. | 588 | -- Coz setting it via metaMum screws with the __index stuff somehow. |
579 | local oldValue = metaMum.__values[name] | 589 | local oldValue = metaMum.__values[name] |
580 | if 'table' == type(oldValue) then | 590 | if 'table' == type(oldValue) then |
581 | oldMum = getmetatable(oldValue) | 591 | oldMum = getmetatable(oldValue) |
582 | if oldMum then | 592 | if oldMum then |
583 | -- TODO - This SHOULD work, but doesn't. | 593 | -- TODO - This SHOULD work, but doesn't. |
584 | --setmetatable(value, oldMum) | 594 | --setmetatable(value, oldMum) |
585 | -- Instead we do this - | 595 | -- Instead we do this - |
586 | -- TODO - This wont clear out any values in the old table that are not in the new table. Should it? | 596 | -- TODO - This wont clear out any values in the old table that are not in the new table. Should it? |
587 | for k, v in pairs(value) do | 597 | for k, v in pairs(value) do |
588 | local newK = oldMum.__self.stuff[k] | 598 | local newK = oldMum.__self.stuff[k] |
589 | if newK then newK = newK.names[1] else newK = k end | 599 | if newK then newK = newK.names[1] else newK = k end |
590 | oldMum.__values[newK] = v | 600 | oldMum.__values[newK] = v |
591 | end | ||
592 | |||
593 | end | 601 | end |
594 | end | 602 | end |
595 | end | 603 | end |
596 | if nil == oldMum then metaMum.__values[name] = value end | 604 | end |
597 | -- NOTE - invalid values are still stored, this is by design. | 605 | if nil == oldMum then metaMum.__values[name] = value end |
598 | if not thingy:isValid(parent) then | 606 | -- NOTE - invalid values are still stored, this is by design. |
599 | for i, v in ipairs(thingy.errors) do | 607 | if not thingy:isValid(parent) then |
600 | print('ERROR - ' .. v) | 608 | for i, v in ipairs(thingy.errors) do |
601 | end | 609 | print('ERROR - ' .. v) |
602 | end | 610 | end |
603 | -- TODO - Go through it's linked things and set them to. | ||
604 | -- Done, don't fall through to the rawset() | ||
605 | return | ||
606 | end | 611 | end |
612 | -- TODO - Go through it's linked things and set them to. | ||
613 | -- Done, don't fall through to the rawset() | ||
614 | return | ||
607 | end | 615 | end |
608 | 616 | ||
609 | rawset(parent, key, value) -- Stuff it normally. | 617 | rawset(parent, key, value) -- Stuff it normally. |