diff options
-rw-r--r-- | ClientHamr/GuiLua/GuiLua.c | 20 | ||||
-rw-r--r-- | ClientHamr/GuiLua/skang.lua | 50 | ||||
-rw-r--r-- | ClientHamr/GuiLua/test.skang | 10 |
3 files changed, 63 insertions, 17 deletions
diff --git a/ClientHamr/GuiLua/GuiLua.c b/ClientHamr/GuiLua/GuiLua.c index b42df1b..69fef14 100644 --- a/ClientHamr/GuiLua/GuiLua.c +++ b/ClientHamr/GuiLua/GuiLua.c | |||
@@ -587,6 +587,24 @@ static int widget(lua_State *L) | |||
587 | return 0; | 587 | return 0; |
588 | } | 588 | } |
589 | 589 | ||
590 | static void _on_click(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) | ||
591 | { | ||
592 | // TODO, pull the action out of the widget, then somehow magically send it to Lua. | ||
593 | } | ||
594 | |||
595 | static int action(lua_State *L) | ||
596 | { | ||
597 | Evas_Object *obj= lua_touserdata(L, 1); | ||
598 | char *action = "nada"; | ||
599 | |||
600 | pull_lua(L, 2, "$", &action); | ||
601 | printf("Setting action %s\n", action); | ||
602 | // TODO - stuff the action into the widget somewhere. | ||
603 | evas_object_smart_callback_add(obj, "clicked", _on_click, L); | ||
604 | |||
605 | return 0; | ||
606 | } | ||
607 | |||
590 | static int colour(lua_State *L) | 608 | static int colour(lua_State *L) |
591 | { | 609 | { |
592 | // TODO - This is just a stub for now. | 610 | // TODO - This is just a stub for now. |
@@ -594,7 +612,6 @@ static int colour(lua_State *L) | |||
594 | return 0; | 612 | return 0; |
595 | } | 613 | } |
596 | 614 | ||
597 | |||
598 | static int window(lua_State *L) | 615 | static int window(lua_State *L) |
599 | { | 616 | { |
600 | globals *ourGlobals; | 617 | globals *ourGlobals; |
@@ -737,6 +754,7 @@ int luaopen_libGuiLua(lua_State *L) | |||
737 | push_lua(L, "@ ( { = $ $ & $ $acl } )", skang, THINGASM, skang, "Cwindow", "Opens our window.", window, "number,number,string", "GGG", 0); | 754 | push_lua(L, "@ ( { = $ $ & $ $acl } )", skang, THINGASM, skang, "Cwindow", "Opens our window.", window, "number,number,string", "GGG", 0); |
738 | push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "clear", "The current skin is cleared of all widgets.", clear, 0); | 755 | push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "clear", "The current skin is cleared of all widgets.", clear, 0); |
739 | push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "widget", "Create a widget.", widget, 0); | 756 | push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "widget", "Create a widget.", widget, 0); |
757 | push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "action", "Add an action to a widget.", action, 0); | ||
740 | push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "Colour", "Change widget colours.", colour, 0); | 758 | push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "Colour", "Change widget colours.", colour, 0); |
741 | push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "loopWindow", "Run our windows main loop.", loopWindow, 0); | 759 | push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "loopWindow", "Run our windows main loop.", loopWindow, 0); |
742 | push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "quit", "Quit, exit, remove thyself.", quit, 0); | 760 | push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "quit", "Quit, exit, remove thyself.", quit, 0); |
diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index 6686e4d..e6b6725 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua | |||
@@ -696,9 +696,14 @@ __newindex = function (parent, key, value) | |||
696 | if metaMum.__self.isKeyed then | 696 | if metaMum.__self.isKeyed then |
697 | -- Deal with setting a new Keyed table entry. | 697 | -- Deal with setting a new Keyed table entry. |
698 | local newThing = copy(parent, key) | 698 | local newThing = copy(parent, key) |
699 | local newSelf = getmetatable(newThing).__self | ||
699 | rawset(metaMum.__values, key, newThing) | 700 | rawset(metaMum.__values, key, newThing) |
700 | -- thingy = {names={key}, types={'table'}, parent=newThing, stuff=getmetatable(newThing).__self.stuff, } | 701 | thingy = {} |
701 | thingy = {names={key}, types={'table'}, stuff=getmetatable(newThing).__self.stuff, } | 702 | for k, v in pairs(newSelf) do |
703 | thingy[k] = v | ||
704 | end | ||
705 | thingy.names={key} | ||
706 | thingy.types={'table'} | ||
702 | setmetatable(thingy, {__index = Thing}) -- To pick up isValid, pattern, and the other stuff by default. | 707 | setmetatable(thingy, {__index = Thing}) -- To pick up isValid, pattern, and the other stuff by default. |
703 | end | 708 | end |
704 | end | 709 | end |
@@ -796,6 +801,7 @@ thingasm = function (names, ...) | |||
796 | local params = {...} | 801 | local params = {...} |
797 | local new = false | 802 | local new = false |
798 | local parent | 803 | local parent |
804 | local set = true | ||
799 | 805 | ||
800 | -- Check how we were called, and re arrange stuff to match. | 806 | -- Check how we were called, and re arrange stuff to match. |
801 | if 0 == #params then | 807 | if 0 == #params then |
@@ -870,8 +876,20 @@ thingasm = function (names, ...) | |||
870 | if '' == types then types = typ end | 876 | if '' == types then types = typ end |
871 | thingy.types = csv2table(types) | 877 | thingy.types = csv2table(types) |
872 | 878 | ||
879 | if 'widget' == thingy.types[1] then | ||
880 | set = false | ||
881 | local args, err = loadstring('return ' .. thingy.widget) | ||
882 | if args then | ||
883 | setfenv(args, parent) | ||
884 | parent.W[name] = {widget = widget(args())} | ||
885 | else | ||
886 | print("ERROR - " .. err) | ||
887 | end | ||
888 | end | ||
889 | |||
873 | -- Deal with Keyed and tables. | 890 | -- Deal with Keyed and tables. |
874 | if 'Keyed' == thingy.types[1] then | 891 | if 'Keyed' == thingy.types[1] then |
892 | set = false | ||
875 | thingy.types[1] = 'table' | 893 | thingy.types[1] = 'table' |
876 | thingy.isKeyed = true | 894 | thingy.isKeyed = true |
877 | end | 895 | end |
@@ -883,14 +901,8 @@ thingasm = function (names, ...) | |||
883 | setmetatable(thingy.default, thisMum) | 901 | setmetatable(thingy.default, thisMum) |
884 | end | 902 | end |
885 | 903 | ||
886 | if 'widget' == thingy.types[1] then | 904 | if 'userdata' == thingy.types[1] then |
887 | local args, err = loadstring('return ' .. thingy.widget) | 905 | set = false |
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 | 906 | end |
895 | 907 | ||
896 | -- Remove old names, then stash the Thing under all of it's new names. | 908 | -- Remove old names, then stash the Thing under all of it's new names. |
@@ -902,7 +914,7 @@ thingasm = function (names, ...) | |||
902 | end | 914 | end |
903 | 915 | ||
904 | -- This triggers the Mum.__newindex metamethod above. If nothing else, it triggers thingy.isValid() | 916 | -- This triggers the Mum.__newindex metamethod above. If nothing else, it triggers thingy.isValid() |
905 | if new and not metaMum.__self.isKeyed and ('widget' ~= thingy.types[1]) then parent[name] = thingy.default end | 917 | if new and set then parent[name] = thingy.default end |
906 | end | 918 | end |
907 | 919 | ||
908 | 920 | ||
@@ -1013,6 +1025,20 @@ thingasm('nada', 'Do nothing.', function () --[[ This function intentionally lef | |||
1013 | local widgets = {} | 1025 | local widgets = {} |
1014 | --thingasm{widgets, 'window', 'The window.', types='userdata'} | 1026 | --thingasm{widgets, 'window', 'The window.', types='userdata'} |
1015 | thingasm{widgets, 'W', 'Holds all the widgets', types='Keyed'} | 1027 | thingasm{widgets, 'W', 'Holds all the widgets', types='Keyed'} |
1028 | widgets.W{'widget', 'The widget.', types='userdata'} | ||
1029 | widgets.W{'action,a', 'The action for the widget.', 'nada', types='string'} | ||
1030 | local aIsValid = function (self, parent) | ||
1031 | local result = Thing.isValid(self, parent) | ||
1032 | |||
1033 | if result then | ||
1034 | local value = parent[self.names[1] ] | ||
1035 | print('NEW ACTION - ' .. self.names[1] .. ' = ' .. value) | ||
1036 | --printTableStart(parent, '', 'parent') | ||
1037 | action(parent.widget, value) | ||
1038 | end | ||
1039 | return result | ||
1040 | end | ||
1041 | |||
1016 | widgets.W{'look,l', 'The look of the widget.', types='string'} | 1042 | widgets.W{'look,l', 'The look of the widget.', types='string'} |
1017 | widgets.W{'colour,color,c', 'The colours of the widget.', types='table'} | 1043 | 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'} | 1044 | widgets.W.c{'red,r', 'The red colour of the widget.', 255, types='number'} |
@@ -1030,6 +1056,8 @@ window = function(w, h, title, name) | |||
1030 | name = name or 'myWindow' | 1056 | name = name or 'myWindow' |
1031 | local win = {} | 1057 | local win = {} |
1032 | win.W = copy(widgets.W, name) | 1058 | win.W = copy(widgets.W, name) |
1059 | local wMum, wThingy = getStuffed(win.W, 'a') | ||
1060 | wThingy.isValid = aIsValid | ||
1033 | win.window = Cwindow(w, h, title, name) | 1061 | win.window = Cwindow(w, h, title, name) |
1034 | return win | 1062 | return win |
1035 | end | 1063 | end |
diff --git a/ClientHamr/GuiLua/test.skang b/ClientHamr/GuiLua/test.skang index a8ca105..340bb08 100644 --- a/ClientHamr/GuiLua/test.skang +++ b/ClientHamr/GuiLua/test.skang | |||
@@ -5,12 +5,12 @@ | |||
5 | 5 | ||
6 | -- local other = require 'otherPackageName' | 6 | -- local other = require 'otherPackageName' |
7 | 7 | ||
8 | skang.clear() | 8 | -- This is a bit more verbose than I wanted. lol |
9 | local win = skang.window(500, 500, "G'day planet.", 'testWindow') | 9 | local win = skang.window(500, 500, "G'day planet.", 'testWindow') |
10 | 10 | skang.thingasm{win, 'quitter', 'Quits the skang window', types = 'widget', widget='"button", "Quit", 10, 10, 100, 50'} | |
11 | 11 | skang.printTableStart(win.W.quitter, '', 'quitter') | |
12 | skang.thingasm{win, 'quitter', 'Quits the skang window', types = 'widget', widget='"button", "Quit", 10, 10, 100, 50', required=true} | 12 | win.W.quitter.action = 1 |
13 | --quitter:action('quit') -- 'quit' is looked up in ThingSpace.commands, and translated into the Lua 'skang.quit()'. | 13 | win.W.quitter.action = 'quit' -- 'quit' is looked up in ThingSpace.commands, and translated into the Lua 'skang.quit()'. |
14 | 14 | ||
15 | --other.foo = 'stuff' | 15 | --other.foo = 'stuff' |
16 | this.bar = 'things' | 16 | this.bar = 'things' |