aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/GuiLua/GuiLua.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-05-05 18:33:27 +1000
committerDavid Walter Seikel2014-05-05 18:33:27 +1000
commit0407fdd77eaafa13a45b9724471ce85c1dd08116 (patch)
tree25d3797d705ec2c8f76c9ce3b28916effe50c7e6 /src/GuiLua/GuiLua.c
parentGuiLua handles multiple windows now. (diff)
downloadSledjHamr-0407fdd77eaafa13a45b9724471ce85c1dd08116.zip
SledjHamr-0407fdd77eaafa13a45b9724471ce85c1dd08116.tar.gz
SledjHamr-0407fdd77eaafa13a45b9724471ce85c1dd08116.tar.bz2
SledjHamr-0407fdd77eaafa13a45b9724471ce85c1dd08116.tar.xz
GuiLuaDo() now returns astructure, and has that structure in Lua's C registry. Now we can have lots of them.
Diffstat (limited to 'src/GuiLua/GuiLua.c')
-rw-r--r--src/GuiLua/GuiLua.c35
1 files changed, 27 insertions, 8 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
146static int logDom; // Our logging domain. 146static int logDom; // Our logging domain.
147static Eina_Clist winFangs; // The windows we might open. 147static const char *glName = "ourGuiLua";
148
149 148
150/* Sooo, how to do this - 149/* Sooo, how to do this -
151widget has to be a light userdata 150widget 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)
269static int closeWindow(lua_State *L) 273static 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
357void GuiLuaDo(int argc, char **argv, Eina_Bool mainloop) 365GuiLua *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}