diff options
Diffstat (limited to 'ClientHamr/GuiLua/skang.lua')
-rw-r--r-- | ClientHamr/GuiLua/skang.lua | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index 5796361..6686e4d 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua | |||
@@ -625,7 +625,9 @@ local Thing = | |||
625 | if 'nil' == t then | 625 | if 'nil' == t then |
626 | if self.required then table.insert(self.errors, mum .. '.' .. name .. ' is required!') end | 626 | if self.required then table.insert(self.errors, mum .. '.' .. name .. ' is required!') end |
627 | else | 627 | else |
628 | if self.types[1] ~= t then table.insert(self.errors, mum .. '.' .. name .. ' should be a ' .. self.types[1] .. ', but it is a ' .. t .. '!') | 628 | if 'widget' == self.types[1] then |
629 | -- TODO - Should validate any attached Thing. | ||
630 | elseif self.types[1] ~= t then table.insert(self.errors, mum .. '.' .. name .. ' should be a ' .. self.types[1] .. ', but it is a ' .. t .. '!') | ||
629 | else | 631 | else |
630 | if 'number' == t then value = '' .. value end | 632 | if 'number' == t then value = '' .. value end |
631 | if ('number' == t) or ('string' == t) then | 633 | if ('number' == t) or ('string' == t) then |
@@ -669,7 +671,6 @@ end | |||
669 | 671 | ||
670 | local Mum = | 672 | local Mum = |
671 | { | 673 | { |
672 | --[[ From an email by Mike Pall - | ||
673 | 674 | ||
674 | __index = function (parent, key) | 675 | __index = function (parent, key) |
675 | -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist. | 676 | -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist. |
@@ -882,6 +883,16 @@ thingasm = function (names, ...) | |||
882 | setmetatable(thingy.default, thisMum) | 883 | setmetatable(thingy.default, thisMum) |
883 | end | 884 | end |
884 | 885 | ||
886 | if 'widget' == thingy.types[1] then | ||
887 | local args, err = loadstring('return ' .. thingy.widget) | ||
888 | if args then | ||
889 | setfenv(args, parent) | ||
890 | parent.W[name] = {widget = widget(args())} | ||
891 | else | ||
892 | print("ERROR - " .. err) | ||
893 | end | ||
894 | end | ||
895 | |||
885 | -- Remove old names, then stash the Thing under all of it's new names. | 896 | -- Remove old names, then stash the Thing under all of it's new names. |
886 | for i, v in ipairs(oldNames) do | 897 | for i, v in ipairs(oldNames) do |
887 | metaMum.__self.stuff[v] = nil | 898 | metaMum.__self.stuff[v] = nil |
@@ -891,7 +902,7 @@ thingasm = function (names, ...) | |||
891 | end | 902 | end |
892 | 903 | ||
893 | -- This triggers the Mum.__newindex metamethod above. If nothing else, it triggers thingy.isValid() | 904 | -- This triggers the Mum.__newindex metamethod above. If nothing else, it triggers thingy.isValid() |
894 | if new and not metaMum.__self.isKeyed then parent[name] = thingy.default end | 905 | if new and not metaMum.__self.isKeyed and ('widget' ~= thingy.types[1]) then parent[name] = thingy.default end |
895 | end | 906 | end |
896 | 907 | ||
897 | 908 | ||
@@ -996,6 +1007,34 @@ thingasm('set', 'Set the current value of an existing Thing or metadata.', set, | |||
996 | thingasm('nada', 'Do nothing.', function () --[[ This function intentionally left blank. ]] end) | 1007 | thingasm('nada', 'Do nothing.', function () --[[ This function intentionally left blank. ]] end) |
997 | 1008 | ||
998 | 1009 | ||
1010 | |||
1011 | -- Widget wrappers. | ||
1012 | -- TODO - Fix this up so we don't need .W | ||
1013 | local widgets = {} | ||
1014 | --thingasm{widgets, 'window', 'The window.', types='userdata'} | ||
1015 | thingasm{widgets, 'W', 'Holds all the widgets', types='Keyed'} | ||
1016 | widgets.W{'look,l', 'The look of the widget.', types='string'} | ||
1017 | widgets.W{'colour,color,c', 'The colours of the widget.', types='table'} | ||
1018 | widgets.W.c{'red,r', 'The red colour of the widget.', 255, types='number'} | ||
1019 | widgets.W.c{'green,g', 'The green colour of the widget.', 255, types='number'} | ||
1020 | widgets.W.c{'blue,b', 'The blue colour of the widget.', 255, types='number'} | ||
1021 | widgets.W.c{'alpha,a', 'The alpha colour of the widget.', 255, types='number'} | ||
1022 | -- At this point we want to change widgets.W.c() to go to a different __call, coz right now it's going to the Mum.__call, which wraps thingasm. | ||
1023 | -- TODO - Keep an eye on this if we change to a single Mum, instead of the shallow copy we use now. | ||
1024 | local wMum = getmetatable(widgets.W.c) | ||
1025 | wMum.__call = function (func, ...) | ||
1026 | return Colour(func, ...) | ||
1027 | end | ||
1028 | |||
1029 | window = function(w, h, title, name) | ||
1030 | name = name or 'myWindow' | ||
1031 | local win = {} | ||
1032 | win.W = copy(widgets.W, name) | ||
1033 | win.window = Cwindow(w, h, title, name) | ||
1034 | return win | ||
1035 | end | ||
1036 | |||
1037 | |||
999 | -- TODO - Some function stubs, for now. Fill them up later. | 1038 | -- TODO - Some function stubs, for now. Fill them up later. |
1000 | skang = function (name) | 1039 | skang = function (name) |
1001 | end | 1040 | end |