summaryrefslogtreecommitdiff
path: root/src/lib/elua
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@samsung.com>2015-04-14 16:14:51 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2015-05-06 15:05:20 +0100
commit7f05cfc0e6795f4dee66c0b9175c658f40d14ab4 (patch)
treeac2a7b06b9e0f0c35f4ffe186582bdbb7b93da1d /src/lib/elua
parentf8f9cc14a798a4e760e09c6c3a2d54eea02e40ee (diff)
elua lib: error_report is now in util namespace
Diffstat (limited to 'src/lib/elua')
-rw-r--r--src/lib/elua/Elua.h5
-rw-r--r--src/lib/elua/elua.c50
2 files changed, 28 insertions, 27 deletions
diff --git a/src/lib/elua/Elua.h b/src/lib/elua/Elua.h
index 1d45e1c5cb..880c7736a2 100644
--- a/src/lib/elua/Elua.h
+++ b/src/lib/elua/Elua.h
@@ -87,8 +87,6 @@ EAPI Eina_Bool elua_state_appload_ref_push(Elua_State *es);
87 87
88EAPI lua_State *elua_state_lua_state_get(const Elua_State *es); 88EAPI lua_State *elua_state_lua_state_get(const Elua_State *es);
89 89
90EAPI int elua_error_report(const Elua_State *es, const char *pname, int status);
91
92EAPI Eina_Bool elua_state_i18n_setup(const Elua_State *es); 90EAPI Eina_Bool elua_state_i18n_setup(const Elua_State *es);
93EAPI Eina_Bool elua_state_modules_setup(const Elua_State *es); 91EAPI Eina_Bool elua_state_modules_setup(const Elua_State *es);
94EAPI Eina_Bool elua_state_io_setup(const Elua_State *es); 92EAPI Eina_Bool elua_state_io_setup(const Elua_State *es);
@@ -107,6 +105,9 @@ EAPI Eina_Bool elua_util_app_load(Elua_State *es, const char *appname);
107EAPI int elua_util_script_run(Elua_State *es, int argc, char **argv, int n, 105EAPI int elua_util_script_run(Elua_State *es, int argc, char **argv, int n,
108 int *quit); 106 int *quit);
109 107
108EAPI int elua_util_error_report(const Elua_State *es, const char *pname,
109 int status);
110
110#endif 111#endif
111 112
112#ifdef __cplusplus 113#ifdef __cplusplus
diff --git a/src/lib/elua/elua.c b/src/lib/elua/elua.c
index 229eb65a12..799dd07ee2 100644
--- a/src/lib/elua/elua.c
+++ b/src/lib/elua/elua.c
@@ -230,25 +230,6 @@ elua_state_from_lua_state_get(lua_State *L)
230 return NULL; 230 return NULL;
231} 231}
232 232
233static void
234_elua_errmsg(const char *pname, const char *msg)
235{
236 ERR("%s%s%s", pname ? pname : "", pname ? ": " : "", msg);
237}
238
239EAPI int
240elua_error_report(const Elua_State *es, const char *pname, int status)
241{
242 EINA_SAFETY_ON_FALSE_RETURN_VAL(es && es->luastate, status);
243 if (status && !lua_isnil(es->luastate, -1))
244 {
245 const char *msg = lua_tostring(es->luastate, -1);
246 _elua_errmsg(pname, msg ? msg : "(non-string error)");
247 lua_pop(es->luastate, 1);
248 }
249 return status;
250}
251
252static int 233static int
253_elua_gettext_bind_textdomain(lua_State *L) 234_elua_gettext_bind_textdomain(lua_State *L)
254{ 235{
@@ -297,7 +278,7 @@ elua_state_i18n_setup(const Elua_State *es)
297 EINA_SAFETY_ON_NULL_RETURN_VAL(es->coredir, EINA_FALSE); 278 EINA_SAFETY_ON_NULL_RETURN_VAL(es->coredir, EINA_FALSE);
298 EINA_SAFETY_ON_NULL_RETURN_VAL(es->progname, EINA_FALSE); 279 EINA_SAFETY_ON_NULL_RETURN_VAL(es->progname, EINA_FALSE);
299 snprintf(buf, sizeof(buf), "%s/gettext.lua", es->coredir); 280 snprintf(buf, sizeof(buf), "%s/gettext.lua", es->coredir);
300 if (elua_error_report(es, es->progname, elua_io_loadfile(es, buf))) 281 if (elua_util_error_report(es, es->progname, elua_io_loadfile(es, buf)))
301 return EINA_FALSE; 282 return EINA_FALSE;
302 lua_createtable(es->luastate, 0, 0); 283 lua_createtable(es->luastate, 0, 0);
303 luaL_register(es->luastate, NULL, gettextlib); 284 luaL_register(es->luastate, NULL, gettextlib);
@@ -327,7 +308,7 @@ elua_state_modules_setup(const Elua_State *es)
327 EINA_SAFETY_ON_NULL_RETURN_VAL(es->coredir, EINA_FALSE); 308 EINA_SAFETY_ON_NULL_RETURN_VAL(es->coredir, EINA_FALSE);
328 EINA_SAFETY_ON_NULL_RETURN_VAL(es->progname, EINA_FALSE); 309 EINA_SAFETY_ON_NULL_RETURN_VAL(es->progname, EINA_FALSE);
329 snprintf(buf, sizeof(buf), "%s/module.lua", es->coredir); 310 snprintf(buf, sizeof(buf), "%s/module.lua", es->coredir);
330 if (elua_error_report(es, es->progname, elua_io_loadfile(es, buf))) 311 if (elua_util_error_report(es, es->progname, elua_io_loadfile(es, buf)))
331 return EINA_FALSE; 312 return EINA_FALSE;
332 lua_pushcfunction(es->luastate, elua_module_system_init); 313 lua_pushcfunction(es->luastate, elua_module_system_init);
333 lua_createtable(es->luastate, 0, 0); 314 lua_createtable(es->luastate, 0, 0);
@@ -453,7 +434,7 @@ elua_util_require(Elua_State *es, const char *libname)
453 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1); 434 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1);
454 EINA_SAFETY_ON_FALSE_RETURN_VAL(elua_state_require_ref_push(es), -1); 435 EINA_SAFETY_ON_FALSE_RETURN_VAL(elua_state_require_ref_push(es), -1);
455 lua_pushstring(es->luastate, libname); 436 lua_pushstring(es->luastate, libname);
456 return elua_error_report(es, es->progname, 437 return elua_util_error_report(es, es->progname,
457 lua_pcall(es->luastate, 1, 0, 0)); 438 lua_pcall(es->luastate, 1, 0, 0));
458} 439}
459 440
@@ -462,7 +443,7 @@ elua_util_file_run(Elua_State *es, const char *fname)
462{ 443{
463 EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1); 444 EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1);
464 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1); 445 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1);
465 return elua_error_report(es, es->progname, 446 return elua_util_error_report(es, es->progname,
466 elua_io_loadfile(es, fname) 447 elua_io_loadfile(es, fname)
467 || _elua_docall(es, 0, 1)); 448 || _elua_docall(es, 0, 1));
468} 449}
@@ -472,7 +453,7 @@ elua_util_string_run(Elua_State *es, const char *chunk, const char *chname)
472{ 453{
473 EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1); 454 EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1);
474 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1); 455 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1);
475 return elua_error_report(es, es->progname, 456 return elua_util_error_report(es, es->progname,
476 luaL_loadbuffer(es->luastate, chunk, strlen(chunk), 457 luaL_loadbuffer(es->luastate, chunk, strlen(chunk),
477 chname) 458 chname)
478 || _elua_docall(es, 0, 0)); 459 || _elua_docall(es, 0, 0));
@@ -531,5 +512,24 @@ elua_util_script_run(Elua_State *es, int argc, char **argv, int n, int *quit)
531 *quit = lua_toboolean(es->luastate, -1); 512 *quit = lua_toboolean(es->luastate, -1);
532 lua_pop(es->luastate, 1); 513 lua_pop(es->luastate, 1);
533 } 514 }
534 return elua_error_report(es, es->progname, status); 515 return elua_util_error_report(es, es->progname, status);
516}
517
518static void
519_elua_errmsg(const char *pname, const char *msg)
520{
521 ERR("%s%s%s", pname ? pname : "", pname ? ": " : "", msg);
522}
523
524EAPI int
525elua_util_error_report(const Elua_State *es, const char *pname, int status)
526{
527 EINA_SAFETY_ON_FALSE_RETURN_VAL(es && es->luastate, status);
528 if (status && !lua_isnil(es->luastate, -1))
529 {
530 const char *msg = lua_tostring(es->luastate, -1);
531 _elua_errmsg(pname, msg ? msg : "(non-string error)");
532 lua_pop(es->luastate, 1);
533 }
534 return status;
535} 535}