aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ClientHamr
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ClientHamr/GuiLua/GuiLua.c61
-rw-r--r--ClientHamr/GuiLua/GuiLua.h1
-rwxr-xr-xClientHamr/GuiLua/build.sh1
-rw-r--r--ClientHamr/GuiLua/test.lua1
4 files changed, 36 insertions, 28 deletions
diff --git a/ClientHamr/GuiLua/GuiLua.c b/ClientHamr/GuiLua/GuiLua.c
index c441fcf..49c62b8 100644
--- a/ClientHamr/GuiLua/GuiLua.c
+++ b/ClientHamr/GuiLua/GuiLua.c
@@ -531,8 +531,6 @@ static int window(lua_State *L)
531 ourGlobals = lua_touserdata(L, -1); 531 ourGlobals = lua_touserdata(L, -1);
532 lua_pop(L, 1); 532 lua_pop(L, 1);
533 533
534 loggingStartup(ourGlobals);
535 PI("GuiLua running as an application.\n");
536 if (pull_lua(L, 1, "%w %h $title", &w, &h, &title) > 0) 534 if (pull_lua(L, 1, "%w %h $title", &w, &h, &title) > 0)
537 PI("Setting window to %d %d %s", w, h, title); 535 PI("Setting window to %d %d %s", w, h, title);
538 else 536 else
@@ -601,6 +599,14 @@ int luaopen_widget(lua_State *L)
601{ 599{
602 // In theory, the only thing on the stack now is 'widget' from the require() call. 600 // In theory, the only thing on the stack now is 'widget' from the require() call.
603 601
602 // In theory this function only ever gets called once.
603 memset(&ourGlobals, 0, sizeof(globals));
604 loggingStartup(&ourGlobals);
605
606 // Shove ourGlobals into the registry.
607 lua_pushlightuserdata(L, &ourGlobals);
608 lua_setfield(L, LUA_REGISTRYINDEX, "ourGlobals");
609
604// pseudo-indices, special tables that can be accessed like the stack - 610// pseudo-indices, special tables that can be accessed like the stack -
605// LUA_GLOBALSINDEX - thread environment, where globals are 611// LUA_GLOBALSINDEX - thread environment, where globals are
606// LUA_ENVIRONINDEX - C function environment, in this case luaopen_test_c() is the C function 612// LUA_ENVIRONINDEX - C function environment, in this case luaopen_test_c() is the C function
@@ -618,14 +624,17 @@ int luaopen_widget(lua_State *L)
618 lua_pushstring(L, "skang"); 624 lua_pushstring(L, "skang");
619 lua_call(L, 1, 1); 625 lua_call(L, 1, 1);
620 skang = lua_gettop(L); 626 skang = lua_gettop(L);
627
621 lua_setfield(L, LUA_REGISTRYINDEX, "skang"); 628 lua_setfield(L, LUA_REGISTRYINDEX, "skang");
622 lua_getfield(L, LUA_REGISTRYINDEX, "skang"); 629 lua_getfield(L, LUA_REGISTRYINDEX, "skang");
623 630
624// local _M = skang.moduleBegin('widget', nil, 'Copyright 2014 David Seikel', '0.1', '2014-04-08 00:42:00', nil, false) 631// local _M = skang.moduleBegin('widget', nil, 'Copyright 2014 David Seikel', '0.1', '2014-04-08 00:42:00', nil, false)
625 push_lua(L, "@ ( $ ~ $ $ $ ~ ! )", skang, "moduleBegin", ourName, "Copyright 2014 David Seikel", "0.1", "2014-04-08 00:42:00", 0, 1); 632 push_lua(L, "@ ( $ ~ $ $ $ ~ ! )", skang, "moduleBegin", ourName, "Copyright 2014 David Seikel", "0.1", "2014-04-08 00:42:00", 0, 1);
626 _M = lua_gettop(L); 633 _M = lua_gettop(L);
634
627 // Save this module in the C registry. 635 // Save this module in the C registry.
628 lua_setfield(L, LUA_REGISTRYINDEX, ourName); 636 lua_setfield(L, LUA_REGISTRYINDEX, ourName);
637 lua_getfield(L, LUA_REGISTRYINDEX, ourName);
629 638
630 // Define our functions. 639 // Define our functions.
631 push_lua(L, "@ ( @ $ $ & $ )", skang, "thingasm", LUA_REGISTRYINDEX, ourName, "window", "Opens our window.", window, "number,number,string", 0); 640 push_lua(L, "@ ( @ $ $ & $ )", skang, "thingasm", LUA_REGISTRYINDEX, ourName, "window", "Opens our window.", window, "number,number,string", 0);
@@ -642,41 +651,41 @@ int luaopen_widget(lua_State *L)
642 651
643void GuiLuaDo(int argc, char **argv) 652void GuiLuaDo(int argc, char **argv)
644{ 653{
654 lua_State *L; // Our Lua state.
645 lua_Number i; 655 lua_Number i;
646 656
647 memset(&ourGlobals, 0, sizeof(globals));
648 657
649 ourGlobals.L = luaL_newstate(); 658 L = luaL_newstate();
650 if (ourGlobals.L) 659 if (L)
651 { 660 {
652 luaL_openlibs(ourGlobals.L); 661 luaL_openlibs(L);
653 // Shove ourGlobals into the registry.
654 lua_pushlightuserdata(ourGlobals.L, &ourGlobals);
655 lua_setfield(ourGlobals.L, LUA_REGISTRYINDEX, "ourGlobals");
656 662
657 // luaopen_widget() expects a string argument, and returns a table. 663 // Pass all our command line arguments to Lua.
658 // Though in this case, both get ignored anyway.
659 lua_pushstring(ourGlobals.L, "widget");
660 lua_pop(ourGlobals.L, luaopen_widget(ourGlobals.L) + 1);
661
662 // Pass all our command line arguments to skang.
663 i = 1; 664 i = 1;
664 push_lua(ourGlobals.L, "@ ( @", LUA_REGISTRYINDEX, "skang", 1, "scanArguments"); 665 lua_newtable(L);
665 lua_newtable(ourGlobals.L);
666 while (--argc > 0 && *++argv != '\0') 666 while (--argc > 0 && *++argv != '\0')
667 { 667 {
668 lua_pushnumber(ourGlobals.L, i++); 668 lua_pushnumber(L, i++);
669 lua_pushstring(ourGlobals.L, *argv); 669 lua_pushstring(L, *argv);
670 lua_settable(ourGlobals.L, -3); 670 lua_settable(L, -3);
671 } 671 }
672 lua_call(ourGlobals.L, 1, 0); 672 lua_setfield(L, LUA_GLOBALSINDEX, "arg");
673 push_lua(ourGlobals.L, "@ ( @ )", 1, "pullArguments", LUA_REGISTRYINDEX, "skang", 0);
674 673
675 // Run the main loop via a Lua call.
676 lua_pop(ourGlobals.L, loopWindow(ourGlobals.L));
677 674
678 lua_pop(ourGlobals.L, closeWindow(ourGlobals.L)); 675 lua_getglobal(L, "require");
679 lua_close(ourGlobals.L); 676 lua_pushstring(L, "skang");
677 // When we do this, skang will process all the arguments passed to GuiLuaDo().
678 // This likely includes a module load, which likely loads the widget module above.
679 lua_call(L, 1, 1);
680 skang = lua_gettop(L);
681 lua_setfield(L, LUA_REGISTRYINDEX, "skang");
682
683
684 // Run the main loop via a Lua call.
685 // This does nothing if no module opened a window.
686 lua_pop(L, loopWindow(L));
687 lua_pop(L, closeWindow(L));
688 lua_close(L);
680 } 689 }
681 else 690 else
682 fprintf(stderr, "Failed to start Lua!\n"); 691 fprintf(stderr, "Failed to start Lua!\n");
diff --git a/ClientHamr/GuiLua/GuiLua.h b/ClientHamr/GuiLua/GuiLua.h
index dfc554a..1041224 100644
--- a/ClientHamr/GuiLua/GuiLua.h
+++ b/ClientHamr/GuiLua/GuiLua.h
@@ -46,7 +46,6 @@ typedef enum
46struct _globals 46struct _globals
47{ 47{
48 Evas_Object *win; // Our Elm window. 48 Evas_Object *win; // Our Elm window.
49 lua_State *L; // Our Lua state.
50 int logDom; // Our logging domain. 49 int logDom; // Our logging domain.
51}; 50};
52 51
diff --git a/ClientHamr/GuiLua/build.sh b/ClientHamr/GuiLua/build.sh
index 076c106..c39df5b 100755
--- a/ClientHamr/GuiLua/build.sh
+++ b/ClientHamr/GuiLua/build.sh
@@ -23,5 +23,6 @@ gcc $CFLAGS -fPIC -shared -o test_c.so test_c.c
23gcc $CFLAGS -fPIC -c GuiLua.c 23gcc $CFLAGS -fPIC -c GuiLua.c
24echo "C libraries" 24echo "C libraries"
25gcc $CFLAGS -shared -Wl,-soname,libGuiLua.so -o libGuiLua.so GuiLua.o 25gcc $CFLAGS -shared -Wl,-soname,libGuiLua.so -o libGuiLua.so GuiLua.o
26ln -fs libGuiLua.so widget.so
26echo "C apps" 27echo "C apps"
27gcc $CFLAGS -Wl,-export-dynamic -o skang skang.c $LDFLAGS -lGuiLua $libs 28gcc $CFLAGS -Wl,-export-dynamic -o skang skang.c $LDFLAGS -lGuiLua $libs
diff --git a/ClientHamr/GuiLua/test.lua b/ClientHamr/GuiLua/test.lua
index d484cf2..fc5de1b 100644
--- a/ClientHamr/GuiLua/test.lua
+++ b/ClientHamr/GuiLua/test.lua
@@ -42,7 +42,6 @@ local copy = skang.copy(test, 'copy')
42 42
43print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.get(test, 'ffunc', 'help') .. ' ->> ' .. skang.get(test, 'f', 'action')) 43print('End ' .. test.bar .. ' ' .. test.VERSION .. ' ' .. skang.get(test, 'ffunc', 'help') .. ' ->> ' .. skang.get(test, 'f', 'action'))
44 44
45print(test.DEFAULT_SKANG)
46print('') 45print('')
47 46
48print('foo = ' .. test.foo .. ' ->> ' .. skang.get(test, 'foo', 'help')) 47print('foo = ' .. test.foo .. ' ->> ' .. skang.get(test, 'foo', 'help'))