aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/GuiLua
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-05-05 15:38:31 +1000
committerDavid Walter Seikel2014-05-05 15:38:31 +1000
commit8e20bc4f700597a007cfec9ee2ecd5ba7c94d5c6 (patch)
tree827a56b9aaea0d930f136b01b61c783bd8b8a3ef /src/GuiLua
parentMake logDom a stand alone, plus related fix ups and some clean ups. (diff)
downloadSledjHamr-8e20bc4f700597a007cfec9ee2ecd5ba7c94d5c6.zip
SledjHamr-8e20bc4f700597a007cfec9ee2ecd5ba7c94d5c6.tar.gz
SledjHamr-8e20bc4f700597a007cfec9ee2ecd5ba7c94d5c6.tar.bz2
SledjHamr-8e20bc4f700597a007cfec9ee2ecd5ba7c94d5c6.tar.xz
No more ourGlobals in GuiLua.
Diffstat (limited to 'src/GuiLua')
-rw-r--r--src/GuiLua/GuiLua.c58
-rw-r--r--src/GuiLua/GuiLua.h7
2 files changed, 14 insertions, 51 deletions
diff --git a/src/GuiLua/GuiLua.c b/src/GuiLua/GuiLua.c
index 1f5cbd5..310d90b 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.
147globals ourGlobals; 147static winFang *win;
148static const char *globName = "ourGlobals";
149 148
150 149
151/* Sooo, how to do this - 150/* Sooo, how to do this -
@@ -161,13 +160,12 @@ win.quitter.colour.r = 5 -> direct access to the table, well "direct" via Th
161// TODO - Should be able to open external and internal windows, and even switch between them on the fly. 160// TODO - Should be able to open external and internal windows, and even switch between them on the fly.
162static void _on_click(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) 161static void _on_click(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
163{ 162{
164 globals *ourGlobals; 163 Widget *wid = data;
165 lua_State *L = data;
166 Widget *wid;
167 164
168 wid = evas_object_data_get(obj, "Widget");
169 if (wid) 165 if (wid)
170 { 166 {
167 lua_State *L = wid->data;
168
171 PD("Doing action %s", wid->action); 169 PD("Doing action %s", wid->action);
172 if (0 != luaL_dostring(L, wid->action)) 170 if (0 != luaL_dostring(L, wid->action))
173 PE("Error running - %s", wid->action); 171 PE("Error running - %s", wid->action);
@@ -177,15 +175,10 @@ static void _on_click(void *data, Evas_Object *obj, void *event_info EINA_UNUSED
177// TODO - skang.thingasm() should pass us the winFang pointer it has as the parent module. 175// TODO - skang.thingasm() should pass us the winFang pointer it has as the parent module.
178static int widget(lua_State *L) 176static int widget(lua_State *L)
179{ 177{
180 globals *ourGlobals;
181 char *type = "label"; 178 char *type = "label";
182 char *title = ":"; 179 char *title = ":";
183 int x = 1, y = 1, w = WIDTH/3, h = HEIGHT/3; 180 int x = 1, y = 1, w = WIDTH/3, h = HEIGHT/3;
184 181
185 lua_getfield(L, LUA_REGISTRYINDEX, globName);
186 ourGlobals = lua_touserdata(L, -1);
187 lua_pop(L, 1);
188
189 pull_lua(L, 1, "$type $title %x %y %w %h", &type, &title, &x, &y, &w, &h); 182 pull_lua(L, 1, "$type $title %x %y %w %h", &type, &title, &x, &y, &w, &h);
190 183
191 // Poor mans introspection, until I write real introspection into EFL. 184 // Poor mans introspection, until I write real introspection into EFL.
@@ -195,16 +188,15 @@ static int widget(lua_State *L)
195 Widget *wid; 188 Widget *wid;
196 189
197 // These two lines are likely the only ones that will be different for the different sorts of widgets. 190 // These two lines are likely the only ones that will be different for the different sorts of widgets.
198 wid = widgetAdd(ourGlobals->win, ELM_OBJ_BUTTON_CLASS, ourGlobals->win->win, title); 191 wid = widgetAdd(win, ELM_OBJ_BUTTON_CLASS, win->win, title);
199 evas_object_smart_callback_add(wid->obj, "clicked", _on_click, L); 192 wid->data = L;
200
201 eo_do(wid->obj, 193 eo_do(wid->obj,
202// elm_obj_widget_part_text_set(NULL, wid->label),
203 evas_obj_size_set(w, h), 194 evas_obj_size_set(w, h),
204 evas_obj_position_set(x, y), 195 evas_obj_position_set(x, y),
205 evas_obj_visibility_set(EINA_TRUE), 196 evas_obj_visibility_set(EINA_TRUE),
206 eo_key_data_set("Widget", wid, NULL) 197 eo_key_data_set("Widget", wid, NULL)
207 ); 198 );
199 evas_object_smart_callback_add(wid->obj, "clicked", _on_click, wid);
208 200
209 /* Evas_Object *bt isn't a real pointer it seems. At least Lua bitches about it - 201 /* Evas_Object *bt isn't a real pointer it seems. At least Lua bitches about it -
210 PANIC: unprotected error in call to Lua API (bad light userdata pointer) 202 PANIC: unprotected error in call to Lua API (bad light userdata pointer)
@@ -226,7 +218,7 @@ static int action(lua_State *L)
226 pull_lua(L, 2, "$", &action); 218 pull_lua(L, 2, "$", &action);
227 if (wid && strcmp(wid->magic, "Widget") == 0) 219 if (wid && strcmp(wid->magic, "Widget") == 0)
228 { 220 {
229printf(">>>>>>>>>> Setting action : %s\n", action); 221PD("Setting action : %s\n", action);
230 wid->action = strdup(action); 222 wid->action = strdup(action);
231 } 223 }
232 return 0; 224 return 0;
@@ -241,22 +233,16 @@ static int colour(lua_State *L)
241 233
242static int window(lua_State *L) 234static int window(lua_State *L)
243{ 235{
244 globals *ourGlobals;
245 char *name = "GuiLua"; 236 char *name = "GuiLua";
246 char *title = "GuiLua test harness"; 237 char *title = "GuiLua test harness";
247 int result = 0;
248 int w = WIDTH, h = HEIGHT; 238 int w = WIDTH, h = HEIGHT;
249 239
250 lua_getfield(L, LUA_REGISTRYINDEX, globName);
251 ourGlobals = lua_touserdata(L, -1);
252 lua_pop(L, 1);
253
254 pull_lua(L, 1, "%w %h $title $name", &w, &h, &title, &name); 240 pull_lua(L, 1, "%w %h $title $name", &w, &h, &title, &name);
255 ourGlobals->win = winFangAdd(NULL, 0, 0, w, h, title, name); 241 win = winFangAdd(NULL, 0, 0, w, h, title, name);
256 lua_pushlightuserdata(L, &ourGlobals->win); 242
257 result = 1; 243 lua_pushlightuserdata(L, &win);
258 244
259 return result; 245 return 1;
260} 246}
261 247
262static int clear(lua_State *L) 248static int clear(lua_State *L)
@@ -268,13 +254,7 @@ static int clear(lua_State *L)
268 254
269static int loopWindow(lua_State *L) 255static int loopWindow(lua_State *L)
270{ 256{
271 globals *ourGlobals; 257 if (win)
272
273 lua_getfield(L, LUA_REGISTRYINDEX, globName);
274 ourGlobals = lua_touserdata(L, -1);
275 lua_pop(L, 1);
276
277 if (ourGlobals->win)
278 elm_run(); 258 elm_run();
279 259
280 return 0; 260 return 0;
@@ -289,13 +269,7 @@ static int quit(lua_State *L)
289 269
290static int closeWindow(lua_State *L) 270static int closeWindow(lua_State *L)
291{ 271{
292 globals *ourGlobals; 272 winFangDel(win);
293
294 lua_getfield(L, LUA_REGISTRYINDEX, globName);
295 ourGlobals = lua_touserdata(L, -1);
296 lua_pop(L, 1);
297
298 winFangDel(ourGlobals->win);
299 273
300 if (logDom >= 0) 274 if (logDom >= 0)
301 { 275 {
@@ -342,10 +316,6 @@ int luaopen_GuiLua(lua_State *L)
342// LUA_REGISTRYINDEX - C registry, global, for unique keys use the module name as a string, or a lightuserdata address to a C object in our module. 316// LUA_REGISTRYINDEX - C registry, global, for unique keys use the module name as a string, or a lightuserdata address to a C object in our module.
343// lua_upvalueindex(n) - C function upvalues 317// lua_upvalueindex(n) - C function upvalues
344 318
345 // Shove ourGlobals into the registry.
346 lua_pushlightuserdata(L, &ourGlobals);
347 lua_setfield(L, LUA_REGISTRYINDEX, globName);
348
349 // The skang module should have been loaded by now, so we can just grab it out of package.loaded[]. 319 // The skang module should have been loaded by now, so we can just grab it out of package.loaded[].
350 lua_getglobal(L, "package"); 320 lua_getglobal(L, "package");
351 lua_getfield(L, lua_gettop(L), "loaded"); 321 lua_getfield(L, lua_gettop(L), "loaded");
diff --git a/src/GuiLua/GuiLua.h b/src/GuiLua/GuiLua.h
index 4ea782e..a4a1273 100644
--- a/src/GuiLua/GuiLua.h
+++ b/src/GuiLua/GuiLua.h
@@ -13,11 +13,4 @@
13#define THINGASM "thingasm" 13#define THINGASM "thingasm"
14 14
15 15
16typedef struct _globals
17{
18 winFang *win;
19 int logDom; // Our logging domain.
20} globals;
21
22
23void GuiLuaDo(int argc, char **argv, Eina_Bool mainloop); 16void GuiLuaDo(int argc, char **argv, Eina_Bool mainloop);