summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2015-04-20 17:04:33 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2015-05-06 15:05:22 +0100
commit660a4d7e1c752164aadafcdadb740745f2b123f7 (patch)
tree8d03f1833a7e8cbfa53a4a75f9edc8d86148c8c2 /src
parenta02bb195d9aabc9726dcac1345f8404d60aefaec (diff)
elua lib: docs for elua_util_error_report + remove unnecessary arg
Diffstat (limited to 'src')
-rw-r--r--src/lib/elua/Elua.h17
-rw-r--r--src/lib/elua/elua.c25
2 files changed, 26 insertions, 16 deletions
diff --git a/src/lib/elua/Elua.h b/src/lib/elua/Elua.h
index 08bfc0c3aa..3a172515c5 100644
--- a/src/lib/elua/Elua.h
+++ b/src/lib/elua/Elua.h
@@ -449,8 +449,21 @@ EAPI Eina_Bool elua_util_app_load(Elua_State *es, const char *appname);
449EAPI int elua_util_script_run(Elua_State *es, int argc, char **argv, int n, 449EAPI int elua_util_script_run(Elua_State *es, int argc, char **argv, int n,
450 int *quit); 450 int *quit);
451 451
452EAPI int elua_util_error_report(const Elua_State *es, const char *pname, 452/**
453 int status); 453 * @brief Reports an error using Eina logging.
454 *
455 * If the given status is 0, this function just returns it. Otherwise, it takes
456 * the topmost item on the Lua stack, converts it to string (if it cannot be
457 * converted, a "(non-string error)" placeholder is used) and logs it out
458 * as an error, together with the program name set on Elua state init.
459 *
460 * @param[in] es The Elua state.
461 * @param[in] status The status code.
462 * @return The status code.
463 *
464 * @ingroup Elua
465 */
466EAPI int elua_util_error_report(const Elua_State *es, int status);
454 467
455#endif 468#endif
456 469
diff --git a/src/lib/elua/elua.c b/src/lib/elua/elua.c
index 488438ab0d..234674dfd9 100644
--- a/src/lib/elua/elua.c
+++ b/src/lib/elua/elua.c
@@ -278,7 +278,7 @@ elua_state_i18n_setup(const Elua_State *es)
278 EINA_SAFETY_ON_NULL_RETURN_VAL(es->coredir, EINA_FALSE); 278 EINA_SAFETY_ON_NULL_RETURN_VAL(es->coredir, EINA_FALSE);
279 EINA_SAFETY_ON_NULL_RETURN_VAL(es->progname, EINA_FALSE); 279 EINA_SAFETY_ON_NULL_RETURN_VAL(es->progname, EINA_FALSE);
280 snprintf(buf, sizeof(buf), "%s/gettext.lua", es->coredir); 280 snprintf(buf, sizeof(buf), "%s/gettext.lua", es->coredir);
281 if (elua_util_error_report(es, es->progname, elua_io_loadfile(es, buf))) 281 if (elua_util_error_report(es, elua_io_loadfile(es, buf)))
282 return EINA_FALSE; 282 return EINA_FALSE;
283 lua_createtable(es->luastate, 0, 0); 283 lua_createtable(es->luastate, 0, 0);
284 luaL_register(es->luastate, NULL, gettextlib); 284 luaL_register(es->luastate, NULL, gettextlib);
@@ -311,7 +311,7 @@ elua_state_modules_setup(const Elua_State *es)
311 EINA_SAFETY_ON_NULL_RETURN_VAL(es->coredir, EINA_FALSE); 311 EINA_SAFETY_ON_NULL_RETURN_VAL(es->coredir, EINA_FALSE);
312 EINA_SAFETY_ON_NULL_RETURN_VAL(es->progname, EINA_FALSE); 312 EINA_SAFETY_ON_NULL_RETURN_VAL(es->progname, EINA_FALSE);
313 snprintf(buf, sizeof(buf), "%s/module.lua", es->coredir); 313 snprintf(buf, sizeof(buf), "%s/module.lua", es->coredir);
314 if (elua_util_error_report(es, es->progname, elua_io_loadfile(es, buf))) 314 if (elua_util_error_report(es, elua_io_loadfile(es, buf)))
315 return EINA_FALSE; 315 return EINA_FALSE;
316 lua_pushcfunction(es->luastate, _elua_module_system_init); 316 lua_pushcfunction(es->luastate, _elua_module_system_init);
317 lua_createtable(es->luastate, 0, 0); 317 lua_createtable(es->luastate, 0, 0);
@@ -437,8 +437,7 @@ elua_util_require(Elua_State *es, const char *libname)
437 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1); 437 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1);
438 EINA_SAFETY_ON_FALSE_RETURN_VAL(elua_state_require_ref_push(es), -1); 438 EINA_SAFETY_ON_FALSE_RETURN_VAL(elua_state_require_ref_push(es), -1);
439 lua_pushstring(es->luastate, libname); 439 lua_pushstring(es->luastate, libname);
440 return elua_util_error_report(es, es->progname, 440 return elua_util_error_report(es, lua_pcall(es->luastate, 1, 0, 0));
441 lua_pcall(es->luastate, 1, 0, 0));
442} 441}
443 442
444EAPI int 443EAPI int
@@ -446,9 +445,8 @@ elua_util_file_run(Elua_State *es, const char *fname)
446{ 445{
447 EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1); 446 EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1);
448 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1); 447 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1);
449 return elua_util_error_report(es, es->progname, 448 return elua_util_error_report(es, elua_io_loadfile(es, fname)
450 elua_io_loadfile(es, fname) 449 || _elua_docall(es, 0, 1));
451 || _elua_docall(es, 0, 1));
452} 450}
453 451
454EAPI int 452EAPI int
@@ -456,10 +454,9 @@ elua_util_string_run(Elua_State *es, const char *chunk, const char *chname)
456{ 454{
457 EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1); 455 EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1);
458 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1); 456 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1);
459 return elua_util_error_report(es, es->progname, 457 return elua_util_error_report(es, luaL_loadbuffer(es->luastate, chunk,
460 luaL_loadbuffer(es->luastate, chunk, strlen(chunk), 458 strlen(chunk), chname)
461 chname) 459 || _elua_docall(es, 0, 0));
462 || _elua_docall(es, 0, 0));
463} 460}
464 461
465EAPI Eina_Bool 462EAPI Eina_Bool
@@ -515,7 +512,7 @@ elua_util_script_run(Elua_State *es, int argc, char **argv, int n, int *quit)
515 *quit = lua_toboolean(es->luastate, -1); 512 *quit = lua_toboolean(es->luastate, -1);
516 lua_pop(es->luastate, 1); 513 lua_pop(es->luastate, 1);
517 } 514 }
518 return elua_util_error_report(es, es->progname, status); 515 return elua_util_error_report(es, status);
519} 516}
520 517
521static void 518static void
@@ -525,13 +522,13 @@ _elua_errmsg(const char *pname, const char *msg)
525} 522}
526 523
527EAPI int 524EAPI int
528elua_util_error_report(const Elua_State *es, const char *pname, int status) 525elua_util_error_report(const Elua_State *es, int status)
529{ 526{
530 EINA_SAFETY_ON_FALSE_RETURN_VAL(es && es->luastate, status); 527 EINA_SAFETY_ON_FALSE_RETURN_VAL(es && es->luastate, status);
531 if (status && !lua_isnil(es->luastate, -1)) 528 if (status && !lua_isnil(es->luastate, -1))
532 { 529 {
533 const char *msg = lua_tostring(es->luastate, -1); 530 const char *msg = lua_tostring(es->luastate, -1);
534 _elua_errmsg(pname, msg ? msg : "(non-string error)"); 531 _elua_errmsg(es->progname, msg ? msg : "(non-string error)");
535 lua_pop(es->luastate, 1); 532 lua_pop(es->luastate, 1);
536 } 533 }
537 return status; 534 return status;