summaryrefslogtreecommitdiff
path: root/src/lib/elua/elua.c
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2015-04-23 16:02:58 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2015-05-06 15:05:23 +0100
commit88faba813c7c0369f4e5c1fd521d41f439c8cfe0 (patch)
treebcc02a18a15b7c1aea45b532023d93b2dfbe9e7b /src/lib/elua/elua.c
parent0d8b38a2acd8fc52a87826f30f56d025794ecf21 (diff)
elua lib: merge the 3 setup funcs into one
This allows simpler initialization and elua_util_require can now queue up modules before full initialization is done.
Diffstat (limited to '')
-rw-r--r--src/lib/elua/elua.c53
1 files changed, 48 insertions, 5 deletions
diff --git a/src/lib/elua/elua.c b/src/lib/elua/elua.c
index 234674dfd9..9ad15d17f0 100644
--- a/src/lib/elua/elua.c
+++ b/src/lib/elua/elua.c
@@ -94,6 +94,8 @@ elua_state_free(Elua_State *es)
94 } 94 }
95 else if (es->cmods) 95 else if (es->cmods)
96 eina_list_free(es->cmods); 96 eina_list_free(es->cmods);
97 EINA_LIST_FREE(es->lmods, data)
98 eina_stringshare_del(data);
97 EINA_LIST_FREE(es->lincs, data) 99 EINA_LIST_FREE(es->lincs, data)
98 eina_stringshare_del(data); 100 eina_stringshare_del(data);
99 eina_stringshare_del(es->progname); 101 eina_stringshare_del(es->progname);
@@ -264,8 +266,8 @@ const luaL_reg gettextlib[] =
264 { NULL, NULL } 266 { NULL, NULL }
265}; 267};
266 268
267EAPI Eina_Bool 269static Eina_Bool
268elua_state_i18n_setup(const Elua_State *es) 270_elua_state_i18n_setup(const Elua_State *es)
269{ 271{
270#ifdef ENABLE_NLS 272#ifdef ENABLE_NLS
271 char *(*dgettextp)(const char*, const char*) = dgettext; 273 char *(*dgettextp)(const char*, const char*) = dgettext;
@@ -302,8 +304,8 @@ const luaL_reg _elua_cutillib[] =
302 { NULL , NULL } 304 { NULL , NULL }
303}; 305};
304 306
305EAPI Eina_Bool 307static Eina_Bool
306elua_state_modules_setup(const Elua_State *es) 308_elua_state_modules_setup(const Elua_State *es)
307{ 309{
308 char buf[PATH_MAX]; 310 char buf[PATH_MAX];
309 EINA_SAFETY_ON_NULL_RETURN_VAL(es, EINA_FALSE); 311 EINA_SAFETY_ON_NULL_RETURN_VAL(es, EINA_FALSE);
@@ -370,6 +372,42 @@ _elua_module_system_init(lua_State *L)
370 return 2; 372 return 2;
371} 373}
372 374
375EAPI Eina_Bool
376elua_state_setup(Elua_State *es)
377{
378 Eina_Stringshare *data;
379 Eina_Bool failed = EINA_FALSE;
380
381 if (!_elua_state_modules_setup(es))
382 return EINA_FALSE;
383 if (!_elua_state_i18n_setup(es))
384 return EINA_FALSE;
385 if (!_elua_state_io_setup(es))
386 return EINA_FALSE;
387
388 /* finally require the necessary modules */
389 EINA_LIST_FREE(es->lmods, data)
390 {
391 if (!failed)
392 {
393 if (!elua_state_require_ref_push(es))
394 {
395 failed = EINA_TRUE;
396 break;
397 }
398 lua_pushstring(es->luastate, data);
399 if (elua_util_error_report(es, lua_pcall(es->luastate, 1, 0, 0)))
400 {
401 failed = EINA_TRUE;
402 break;
403 }
404 }
405 eina_stringshare_del(data);
406 }
407
408 return EINA_TRUE;
409}
410
373/* Utility functions - these could be written using the other APIs */ 411/* Utility functions - these could be written using the other APIs */
374 412
375static int 413static int
@@ -435,7 +473,12 @@ elua_util_require(Elua_State *es, const char *libname)
435{ 473{
436 EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1); 474 EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1);
437 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1); 475 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1);
438 EINA_SAFETY_ON_FALSE_RETURN_VAL(elua_state_require_ref_push(es), -1); 476 if (!elua_state_require_ref_push(es))
477 {
478 /* store stuff until things are correctly set up */
479 es->lmods = eina_list_append(es->lmods, eina_stringshare_add(libname));
480 return 0;
481 }
439 lua_pushstring(es->luastate, libname); 482 lua_pushstring(es->luastate, libname);
440 return elua_util_error_report(es, lua_pcall(es->luastate, 1, 0, 0)); 483 return elua_util_error_report(es, lua_pcall(es->luastate, 1, 0, 0));
441} 484}