aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-04-18 20:23:52 +1000
committerDavid Walter Seikel2014-04-18 20:23:52 +1000
commitb3a9d6b10732f3f65ca0a24aa2a66275e24f8cd7 (patch)
tree50363eeef17eef1785571ee6325828a8dce3c8cc
parentHalf arsed window and button implementation. (diff)
downloadSledjHamr-b3a9d6b10732f3f65ca0a24aa2a66275e24f8cd7.zip
SledjHamr-b3a9d6b10732f3f65ca0a24aa2a66275e24f8cd7.tar.gz
SledjHamr-b3a9d6b10732f3f65ca0a24aa2a66275e24f8cd7.tar.bz2
SledjHamr-b3a9d6b10732f3f65ca0a24aa2a66275e24f8cd7.tar.xz
Trying to add widget actions, but it's broken somehow. Think maybe Keyed is screwing it up?
I need sleep.
-rw-r--r--ClientHamr/GuiLua/GuiLua.c20
-rw-r--r--ClientHamr/GuiLua/skang.lua50
-rw-r--r--ClientHamr/GuiLua/test.skang10
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
590static 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
595static 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);
601printf("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
590static int colour(lua_State *L) 608static 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
598static int window(lua_State *L) 615static 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
906end 918end
907 919
908 920
@@ -1013,6 +1025,20 @@ thingasm('nada', 'Do nothing.', function () --[[ This function intentionally lef
1013local widgets = {} 1025local widgets = {}
1014--thingasm{widgets, 'window', 'The window.', types='userdata'} 1026--thingasm{widgets, 'window', 'The window.', types='userdata'}
1015thingasm{widgets, 'W', 'Holds all the widgets', types='Keyed'} 1027thingasm{widgets, 'W', 'Holds all the widgets', types='Keyed'}
1028widgets.W{'widget', 'The widget.', types='userdata'}
1029widgets.W{'action,a', 'The action for the widget.', 'nada', types='string'}
1030local aIsValid = function (self, parent)
1031 local result = Thing.isValid(self, parent)
1032
1033 if result then
1034 local value = parent[self.names[1] ]
1035print('NEW ACTION - ' .. self.names[1] .. ' = ' .. value)
1036--printTableStart(parent, '', 'parent')
1037 action(parent.widget, value)
1038 end
1039 return result
1040end
1041
1016widgets.W{'look,l', 'The look of the widget.', types='string'} 1042widgets.W{'look,l', 'The look of the widget.', types='string'}
1017widgets.W{'colour,color,c', 'The colours of the widget.', types='table'} 1043widgets.W{'colour,color,c', 'The colours of the widget.', types='table'}
1018widgets.W.c{'red,r', 'The red colour of the widget.', 255, types='number'} 1044widgets.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
1035end 1063end
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
8skang.clear() 8-- This is a bit more verbose than I wanted. lol
9local win = skang.window(500, 500, "G'day planet.", 'testWindow') 9local win = skang.window(500, 500, "G'day planet.", 'testWindow')
10 10skang.thingasm{win, 'quitter', 'Quits the skang window', types = 'widget', widget='"button", "Quit", 10, 10, 100, 50'}
11 11skang.printTableStart(win.W.quitter, '', 'quitter')
12skang.thingasm{win, 'quitter', 'Quits the skang window', types = 'widget', widget='"button", "Quit", 10, 10, 100, 50', required=true} 12win.W.quitter.action = 1
13--quitter:action('quit') -- 'quit' is looked up in ThingSpace.commands, and translated into the Lua 'skang.quit()'. 13win.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'
16this.bar = 'things' 16this.bar = 'things'