diff options
-rw-r--r-- | src/GuiLua/GuiLua.c | 35 | ||||
-rw-r--r-- | src/GuiLua/GuiLua.h | 13 | ||||
-rw-r--r-- | src/GuiLua/skang.c | 2 |
3 files changed, 40 insertions, 10 deletions
diff --git a/src/GuiLua/GuiLua.c b/src/GuiLua/GuiLua.c index f3956cb..2b09675 100644 --- a/src/GuiLua/GuiLua.c +++ b/src/GuiLua/GuiLua.c | |||
@@ -144,8 +144,7 @@ and ordinary elementary widgets. Proper introspection can come later. | |||
144 | 144 | ||
145 | 145 | ||
146 | static int logDom; // Our logging domain. | 146 | static int logDom; // Our logging domain. |
147 | static Eina_Clist winFangs; // The windows we might open. | 147 | static const char *glName = "ourGuiLua"; |
148 | |||
149 | 148 | ||
150 | /* Sooo, how to do this - | 149 | /* Sooo, how to do this - |
151 | widget has to be a light userdata | 150 | widget has to be a light userdata |
@@ -236,10 +235,15 @@ static int window(lua_State *L) | |||
236 | char *name = "GuiLua"; | 235 | char *name = "GuiLua"; |
237 | char *title = "GuiLua test harness"; | 236 | char *title = "GuiLua test harness"; |
238 | int w = WIDTH, h = HEIGHT; | 237 | int w = WIDTH, h = HEIGHT; |
238 | GuiLua *gl; | ||
239 | |||
240 | lua_getfield(L, LUA_REGISTRYINDEX, glName); | ||
241 | gl = lua_touserdata(L, -1); | ||
242 | lua_pop(L, 1); | ||
239 | 243 | ||
240 | pull_lua(L, 1, "%w %h $title $name", &w, &h, &title, &name); | 244 | pull_lua(L, 1, "%w %h $title $name", &w, &h, &title, &name); |
241 | win = winFangAdd(NULL, 0, 0, w, h, title, name); | 245 | win = winFangAdd(NULL, 0, 0, w, h, title, name); |
242 | eina_clist_add_head(&winFangs, &win->node); | 246 | eina_clist_add_head(&gl->winFangs, &win->node); |
243 | lua_pushlightuserdata(L, win); | 247 | lua_pushlightuserdata(L, win); |
244 | 248 | ||
245 | return 1; | 249 | return 1; |
@@ -269,8 +273,14 @@ static int quit(lua_State *L) | |||
269 | static int closeWindow(lua_State *L) | 273 | static int closeWindow(lua_State *L) |
270 | { | 274 | { |
271 | winFang *win; | 275 | winFang *win; |
276 | GuiLua *gl; | ||
277 | |||
278 | lua_getfield(L, LUA_REGISTRYINDEX, glName); | ||
279 | gl = lua_touserdata(L, -1); | ||
280 | lua_pop(L, 1); | ||
281 | |||
272 | 282 | ||
273 | EINA_CLIST_FOR_EACH_ENTRY(win, &winFangs, winFang, node) | 283 | EINA_CLIST_FOR_EACH_ENTRY(win, &gl->winFangs, winFang, node) |
274 | { | 284 | { |
275 | winFangDel(win); | 285 | winFangDel(win); |
276 | } | 286 | } |
@@ -314,8 +324,6 @@ int luaopen_GuiLua(lua_State *L) | |||
314 | elm_config_finger_size_set(0); | 324 | elm_config_finger_size_set(0); |
315 | elm_config_scale_set(1.0); | 325 | elm_config_scale_set(1.0); |
316 | 326 | ||
317 | eina_clist_init(&winFangs); | ||
318 | |||
319 | // pseudo-indices, special tables that can be accessed like the stack - | 327 | // pseudo-indices, special tables that can be accessed like the stack - |
320 | // LUA_GLOBALSINDEX - thread environment, where globals are | 328 | // LUA_GLOBALSINDEX - thread environment, where globals are |
321 | // LUA_ENVIRONINDEX - C function environment, in this case luaopen_GuiLUa() is the C function | 329 | // LUA_ENVIRONINDEX - C function environment, in this case luaopen_GuiLUa() is the C function |
@@ -354,14 +362,20 @@ PD("GuiLua 3"); | |||
354 | return 1; | 362 | return 1; |
355 | } | 363 | } |
356 | 364 | ||
357 | void GuiLuaDo(int argc, char **argv, Eina_Bool mainloop) | 365 | GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent) |
358 | { | 366 | { |
367 | GuiLua *result; | ||
359 | lua_State *L; | 368 | lua_State *L; |
360 | lua_Number i; | 369 | lua_Number i; |
361 | 370 | ||
371 | result = calloc(1, sizeof(GuiLua)); | ||
372 | result->parent = parent; | ||
373 | eina_clist_init(&result->winFangs); | ||
374 | |||
362 | L = luaL_newstate(); | 375 | L = luaL_newstate(); |
363 | if (L) | 376 | if (L) |
364 | { | 377 | { |
378 | result->L = L; | ||
365 | luaL_openlibs(L); | 379 | luaL_openlibs(L); |
366 | 380 | ||
367 | // Pass all our command line arguments to Lua. | 381 | // Pass all our command line arguments to Lua. |
@@ -375,6 +389,9 @@ void GuiLuaDo(int argc, char **argv, Eina_Bool mainloop) | |||
375 | } | 389 | } |
376 | lua_setfield(L, LUA_GLOBALSINDEX, "arg"); | 390 | lua_setfield(L, LUA_GLOBALSINDEX, "arg"); |
377 | 391 | ||
392 | // Shove our structure into the registry. | ||
393 | lua_pushlightuserdata(L, result); | ||
394 | lua_setfield(L, LUA_REGISTRYINDEX, glName); | ||
378 | 395 | ||
379 | // When we do this, skang will process all the arguments passed to GuiLuaDo(). | 396 | // When we do this, skang will process all the arguments passed to GuiLuaDo(). |
380 | // This likely includes a module load, which likely opens a window. | 397 | // This likely includes a module load, which likely opens a window. |
@@ -384,7 +401,7 @@ void GuiLuaDo(int argc, char **argv, Eina_Bool mainloop) | |||
384 | lua_setfield(L, LUA_GLOBALSINDEX, SKANG); | 401 | lua_setfield(L, LUA_GLOBALSINDEX, SKANG); |
385 | 402 | ||
386 | 403 | ||
387 | if (mainloop) | 404 | if (!parent) |
388 | { | 405 | { |
389 | // Run the main loop via a Lua call. | 406 | // Run the main loop via a Lua call. |
390 | // This does nothing if no module opened a window. | 407 | // This does nothing if no module opened a window. |
@@ -396,4 +413,6 @@ void GuiLuaDo(int argc, char **argv, Eina_Bool mainloop) | |||
396 | } | 413 | } |
397 | else | 414 | else |
398 | fprintf(stderr, "Failed to start Lua!\n"); | 415 | fprintf(stderr, "Failed to start Lua!\n"); |
416 | |||
417 | return result; | ||
399 | } | 418 | } |
diff --git a/src/GuiLua/GuiLua.h b/src/GuiLua/GuiLua.h index a4a1273..fd766e6 100644 --- a/src/GuiLua/GuiLua.h +++ b/src/GuiLua/GuiLua.h | |||
@@ -13,4 +13,15 @@ | |||
13 | #define THINGASM "thingasm" | 13 | #define THINGASM "thingasm" |
14 | 14 | ||
15 | 15 | ||
16 | void GuiLuaDo(int argc, char **argv, Eina_Bool mainloop); | 16 | typedef struct _GuiLua |
17 | { | ||
18 | lua_State *L; | ||
19 | winFang *parent; // Our parent window, if it exists. | ||
20 | Eina_Clist winFangs; // The windows we might open. | ||
21 | |||
22 | Eina_Clist node; | ||
23 | void *data; | ||
24 | Evas_Smart_Cb on_del; | ||
25 | } GuiLua; | ||
26 | |||
27 | GuiLua *GuiLuaDo(int argc, char **argv, winFang *parent); | ||
diff --git a/src/GuiLua/skang.c b/src/GuiLua/skang.c index 19e448b..c15108b 100644 --- a/src/GuiLua/skang.c +++ b/src/GuiLua/skang.c | |||
@@ -4,7 +4,7 @@ | |||
4 | EAPI_MAIN int elm_main(int argc, char **argv) | 4 | EAPI_MAIN int elm_main(int argc, char **argv) |
5 | { | 5 | { |
6 | HamrTime(elm_main, "GuiLua"); | 6 | HamrTime(elm_main, "GuiLua"); |
7 | GuiLuaDo(argc, argv, EINA_TRUE); | 7 | GuiLuaDo(argc, argv, NULL); |
8 | 8 | ||
9 | return 0; | 9 | return 0; |
10 | } | 10 | } |