diff options
author | Daniel Kolesa <d.kolesa@osg.samsung.com> | 2015-04-27 11:30:33 +0100 |
---|---|---|
committer | Daniel Kolesa <d.kolesa@osg.samsung.com> | 2015-05-06 15:05:23 +0100 |
commit | db66fe62551c170da81b071c0055b3b3dd4159da (patch) | |
tree | aa3b808c35916df39cd8643c24fa80cec809425d | |
parent | e73f7f7a40ba3832d743ae4b893940440a38e3d4 (diff) |
elua lib: fix elua_util_app_load + docs
-rw-r--r-- | src/lib/elua/Elua.h | 14 | ||||
-rw-r--r-- | src/lib/elua/elua.c | 14 | ||||
-rw-r--r-- | 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); | |||
335 | * @brief Loads a file using Elua's own mmap-based IO. | 335 | * @brief Loads a file using Elua's own mmap-based IO. |
336 | * | 336 | * |
337 | * This function behaves identically to luaL_loadfile when it comes to | 337 | * This function behaves identically to luaL_loadfile when it comes to |
338 | * semantics. The loaded file remains on the Lua stack. | 338 | * semantics. The loaded file remains on the Lua stack. If the input |
339 | * state is NULL, the return value is -1 and nothing is left on the stack. | ||
340 | * On any different error, the error object is left on the stack and this | ||
341 | * returns a value larger than zero (LUA_ERR*). On success, zero is returned. | ||
339 | * | 342 | * |
340 | * @param[in] es The Elua state. | 343 | * @param[in] es The Elua state. |
341 | * @param[in] fname The file name. | 344 | * @param[in] fname The file name. |
@@ -390,15 +393,18 @@ EAPI Eina_Bool elua_util_string_run(Elua_State *es, const char *chunk, | |||
390 | * @brief Loads an application. | 393 | * @brief Loads an application. |
391 | * | 394 | * |
392 | * This loads an app, respecting the app path set on state initialization. | 395 | * This loads an app, respecting the app path set on state initialization. |
393 | * Leaves the Lua stack clean. Actually runs the app. | 396 | * Actually runs the app. If the input state is NULL, the return value is -1 |
397 | * nd nothing is left on the stack. On any different error, the error object | ||
398 | * is left on the stack and this returns 1. On success, zero is returned | ||
399 | * (and the return value from the app is left on the stack). | ||
394 | * | 400 | * |
395 | * @param[in] es The Elua state. | 401 | * @param[in] es The Elua state. |
396 | * @param[in] appname The application name. | 402 | * @param[in] appname The application name. |
397 | * @return EINA_TRUE on success, EINA_FALSE on failure. | 403 | * @return 0 for no errors, 1 on errors, -1 on null input. |
398 | * | 404 | * |
399 | * @ingroup Elua | 405 | * @ingroup Elua |
400 | */ | 406 | */ |
401 | EAPI Eina_Bool elua_util_app_load(Elua_State *es, const char *appname); | 407 | EAPI int elua_util_app_load(Elua_State *es, const char *appname); |
402 | 408 | ||
403 | /** | 409 | /** |
404 | * @brief Runs a script. | 410 | * @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) | |||
502 | || _elua_docall(es, 0, 0)); | 502 | || _elua_docall(es, 0, 0)); |
503 | } | 503 | } |
504 | 504 | ||
505 | EAPI Eina_Bool | 505 | EAPI int |
506 | elua_util_app_load(Elua_State *es, const char *appname) | 506 | elua_util_app_load(Elua_State *es, const char *appname) |
507 | { | 507 | { |
508 | EINA_SAFETY_ON_NULL_RETURN_VAL(es, EINA_FALSE); | 508 | EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1); |
509 | EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, EINA_FALSE); | 509 | EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1); |
510 | EINA_SAFETY_ON_FALSE_RETURN_VAL(elua_state_appload_ref_push(es), EINA_FALSE); | 510 | EINA_SAFETY_ON_FALSE_RETURN_VAL(elua_state_appload_ref_push(es), -1); |
511 | lua_pushstring(es->luastate, appname); | 511 | lua_pushstring(es->luastate, appname); |
512 | lua_call(es->luastate, 1, 2); | 512 | lua_call(es->luastate, 1, 2); |
513 | if (lua_isnil(es->luastate, -2)) | 513 | if (lua_isnil(es->luastate, -2)) |
514 | { | 514 | { |
515 | lua_remove(es->luastate, -2); | 515 | lua_remove(es->luastate, -2); |
516 | return EINA_FALSE; | 516 | return 1; |
517 | } | 517 | } |
518 | lua_pop(es->luastate, 1); | 518 | lua_pop(es->luastate, 1); |
519 | return EINA_TRUE; | 519 | return 0; |
520 | } | 520 | } |
521 | 521 | ||
522 | EAPI Eina_Bool | 522 | EAPI Eina_Bool |
@@ -541,7 +541,7 @@ elua_util_script_run(Elua_State *es, int argc, char **argv, int n, int *quit) | |||
541 | status = elua_io_loadfile(es, fname); | 541 | status = elua_io_loadfile(es, fname); |
542 | } | 542 | } |
543 | else | 543 | else |
544 | status = !elua_util_app_load(es, fname); | 544 | status = elua_util_app_load(es, fname); |
545 | } | 545 | } |
546 | else | 546 | else |
547 | status = elua_io_loadfile(es, fname); | 547 | 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) | |||
69 | fail_if(!elua_util_require(st, "util")); | 69 | fail_if(!elua_util_require(st, "util")); |
70 | fail_if(!elua_util_string_run(st, "return 1337", "foo")); | 70 | fail_if(!elua_util_string_run(st, "return 1337", "foo")); |
71 | fail_if(elua_util_string_run(st, "foo bar", "foo")); /* invalid code */ | 71 | fail_if(elua_util_string_run(st, "foo bar", "foo")); /* invalid code */ |
72 | fail_if(!elua_util_app_load(st, "lualian")); | 72 | fail_if(elua_util_app_load(st, "lualian")); |
73 | fail_if(lua_type(lst, -1) != LUA_TFUNCTION); | 73 | fail_if(lua_type(lst, -1) != LUA_TFUNCTION); |
74 | lua_pop(lst, 1); | 74 | lua_pop(lst, 1); |
75 | fail_if(elua_util_app_load(st, "non_existent_app")); | 75 | fail_if(!elua_util_app_load(st, "non_existent_app")); |
76 | fail_if(lua_type(lst, -1) != LUA_TSTRING); | 76 | fail_if(lua_type(lst, -1) != LUA_TSTRING); |
77 | lua_pop(lst, 1); | 77 | lua_pop(lst, 1); |
78 | fail_if(elua_io_loadfile(st, ELUA_CORE_DIR "/util.lua")); | 78 | fail_if(elua_io_loadfile(st, ELUA_CORE_DIR "/util.lua")); |