summaryrefslogtreecommitdiff
path: root/src/lib/elua
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
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 'src/lib/elua')
-rw-r--r--src/lib/elua/Elua.h34
-rw-r--r--src/lib/elua/cache.c4
-rw-r--r--src/lib/elua/elua.c53
-rw-r--r--src/lib/elua/elua_private.h2
4 files changed, 61 insertions, 32 deletions
diff --git a/src/lib/elua/Elua.h b/src/lib/elua/Elua.h
index 3a172515c5..93814a359d 100644
--- a/src/lib/elua/Elua.h
+++ b/src/lib/elua/Elua.h
@@ -307,45 +307,29 @@ EAPI Eina_Bool elua_state_appload_ref_push(Elua_State *es);
307EAPI lua_State *elua_state_lua_state_get(const Elua_State *es); 307EAPI lua_State *elua_state_lua_state_get(const Elua_State *es);
308 308
309/** 309/**
310 * @brief Set up internationalization support for an Elua state. 310 * @brief Set up the Elua state.
311 *
312 * This API function sets up 3 things, module system, i18n and I/O. After that
313 * it requires all modules not yet required (i.e. those queued in before the
314 * state was fully initialized).
311 * 315 *
312 * This function sets up correct i18n for an Elua state. That means loading 316 * This function sets up correct i18n for an Elua state. That means loading
313 * the gettext bindings and making Lua aware of them. This also works when 317 * the gettext bindings and making Lua aware of them. This also works when
314 * i18n support is disabled at compilation time, so you can just call it 318 * i18n support is disabled at compilation time, so you can just call it
315 * unconditionally. 319 * unconditionally.
316 * 320 *
317 * @param[in] es The Elua state. 321 * This also loads the Elua module system and makes Lua aware of it. It also
318 * @return EINA_TRUE on success, EINA_FALSE on failure.
319 *
320 * @ingroup Elua
321 */
322EAPI Eina_Bool elua_state_i18n_setup(const Elua_State *es);
323
324/**
325 * @brief Set up module support for an Elua state.
326 *
327 * This loads the Elua module system and makes Lua aware of it. It also
328 * registers the Elua C utility library module. 322 * registers the Elua C utility library module.
329 * 323 *
330 * @param[in] es The Elua state. 324 * Finally, Elua provides its own loadfile based around mmap to replace the
331 * @return EINA_TRUE on success, EINA_FALSE on failure. 325 * less efficient Lua version. This function takes care of the setup.
332 *
333 * @ingroup Elua
334 */
335EAPI Eina_Bool elua_state_modules_setup(const Elua_State *es);
336
337/**
338 * @brief Set up IO support for an Elua state.
339 *
340 * Elua provides its own loadfile based around mmap to replace the less
341 * efficient Lua version. This function takes care of the setup.
342 * 326 *
343 * @param[in] es The Elua state. 327 * @param[in] es The Elua state.
344 * @return EINA_TRUE on success, EINA_FALSE on failure. 328 * @return EINA_TRUE on success, EINA_FALSE on failure.
345 * 329 *
346 * @ingroup Elua 330 * @ingroup Elua
347 */ 331 */
348EAPI Eina_Bool elua_state_io_setup(const Elua_State *es); 332EAPI Eina_Bool elua_state_setup(Elua_State *es);
349 333
350/** 334/**
351 * @brief Loads a file using Elua's own mmap-based IO. 335 * @brief Loads a file using Elua's own mmap-based IO.
diff --git a/src/lib/elua/cache.c b/src/lib/elua/cache.c
index 43ef3d7d19..b856b0bde9 100644
--- a/src/lib/elua/cache.c
+++ b/src/lib/elua/cache.c
@@ -208,8 +208,8 @@ loadfile(lua_State *L)
208 return 2; 208 return 2;
209} 209}
210 210
211EAPI Eina_Bool 211Eina_Bool
212elua_state_io_setup(const Elua_State *es) 212_elua_state_io_setup(const Elua_State *es)
213{ 213{
214 EINA_SAFETY_ON_FALSE_RETURN_VAL(es && es->luastate, EINA_FALSE); 214 EINA_SAFETY_ON_FALSE_RETURN_VAL(es && es->luastate, EINA_FALSE);
215 lua_pushcfunction(es->luastate, loadfile); 215 lua_pushcfunction(es->luastate, loadfile);
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}
diff --git a/src/lib/elua/elua_private.h b/src/lib/elua/elua_private.h
index cf24e1e661..53b514e627 100644
--- a/src/lib/elua/elua_private.h
+++ b/src/lib/elua/elua_private.h
@@ -34,6 +34,7 @@ struct _Elua_State
34 Eina_Stringshare *coredir; 34 Eina_Stringshare *coredir;
35 Eina_Stringshare *moddir; 35 Eina_Stringshare *moddir;
36 Eina_Stringshare *appsdir; 36 Eina_Stringshare *appsdir;
37 Eina_List *lmods;
37 Eina_List *cmods; 38 Eina_List *cmods;
38 Eina_List *lincs; 39 Eina_List *lincs;
39 int requireref, apploadref; 40 int requireref, apploadref;
@@ -48,5 +49,6 @@ extern int _elua_log_dom;
48#define CRT(...) EINA_LOG_DOM_CRITICAL(_elua_log_dom, __VA_ARGS__) 49#define CRT(...) EINA_LOG_DOM_CRITICAL(_elua_log_dom, __VA_ARGS__)
49 50
50int _elua_io_popen(lua_State *L); 51int _elua_io_popen(lua_State *L);
52Eina_Bool _elua_state_io_setup(const Elua_State *es);
51 53
52#endif 54#endif