summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2015-04-24 16:01:24 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2015-05-06 15:05:23 +0100
commite73f7f7a40ba3832d743ae4b893940440a38e3d4 (patch)
tree4e115a67920858cbd16f01dcaa37eec9a3153ccb /src
parente9aadea402f2f533e6d9137171f5bff4eeb4bafc (diff)
elua lib: use Eina_Bool as return val in some utils
Diffstat (limited to 'src')
-rw-r--r--src/bin/elua/main.c2
-rw-r--r--src/lib/elua/Elua.h31
-rw-r--r--src/lib/elua/elua.c34
-rw-r--r--src/tests/elua/elua_lib.c12
4 files changed, 38 insertions, 41 deletions
diff --git a/src/bin/elua/main.c b/src/bin/elua/main.c
index 6b55120067..ed1b4074a4 100644
--- a/src/bin/elua/main.c
+++ b/src/bin/elua/main.c
@@ -107,7 +107,7 @@ elua_main(lua_State *L)
107 if (optind < argc) 107 if (optind < argc)
108 { 108 {
109 int quit = 0; 109 int quit = 0;
110 if (elua_util_script_run(es, argc, argv, optind, &quit)) 110 if (!elua_util_script_run(es, argc, argv, optind, &quit))
111 { 111 {
112 m->status = 1; 112 m->status = 1;
113 return 0; 113 return 0;
diff --git a/src/lib/elua/Elua.h b/src/lib/elua/Elua.h
index 93814a359d..623179fecb 100644
--- a/src/lib/elua/Elua.h
+++ b/src/lib/elua/Elua.h
@@ -348,46 +348,43 @@ EAPI int elua_io_loadfile(const Elua_State *es, const char *fname);
348/** 348/**
349 * @brief Requires a module. 349 * @brief Requires a module.
350 * 350 *
351 * Requires a Lua module. Leaves the Lua stack clean. Returns 0 on success 351 * Requires a Lua module. Leaves the Lua stack clean.
352 * or non-zero value on failure (see lua_pcall).
353 * 352 *
354 * @param[in] es The Elua state. 353 * @param[in] es The Elua state.
355 * @param[in] libname The library name. 354 * @param[in] libname The library name.
356 * @return 0 for no errors, a non-zero value for errors (-1 for NULL es or 355 * @return EINA_TRUE on success, EINA_FALSE on failure.
357 * NULL require).
358 * 356 *
359 * @ingroup Elua 357 * @ingroup Elua
360 */ 358 */
361EAPI int elua_util_require(Elua_State *es, const char *libname); 359EAPI Eina_Bool elua_util_require(Elua_State *es, const char *libname);
362 360
363/** 361/**
364 * @brief Runs a file. 362 * @brief Runs a file.
365 * 363 *
366 * Runs a file. Uses the Elua mmapped file IO to load the file. Returns zero 364 * Runs a file. Uses the Elua mmapped file IO to load the file.
367 * on success or non-zero value on failure.
368 * 365 *
369 * @param[in] es The Elua state. 366 * @param[in] es The Elua state.
370 * @param[in] fname The file name. 367 * @param[in] fname The file name.
371 * @return 0 for no errors, a non-zero value for errors (-1 for NULL es). 368 * @return EINA_TRUE on success, EINA_FALSE on failure.
372 * 369 *
373 * @ingroup Elua 370 * @ingroup Elua
374 */ 371 */
375EAPI int elua_util_file_run(Elua_State *es, const char *fname); 372EAPI Eina_Bool elua_util_file_run(Elua_State *es, const char *fname);
376 373
377/** 374/**
378 * @brief Runs a string. 375 * @brief Runs a string.
379 * 376 *
380 * Runs a string. Returns zero on success or non-zero value on failure. 377 * Runs a string.
381 * 378 *
382 * @param[in] es The Elua state. 379 * @param[in] es The Elua state.
383 * @param[in] chunk The string to run. 380 * @param[in] chunk The string to run.
384 * @param[in] chname The chunk name to use for traceback/debug. 381 * @param[in] chname The chunk name to use for traceback/debug.
385 * @return 0 for no errors, a non-zero value for errors (-1 for NULL es). 382 * @return EINA_TRUE on success, EINA_FALSE on failure.
386 * 383 *
387 * @ingroup Elua 384 * @ingroup Elua
388 */ 385 */
389EAPI int elua_util_string_run(Elua_State *es, const char *chunk, 386EAPI Eina_Bool elua_util_string_run(Elua_State *es, const char *chunk,
390 const char *chname); 387 const char *chname);
391 388
392/** 389/**
393 * @brief Loads an application. 390 * @brief Loads an application.
@@ -424,14 +421,14 @@ EAPI Eina_Bool elua_util_app_load(Elua_State *es, const char *appname);
424 * @param[in] es The Elua state. 421 * @param[in] es The Elua state.
425 * @param[in] argc The argument count. 422 * @param[in] argc The argument count.
426 * @param[in] argv The arguments. 423 * @param[in] argv The arguments.
427 * @param[in] n The index of the first positional argument. 424 * @param[in] n The index of the first positional argt.
428 * @param[out] quit Whether to quit or run a main loop. 425 * @param[out] quit Whether to quit or run a main loop.
429 * @return 0 on success, non-zero value on failure (-1 for NULL inputs). 426 * @return EINA_TRUE on success, EINA_FALSE on failure.
430 * 427 *
431 * @ingroup Elua 428 * @ingroup Elua
432 */ 429 */
433EAPI int elua_util_script_run(Elua_State *es, int argc, char **argv, int n, 430EAPI Eina_Bool elua_util_script_run(Elua_State *es, int argc, char **argv,
434 int *quit); 431 int n, int *quit);
435 432
436/** 433/**
437 * @brief Reports an error using Eina logging. 434 * @brief Reports an error using Eina logging.
diff --git a/src/lib/elua/elua.c b/src/lib/elua/elua.c
index 9ad15d17f0..6cb2e13d71 100644
--- a/src/lib/elua/elua.c
+++ b/src/lib/elua/elua.c
@@ -468,11 +468,11 @@ _elua_getargs(Elua_State *es, int argc, char **argv, int n)
468 return narg; 468 return narg;
469} 469}
470 470
471EAPI int 471EAPI Eina_Bool
472elua_util_require(Elua_State *es, const char *libname) 472elua_util_require(Elua_State *es, const char *libname)
473{ 473{
474 EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1); 474 EINA_SAFETY_ON_NULL_RETURN_VAL(es, EINA_FALSE);
475 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1); 475 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, EINA_FALSE);
476 if (!elua_state_require_ref_push(es)) 476 if (!elua_state_require_ref_push(es))
477 { 477 {
478 /* store stuff until things are correctly set up */ 478 /* store stuff until things are correctly set up */
@@ -480,26 +480,26 @@ elua_util_require(Elua_State *es, const char *libname)
480 return 0; 480 return 0;
481 } 481 }
482 lua_pushstring(es->luastate, libname); 482 lua_pushstring(es->luastate, libname);
483 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));
484} 484}
485 485
486EAPI int 486EAPI Eina_Bool
487elua_util_file_run(Elua_State *es, const char *fname) 487elua_util_file_run(Elua_State *es, const char *fname)
488{ 488{
489 EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1); 489 EINA_SAFETY_ON_NULL_RETURN_VAL(es, EINA_FALSE);
490 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1); 490 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, EINA_FALSE);
491 return elua_util_error_report(es, elua_io_loadfile(es, fname) 491 return !elua_util_error_report(es, elua_io_loadfile(es, fname)
492 || _elua_docall(es, 0, 1)); 492 || _elua_docall(es, 0, 1));
493} 493}
494 494
495EAPI int 495EAPI Eina_Bool
496elua_util_string_run(Elua_State *es, const char *chunk, const char *chname) 496elua_util_string_run(Elua_State *es, const char *chunk, const char *chname)
497{ 497{
498 EINA_SAFETY_ON_NULL_RETURN_VAL(es, -1); 498 EINA_SAFETY_ON_NULL_RETURN_VAL(es, EINA_FALSE);
499 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, -1); 499 EINA_SAFETY_ON_NULL_RETURN_VAL(es->luastate, EINA_FALSE);
500 return elua_util_error_report(es, luaL_loadbuffer(es->luastate, chunk, 500 return !elua_util_error_report(es, luaL_loadbuffer(es->luastate, chunk,
501 strlen(chunk), chname) 501 strlen(chunk), chname)
502 || _elua_docall(es, 0, 0)); 502 || _elua_docall(es, 0, 0));
503} 503}
504 504
505EAPI Eina_Bool 505EAPI Eina_Bool
@@ -519,7 +519,7 @@ elua_util_app_load(Elua_State *es, const char *appname)
519 return EINA_TRUE; 519 return EINA_TRUE;
520} 520}
521 521
522EAPI int 522EAPI Eina_Bool
523elua_util_script_run(Elua_State *es, int argc, char **argv, int n, int *quit) 523elua_util_script_run(Elua_State *es, int argc, char **argv, int n, int *quit)
524{ 524{
525 int status, narg; 525 int status, narg;
@@ -555,7 +555,7 @@ elua_util_script_run(Elua_State *es, int argc, char **argv, int n, int *quit)
555 *quit = lua_toboolean(es->luastate, -1); 555 *quit = lua_toboolean(es->luastate, -1);
556 lua_pop(es->luastate, 1); 556 lua_pop(es->luastate, 1);
557 } 557 }
558 return elua_util_error_report(es, status); 558 return !elua_util_error_report(es, status);
559} 559}
560 560
561static void 561static void
diff --git a/src/tests/elua/elua_lib.c b/src/tests/elua/elua_lib.c
index 445a89d9d3..7ee3f2b0a1 100644
--- a/src/tests/elua/elua_lib.c
+++ b/src/tests/elua/elua_lib.c
@@ -66,9 +66,9 @@ START_TEST(elua_api)
66 fail_if(lua_type(lst, -1) != LUA_TFUNCTION); 66 fail_if(lua_type(lst, -1) != LUA_TFUNCTION);
67 lua_pop(lst, 1); 67 lua_pop(lst, 1);
68 68
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);
@@ -88,7 +88,7 @@ START_TEST(elua_api)
88 fail_if(!f); 88 fail_if(!f);
89 fprintf(f, "return 5\n"); 89 fprintf(f, "return 5\n");
90 fclose(f); 90 fclose(f);
91 fail_if(elua_util_file_run(st, buf)); 91 fail_if(!elua_util_file_run(st, buf));
92 fail_if(lua_tointeger(lst, -1) != 5); 92 fail_if(lua_tointeger(lst, -1) != 5);
93 lua_pop(lst, 1); 93 lua_pop(lst, 1);
94 fail_if(remove(buf)); 94 fail_if(remove(buf));
@@ -99,7 +99,7 @@ START_TEST(elua_api)
99 fail_if(!elua_util_error_report(st, 5)); 99 fail_if(!elua_util_error_report(st, 5));
100 fail_if(lua_gettop(lst) > 0); 100 fail_if(lua_gettop(lst) > 0);
101 101
102 fail_if(elua_util_script_run(st, 2, cargv, 1, &quit)); 102 fail_if(!elua_util_script_run(st, 2, cargv, 1, &quit));
103 fail_if(quit != 1); 103 fail_if(quit != 1);
104 104
105 f = fopen(buf, "w"); 105 f = fopen(buf, "w");
@@ -107,7 +107,7 @@ START_TEST(elua_api)
107 fprintf(f, "return false"); 107 fprintf(f, "return false");
108 fclose(f); 108 fclose(f);
109 cargv[1] = buf; 109 cargv[1] = buf;
110 fail_if(elua_util_script_run(st, 2, cargv, 1, &quit)); 110 fail_if(!elua_util_script_run(st, 2, cargv, 1, &quit));
111 fail_if(quit != 0); 111 fail_if(quit != 0);
112 fail_if(remove(buf)); 112 fail_if(remove(buf));
113 113