aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ClientHamr/GuiLua/GuiLua.c
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/GuiLua/GuiLua.c
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 '')
-rw-r--r--ClientHamr/GuiLua/GuiLua.c76
1 files changed, 56 insertions, 20 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 }