From db66fe62551c170da81b071c0055b3b3dd4159da Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Mon, 27 Apr 2015 11:30:33 +0100 Subject: [PATCH] elua lib: fix elua_util_app_load + docs --- src/lib/elua/Elua.h | 14 ++++++++++---- src/lib/elua/elua.c | 14 +++++++------- src/tests/elua/elua_lib.c | 4 ++-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/lib/elua/Elua.h b/src/lib/elua/Elua.h index 623179fecb..3b087790b8 100644 --- a/src/lib/elua/Elua.h +++ b/src/lib/elua/Elua.h @@ -335,7 +335,10 @@ EAPI Eina_Bool elua_state_setup(Elua_State *es); * @brief Loads a file using Elua's own mmap-based IO. * * This function behaves identically to luaL_loadfile when it comes to - * semantics. The loaded file remains on the Lua stack. + * semantics. The loaded file remains on the Lua stack. If the input + * state is NULL, the return value is -1 and nothing is left on the stack. + * On any different error, the error object is left on the stack and this + * returns a value larger than zero (LUA_ERR*). On success, zero is returned. * * @param[in] es The Elua state. * @param[in] fname The file name. @@ -390,15 +393,18 @@ EAPI Eina_Bool elua_util_string_run(Elua_State *es, const char *chunk, * @brief Loads an application. * * This loads an app, respecting the app path set on state initialization. - * Leaves the Lua stack clean. Actually runs the app. + * Actually runs the app. If the input state is NULL, the return value is -1 + * nd nothing is left on the stack. On any different error, the error object + * is left on the stack and this returns 1. On success, zero is returned + * (and the return value from the app is left on the stack). * * @param[in] es The Elua state. * @param[in] appname The application name. - * @return EINA_TRUE on success, EINA_FALSE on failure. + * @return 0 for no errors, 1 on errors, -1 on null input. * * @ingroup Elua */ -EAPI Eina_Bool elua_util_app_load(Elua_State *es, const char *appname); +EAPI int elua_util_app_load(Elua_State *es, const char *appname); /** * @brief Runs a script. diff --git a/src/lib/elua/elua.c b/src/lib/elua/elua.c index 6cb2e13d71..76cafb1ea6 100644 --- a/src/lib/elua/elua.c +++ b/src/lib/elua/elua.c @@ -502,21 +502,21 @@ elua_util_string_run(Elua_State *es, const char *chunk, const char *chname) || _elua_docall(es, 0, 0)); } -EAPI Eina_Bool +EAPI int elua_util_app_load(Elua_State *es, const char *appname) { - EINA_SAFETY_ON_NULL_RETURN_VAL(es, EINA_FALSE); - EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, EINA_FALSE); - EINA_SAFETY_ON_FALSE_RETURN_VAL(elua_state_appload_ref_push(es), EINA_FALSE); + EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1); + EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1); + EINA_SAFETY_ON_FALSE_RETURN_VAL(elua_state_appload_ref_push(es), -1); lua_pushstring(es->luastate, appname); lua_call(es->luastate, 1, 2); if (lua_isnil(es->luastate, -2)) { lua_remove(es->luastate, -2); - return EINA_FALSE; + return 1; } lua_pop(es->luastate, 1); - return EINA_TRUE; + return 0; } EAPI Eina_Bool @@ -541,7 +541,7 @@ elua_util_script_run(Elua_State *es, int argc, char **argv, int n, int *quit) status = elua_io_loadfile(es, fname); } else - status = !elua_util_app_load(es, fname); + status = elua_util_app_load(es, fname); } else status = elua_io_loadfile(es, fname); diff --git a/src/tests/elua/elua_lib.c b/src/tests/elua/elua_lib.c index 7ee3f2b0a1..82857270db 100644 --- a/src/tests/elua/elua_lib.c +++ b/src/tests/elua/elua_lib.c @@ -69,10 +69,10 @@ START_TEST(elua_api) fail_if(!elua_util_require(st, "util")); fail_if(!elua_util_string_run(st, "return 1337", "foo")); fail_if(elua_util_string_run(st, "foo bar", "foo")); /* invalid code */ - fail_if(!elua_util_app_load(st, "lualian")); + fail_if(elua_util_app_load(st, "lualian")); fail_if(lua_type(lst, -1) != LUA_TFUNCTION); lua_pop(lst, 1); - fail_if(elua_util_app_load(st, "non_existent_app")); + fail_if(!elua_util_app_load(st, "non_existent_app")); fail_if(lua_type(lst, -1) != LUA_TSTRING); lua_pop(lst, 1); fail_if(elua_io_loadfile(st, ELUA_CORE_DIR "/util.lua"));