diff options
author | David Walter Seikel | 2014-04-09 09:22:04 +1000 |
---|---|---|
committer | David Walter Seikel | 2014-04-09 09:22:04 +1000 |
commit | bbd34d9c87517994462904d965f4ae70cd5f8dab (patch) | |
tree | 91a46459547bd351bb32905d86e66714bf12b98f /ClientHamr/GuiLua/GuiLua.c | |
parent | Make GuiLua a bit more real, with real Lua functions and stuff. (diff) | |
download | SledjHamr-bbd34d9c87517994462904d965f4ae70cd5f8dab.zip SledjHamr-bbd34d9c87517994462904d965f4ae70cd5f8dab.tar.gz SledjHamr-bbd34d9c87517994462904d965f4ae70cd5f8dab.tar.bz2 SledjHamr-bbd34d9c87517994462904d965f4ae70cd5f8dab.tar.xz |
Pass C command arguments to skang.
Diffstat (limited to 'ClientHamr/GuiLua/GuiLua.c')
-rw-r--r-- | ClientHamr/GuiLua/GuiLua.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/ClientHamr/GuiLua/GuiLua.c b/ClientHamr/GuiLua/GuiLua.c index e3af5ee..25625aa 100644 --- a/ClientHamr/GuiLua/GuiLua.c +++ b/ClientHamr/GuiLua/GuiLua.c | |||
@@ -416,6 +416,8 @@ int luaopen_widget(lua_State *L) | |||
416 | lua_pushstring(L, "skang"); | 416 | lua_pushstring(L, "skang"); |
417 | lua_call(L, 1, 1); | 417 | lua_call(L, 1, 1); |
418 | skang = lua_gettop(L); | 418 | skang = lua_gettop(L); |
419 | lua_setfield(L, LUA_REGISTRYINDEX, "skang"); | ||
420 | lua_getfield(L, LUA_REGISTRYINDEX, "skang"); | ||
419 | 421 | ||
420 | // local _M = skang.moduleBegin('widget', nil, 'Copyright 2014 David Seikel', '0.1', '2014-04-08 00:42:00', nil, false) | 422 | // local _M = skang.moduleBegin('widget', nil, 'Copyright 2014 David Seikel', '0.1', '2014-04-08 00:42:00', nil, false) |
421 | lua_getfield(L, skang, "moduleBegin"); | 423 | lua_getfield(L, skang, "moduleBegin"); |
@@ -468,6 +470,7 @@ int luaopen_widget(lua_State *L) | |||
468 | int main(int argc, char **argv) | 470 | int main(int argc, char **argv) |
469 | { | 471 | { |
470 | int result = EXIT_FAILURE; | 472 | int result = EXIT_FAILURE; |
473 | lua_Number i; | ||
471 | 474 | ||
472 | memset(&ourGlobals, 0, sizeof(globals)); | 475 | memset(&ourGlobals, 0, sizeof(globals)); |
473 | 476 | ||
@@ -482,7 +485,23 @@ int main(int argc, char **argv) | |||
482 | // luaopen_widget() expects a string argument, and returns a table. | 485 | // luaopen_widget() expects a string argument, and returns a table. |
483 | // Though in this case, both get ignored anyway. | 486 | // Though in this case, both get ignored anyway. |
484 | lua_pushstring(ourGlobals.L, "widget"); | 487 | lua_pushstring(ourGlobals.L, "widget"); |
485 | lua_pop(ourGlobals.L, luaopen_widget(ourGlobals.L)); | 488 | lua_pop(ourGlobals.L, luaopen_widget(ourGlobals.L) + 1); |
489 | |||
490 | // Pass all our command line arguments to skang. | ||
491 | i = 1; | ||
492 | lua_getfield(ourGlobals.L, LUA_REGISTRYINDEX, "skang"); | ||
493 | lua_getfield(ourGlobals.L, 1, "scanArguments"); | ||
494 | lua_newtable(ourGlobals.L); | ||
495 | while (--argc > 0 && *++argv != '\0') | ||
496 | { | ||
497 | lua_pushnumber(ourGlobals.L, i++); | ||
498 | lua_pushstring(ourGlobals.L, *argv); | ||
499 | lua_settable(ourGlobals.L, -3); | ||
500 | } | ||
501 | lua_call(ourGlobals.L, 1, 0); | ||
502 | lua_getfield(ourGlobals.L, 1, "pullArguments"); | ||
503 | lua_getfield(ourGlobals.L, LUA_REGISTRYINDEX, "skang"); | ||
504 | lua_call(ourGlobals.L, 1, 0); | ||
486 | 505 | ||
487 | // Run the main loop via a Lua call. | 506 | // Run the main loop via a Lua call. |
488 | lua_pop(ourGlobals.L, loopWindow(ourGlobals.L)); | 507 | lua_pop(ourGlobals.L, loopWindow(ourGlobals.L)); |