aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ClientHamr
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-04-20 04:51:19 +1000
committerDavid Walter Seikel2014-04-20 04:51:19 +1000
commit407dee6650c6fbb8506146eda91428155890c623 (patch)
tree13a63b74a71f5edb67c4c453d59111edb3a6f4fc /ClientHamr
parentTrying to add widget actions, but it's broken somehow. Think maybe Keyed is ... (diff)
downloadSledjHamr-407dee6650c6fbb8506146eda91428155890c623.zip
SledjHamr-407dee6650c6fbb8506146eda91428155890c623.tar.gz
SledjHamr-407dee6650c6fbb8506146eda91428155890c623.tar.bz2
SledjHamr-407dee6650c6fbb8506146eda91428155890c623.tar.xz
Fix up widget action stuff.
Diffstat (limited to 'ClientHamr')
-rw-r--r--ClientHamr/GuiLua/GuiLua.c76
-rw-r--r--ClientHamr/GuiLua/skang.lua15
-rw-r--r--ClientHamr/GuiLua/test.lua5
-rw-r--r--ClientHamr/GuiLua/test.skang4
4 files changed, 69 insertions, 31 deletions
diff --git a/ClientHamr/GuiLua/GuiLua.c b/ClientHamr/GuiLua/GuiLua.c
index 69fef14..9339552 100644
--- a/ClientHamr/GuiLua/GuiLua.c
+++ b/ClientHamr/GuiLua/GuiLua.c
@@ -557,10 +557,35 @@ win.quitter.colour.r = 5 -> direct access to the table, well "direct" via Th
557 557
558*/ 558*/
559 559
560struct _Widget
561{
562 char magic[8];
563 char *action;
564 Evas_Object *obj;
565};
566
567static void _on_click(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
568{
569 globals *ourGlobals;
570 lua_State *L = data;
571 struct _Widget *wid;
572
573 lua_getfield(L, LUA_REGISTRYINDEX, globName);
574 ourGlobals = lua_touserdata(L, -1);
575 lua_pop(L, 1);
576
577 wid = evas_object_data_get(obj, "Widget");
578 if (wid)
579 {
580 PD("Doing action %s", wid->action);
581 if (0 != luaL_dostring(L, wid->action))
582 PE("Error running - %s", wid->action);
583 }
584}
585
560static int widget(lua_State *L) 586static int widget(lua_State *L)
561{ 587{
562 globals *ourGlobals; 588 globals *ourGlobals;
563 Evas_Object *bt;
564 char *type = "label"; 589 char *type = "label";
565 char *title = ":"; 590 char *title = ":";
566 int x = 1, y = 1, w = WIDTH/3, h = HEIGHT/3; 591 int x = 1, y = 1, w = WIDTH/3, h = HEIGHT/3;
@@ -574,34 +599,44 @@ static int widget(lua_State *L)
574 // Poor mans introspection, until I write real introspection into EFL. 599 // Poor mans introspection, until I write real introspection into EFL.
575 if (strcmp(type, "button") == 0) 600 if (strcmp(type, "button") == 0)
576 { 601 {
577 bt = elm_button_add(ourGlobals->win); 602 struct _Widget *wid;
578 elm_object_text_set(bt, title); 603
579 evas_object_smart_callback_add(bt, "clicked", _on_done, ourGlobals); 604 wid = calloc(1, sizeof(struct _Widget));
580 evas_object_resize(bt, w, h); 605 strcpy(wid->magic, "Widget");
581 evas_object_move(bt, x, y); 606 wid->obj = elm_button_add(ourGlobals->win);
582 evas_object_show(bt); 607 elm_object_text_set(wid->obj, title);
583 lua_pushlightuserdata(L, &bt); 608 evas_object_smart_callback_add(wid->obj, "clicked", _on_click, L);
609 evas_object_resize(wid->obj, w, h);
610 evas_object_move(wid->obj, x, y);
611 evas_object_show(wid->obj);
612 evas_object_data_set(wid->obj, "Widget", wid);
613 /* Evas_Object *bt isn't a real pointer it seems. At least Lua bitches about it -
614 PANIC: unprotected error in call to Lua API (bad light userdata pointer)
615 So we wrap it.
616 */
617 lua_pushlightuserdata(L, (void *) wid);
584 return 1; 618 return 1;
585 } 619 }
586 620
587 return 0; 621 return 0;
588} 622}
589 623
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) 624static int action(lua_State *L)
596{ 625{
597 Evas_Object *obj= lua_touserdata(L, 1); 626 globals *ourGlobals;
627 struct _Widget *wid = lua_touserdata(L, 1);
598 char *action = "nada"; 628 char *action = "nada";
599 629
600 pull_lua(L, 2, "$", &action); 630 lua_getfield(L, LUA_REGISTRYINDEX, globName);
601printf("Setting action %s\n", action); 631 ourGlobals = lua_touserdata(L, -1);
602 // TODO - stuff the action into the widget somewhere. 632 lua_pop(L, 1);
603 evas_object_smart_callback_add(obj, "clicked", _on_click, L);
604 633
634 pull_lua(L, 2, "$", &action);
635 if (wid && strcmp(wid->magic, "Widget") == 0)
636 {
637 PD("Setting action %s", action);
638 wid->action = strdup(action);
639 }
605 return 0; 640 return 0;
606} 641}
607 642
@@ -795,12 +830,13 @@ void GuiLuaDo(int argc, char **argv)
795 lua_getglobal(L, "require"); 830 lua_getglobal(L, "require");
796 lua_pushstring(L, SKANG); 831 lua_pushstring(L, SKANG);
797 lua_call(L, 1, 1); 832 lua_call(L, 1, 1);
798 lua_pop(L, 1); // Ignore the returned value. 833 lua_setfield(L, LUA_GLOBALSINDEX, SKANG);
799 834
800 835
801 // Run the main loop via a Lua call. 836 // Run the main loop via a Lua call.
802 // This does nothing if no module opened a window. 837 // This does nothing if no module opened a window.
803 lua_pop(L, loopWindow(L)); 838 if (0 != luaL_dostring(L, "skang.loopWindow()"))
839 PEm("Error running - skang.loopWindow()");
804 lua_pop(L, closeWindow(L)); 840 lua_pop(L, closeWindow(L));
805 lua_close(L); 841 lua_close(L);
806 } 842 }
diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua
index e6b6725..fdd61de 100644
--- a/ClientHamr/GuiLua/skang.lua
+++ b/ClientHamr/GuiLua/skang.lua
@@ -881,7 +881,9 @@ thingasm = function (names, ...)
881 local args, err = loadstring('return ' .. thingy.widget) 881 local args, err = loadstring('return ' .. thingy.widget)
882 if args then 882 if args then
883 setfenv(args, parent) 883 setfenv(args, parent)
884 parent.W[name] = {widget = widget(args())} 884 local result = widget(args())
885print('NO IDEA WHY this does isValid() three times on the action, and the first one being a string.')
886 parent.W[name] = {Cwidget = result}
885 else 887 else
886 print("ERROR - " .. err) 888 print("ERROR - " .. err)
887 end 889 end
@@ -1025,21 +1027,21 @@ thingasm('nada', 'Do nothing.', function () --[[ This function intentionally lef
1025local widgets = {} 1027local widgets = {}
1026--thingasm{widgets, 'window', 'The window.', types='userdata'} 1028--thingasm{widgets, 'window', 'The window.', types='userdata'}
1027thingasm{widgets, 'W', 'Holds all the widgets', types='Keyed'} 1029thingasm{widgets, 'W', 'Holds all the widgets', types='Keyed'}
1028widgets.W{'widget', 'The widget.', types='userdata'} 1030widgets.W{'Cwidget', 'The widget.', types='userdata'}
1029widgets.W{'action,a', 'The action for the widget.', 'nada', types='string'} 1031widgets.W{'action,a', 'The action for the widget.', 'nada', types='string'}
1030local aIsValid = function (self, parent) 1032local aIsValid = function (self, parent)
1031 local result = Thing.isValid(self, parent) 1033 local result = Thing.isValid(self, parent)
1032 1034
1033 if result then 1035 if result then
1034 local value = parent[self.names[1] ] 1036 local value = parent[self.names[1] ]
1035print('NEW ACTION - ' .. self.names[1] .. ' = ' .. value) 1037print('NEW ACTION - ' .. self.names[1] .. ' = ' .. value .. ' ' .. type(parent.Cwidget))
1036--printTableStart(parent, '', 'parent') 1038 action(parent.Cwidget, value)
1037 action(parent.widget, value)
1038 end 1039 end
1039 return result 1040 return result
1040end 1041end
1041 1042
1042widgets.W{'look,l', 'The look of the widget.', types='string'} 1043widgets.W{'look,l', 'The look of the widget.', types='string'}
1044--[[
1043widgets.W{'colour,color,c', 'The colours of the widget.', types='table'} 1045widgets.W{'colour,color,c', 'The colours of the widget.', types='table'}
1044widgets.W.c{'red,r', 'The red colour of the widget.', 255, types='number'} 1046widgets.W.c{'red,r', 'The red colour of the widget.', 255, types='number'}
1045widgets.W.c{'green,g', 'The green colour of the widget.', 255, types='number'} 1047widgets.W.c{'green,g', 'The green colour of the widget.', 255, types='number'}
@@ -1051,11 +1053,12 @@ local wMum = getmetatable(widgets.W.c)
1051wMum.__call = function (func, ...) 1053wMum.__call = function (func, ...)
1052 return Colour(func, ...) 1054 return Colour(func, ...)
1053end 1055end
1056]]
1054 1057
1055window = function(w, h, title, name) 1058window = function(w, h, title, name)
1056 name = name or 'myWindow' 1059 name = name or 'myWindow'
1057 local win = {} 1060 local win = {}
1058 win.W = copy(widgets.W, name) 1061 win = copy(widgets, name)
1059 local wMum, wThingy = getStuffed(win.W, 'a') 1062 local wMum, wThingy = getStuffed(win.W, 'a')
1060 wThingy.isValid = aIsValid 1063 wThingy.isValid = aIsValid
1061 win.window = Cwindow(w, h, title, name) 1064 win.window = Cwindow(w, h, title, name)
diff --git a/ClientHamr/GuiLua/test.lua b/ClientHamr/GuiLua/test.lua
index a7e3b7f..65e686f 100644
--- a/ClientHamr/GuiLua/test.lua
+++ b/ClientHamr/GuiLua/test.lua
@@ -193,14 +193,15 @@ print(stuff.s.sa)
193print(stuff.s.sb) 193print(stuff.s.sb)
194print('') 194print('')
195 195
196skang.printTableStart(stuff.s, '', 'stuff.s') 196--skang.printTableStart(stuff.s, '', 'stuff.s')
197skang.printTableStart(stuff.S, '', 'stuff.S') 197--skang.printTableStart(stuff.S, '', 'stuff.S')
198--skang.printTableStart(getmetatable(stuff.S), '', 'stuff.S metatable') 198--skang.printTableStart(getmetatable(stuff.S), '', 'stuff.S metatable')
199 199
200print(stuff.S['record0'].field1) 200print(stuff.S['record0'].field1)
201print(stuff.S['record1'].field0) 201print(stuff.S['record1'].field0)
202print(stuff.S['record2'].field1) 202print(stuff.S['record2'].field1)
203 203
204--skang.printTableStart(stuff.S['record0'], '', 'stuff.S[record0]')
204--skang.printTableStart(getmetatable(stuff.S['record0']), '', 'metatable stuff.S[record0]') 205--skang.printTableStart(getmetatable(stuff.S['record0']), '', 'metatable stuff.S[record0]')
205--skang.printTableStart(getmetatable(stuff.S['record1']), '', 'metatable stuff.S[record1]') 206--skang.printTableStart(getmetatable(stuff.S['record1']), '', 'metatable stuff.S[record1]')
206--skang.printTableStart(getmetatable(stuff.S['record2']), '', 'metatable stuff.S[record2]') 207--skang.printTableStart(getmetatable(stuff.S['record2']), '', 'metatable stuff.S[record2]')
diff --git a/ClientHamr/GuiLua/test.skang b/ClientHamr/GuiLua/test.skang
index 340bb08..0c37f92 100644
--- a/ClientHamr/GuiLua/test.skang
+++ b/ClientHamr/GuiLua/test.skang
@@ -8,9 +8,7 @@
8-- This is a bit more verbose than I wanted. lol 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')
10skang.thingasm{win, 'quitter', 'Quits the skang window', types = 'widget', widget='"button", "Quit", 10, 10, 100, 50'} 10skang.thingasm{win, 'quitter', 'Quits the skang window', types = 'widget', widget='"button", "Quit", 10, 10, 100, 50'}
11skang.printTableStart(win.W.quitter, '', 'quitter') 11win.W.quitter.action = 'skang.quit()' -- TODO Should look it up in ThingSpace.commands, and translat 'quit' into the Lua 'skang.quit()'?
12win.W.quitter.action = 1
13win.W.quitter.action = 'quit' -- 'quit' is looked up in ThingSpace.commands, and translated into the Lua 'skang.quit()'.
14 12
15--other.foo = 'stuff' 13--other.foo = 'stuff'
16this.bar = 'things' 14this.bar = 'things'