diff options
author | Daniel Kolesa <d.kolesa@samsung.com> | 2014-12-17 14:43:50 +0000 |
---|---|---|
committer | Daniel Kolesa <d.kolesa@samsung.com> | 2014-12-17 14:44:12 +0000 |
commit | 208ad62d3cb184688f10198ce42c35cbd3489d90 (patch) | |
tree | e35d1389a294d3b3710f0a78606da3b561e98d31 /src | |
parent | c8a993d1f77087750518a2684b151870f5e76651 (diff) |
elua: error reporting in the library
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/elua/main.c | 33 | ||||
-rw-r--r-- | src/lib/elua/Elua.h | 2 | ||||
-rw-r--r-- | src/lib/elua/elua.c | 18 |
3 files changed, 28 insertions, 25 deletions
diff --git a/src/bin/elua/main.c b/src/bin/elua/main.c index 94beacf241..3716a51984 100644 --- a/src/bin/elua/main.c +++ b/src/bin/elua/main.c | |||
@@ -48,24 +48,6 @@ static int _el_log_domain = -1; | |||
48 | #define ERR(...) EINA_LOG_DOM_ERR(_el_log_domain, __VA_ARGS__) | 48 | #define ERR(...) EINA_LOG_DOM_ERR(_el_log_domain, __VA_ARGS__) |
49 | #define CRT(...) EINA_LOG_DOM_CRITICAL(_el_log_domain, __VA_ARGS__) | 49 | #define CRT(...) EINA_LOG_DOM_CRITICAL(_el_log_domain, __VA_ARGS__) |
50 | 50 | ||
51 | static void | ||
52 | elua_errmsg(const char *pname, const char *msg) | ||
53 | { | ||
54 | ERR("%s%s%s", pname ? pname : "", pname ? ": " : "", msg); | ||
55 | } | ||
56 | |||
57 | static int | ||
58 | elua_report(lua_State *L, int status) | ||
59 | { | ||
60 | if (status && !lua_isnil(L, -1)) | ||
61 | { | ||
62 | const char *msg = lua_tostring(L, -1); | ||
63 | elua_errmsg(elua_progname, msg ? msg : "(non-string error)"); | ||
64 | lua_pop(L, 1); | ||
65 | } | ||
66 | return status; | ||
67 | } | ||
68 | |||
69 | static int | 51 | static int |
70 | elua_traceback(lua_State *L) | 52 | elua_traceback(lua_State *L) |
71 | { | 53 | { |
@@ -210,20 +192,21 @@ elua_dolib(lua_State *L, const char *libname) | |||
210 | { | 192 | { |
211 | lua_rawgeti(L, LUA_REGISTRYINDEX, elua_require_ref); | 193 | lua_rawgeti(L, LUA_REGISTRYINDEX, elua_require_ref); |
212 | lua_pushstring(L, libname); | 194 | lua_pushstring(L, libname); |
213 | return elua_report(L, lua_pcall(L, 1, 0, 0)); | 195 | return elua_report_error(L, elua_progname, lua_pcall(L, 1, 0, 0)); |
214 | } | 196 | } |
215 | 197 | ||
216 | static int | 198 | static int |
217 | elua_dofile(lua_State *L, const char *fname) | 199 | elua_dofile(lua_State *L, const char *fname) |
218 | { | 200 | { |
219 | return elua_report(L, elua_io_loadfile(L, fname) || elua_docall(L, 0, 1)); | 201 | return elua_report_error(L, elua_progname, elua_io_loadfile(L, fname) |
202 | || elua_docall(L, 0, 1)); | ||
220 | } | 203 | } |
221 | 204 | ||
222 | static int | 205 | static int |
223 | elua_dostr(lua_State *L, const char *chunk, const char *chname) | 206 | elua_dostr(lua_State *L, const char *chunk, const char *chname) |
224 | { | 207 | { |
225 | return elua_report(L, luaL_loadbuffer(L, chunk, strlen(chunk), chname) | 208 | return elua_report_error(L, elua_progname, luaL_loadbuffer(L, chunk, |
226 | || elua_docall(L, 0, 0)); | 209 | strlen(chunk), chname) || elua_docall(L, 0, 0)); |
227 | } | 210 | } |
228 | 211 | ||
229 | static Eina_Bool | 212 | static Eina_Bool |
@@ -282,7 +265,7 @@ elua_doscript(lua_State *L, int argc, char **argv, int n, int *quit) | |||
282 | *quit = lua_toboolean(L, -1); | 265 | *quit = lua_toboolean(L, -1); |
283 | lua_pop(L, 1); | 266 | lua_pop(L, 1); |
284 | } | 267 | } |
285 | return elua_report(L, status); | 268 | return elua_report_error(L, elua_progname, status); |
286 | } | 269 | } |
287 | 270 | ||
288 | void | 271 | void |
@@ -465,7 +448,7 @@ elua_main(lua_State *L) | |||
465 | } | 448 | } |
466 | } | 449 | } |
467 | snprintf(modfile, sizeof(modfile), "%s/module.lua", coref); | 450 | snprintf(modfile, sizeof(modfile), "%s/module.lua", coref); |
468 | if (elua_report(L, elua_io_loadfile(L, modfile))) | 451 | if (elua_report_error(L, elua_progname, elua_io_loadfile(L, modfile))) |
469 | { | 452 | { |
470 | m->status = 1; | 453 | m->status = 1; |
471 | return 0; | 454 | return 0; |
@@ -481,7 +464,7 @@ elua_main(lua_State *L) | |||
481 | lua_call(L, 2, 0); | 464 | lua_call(L, 2, 0); |
482 | 465 | ||
483 | snprintf(modfile, sizeof(modfile), "%s/gettext.lua", coref); | 466 | snprintf(modfile, sizeof(modfile), "%s/gettext.lua", coref); |
484 | if (elua_report(L, elua_io_loadfile(L, modfile))) | 467 | if (elua_report_error(L, elua_progname, elua_io_loadfile(L, modfile))) |
485 | { | 468 | { |
486 | m->status = 1; | 469 | m->status = 1; |
487 | return 0; | 470 | return 0; |
diff --git a/src/lib/elua/Elua.h b/src/lib/elua/Elua.h index 80a8a894a4..8df01de3cc 100644 --- a/src/lib/elua/Elua.h +++ b/src/lib/elua/Elua.h | |||
@@ -61,6 +61,8 @@ extern "C" { | |||
61 | EAPI int elua_init(void); | 61 | EAPI int elua_init(void); |
62 | EAPI int elua_shutdown(void); | 62 | EAPI int elua_shutdown(void); |
63 | 63 | ||
64 | EAPI int elua_report_error(lua_State *L, const char *pname, int status); | ||
65 | |||
64 | EAPI void elua_state_setup_i18n(lua_State *L); | 66 | EAPI void elua_state_setup_i18n(lua_State *L); |
65 | 67 | ||
66 | EAPI int elua_io_popen(lua_State *L); | 68 | EAPI int elua_io_popen(lua_State *L); |
diff --git a/src/lib/elua/elua.c b/src/lib/elua/elua.c index f4411ae1e9..2f88e7be02 100644 --- a/src/lib/elua/elua.c +++ b/src/lib/elua/elua.c | |||
@@ -62,6 +62,24 @@ elua_shutdown(void) | |||
62 | return _elua_init_counter; | 62 | return _elua_init_counter; |
63 | } | 63 | } |
64 | 64 | ||
65 | static void | ||
66 | _elua_errmsg(const char *pname, const char *msg) | ||
67 | { | ||
68 | ERR("%s%s%s", pname ? pname : "", pname ? ": " : "", msg); | ||
69 | } | ||
70 | |||
71 | EAPI int | ||
72 | elua_report_error(lua_State *L, const char *pname, int status) | ||
73 | { | ||
74 | if (status && !lua_isnil(L, -1)) | ||
75 | { | ||
76 | const char *msg = lua_tostring(L, -1); | ||
77 | _elua_errmsg(pname, msg ? msg : "(non-string error)"); | ||
78 | lua_pop(L, 1); | ||
79 | } | ||
80 | return status; | ||
81 | } | ||
82 | |||
65 | static int | 83 | static int |
66 | _elua_gettext_bind_textdomain(lua_State *L) | 84 | _elua_gettext_bind_textdomain(lua_State *L) |
67 | { | 85 | { |