From d148e7d1e14949f2565a4765eba1113fae449ebb Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 25 Dec 2009 15:36:39 +0000 Subject: moved from useless checklstring to checkstring getting error message from stack at loadfile and call --- src/anylike.c | 19 ++++++++++++------- src/l_log.c | 6 +++--- src/main_loop.lua | 2 ++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/anylike.c b/src/anylike.c index ef0669b..c6e39d7 100644 --- a/src/anylike.c +++ b/src/anylike.c @@ -107,11 +107,12 @@ int main_loop(options_t* opt) int ret = luaL_loadfile(L, LUA_MAIN_LOOP); if(ret) { + const char* err_str = luaL_checkstring(L, -1); switch(ret) { - case LUA_ERRSYNTAX: log_printf(ERROR, "luaL_loadfile(%s): syntax error during pre-compilation", LUA_MAIN_LOOP); break; - case LUA_ERRMEM: log_printf(ERROR, "luaL_loadfile(%s): memory allocation error", LUA_MAIN_LOOP); break; - case LUA_ERRFILE: log_printf(ERROR, "luaL_loadfile(%s): file access error", LUA_MAIN_LOOP); break; - default: log_printf(ERROR, "luaL_loadfile(%s): unknown error", LUA_MAIN_LOOP); break; + case LUA_ERRSYNTAX: log_printf(ERROR, "luaL_loadfile(%s) syntax error: %s", LUA_MAIN_LOOP, err_str); break; + case LUA_ERRMEM: log_printf(ERROR, "luaL_loadfile(%s) malloc error: %s", LUA_MAIN_LOOP, err_str); break; + case LUA_ERRFILE: log_printf(ERROR, "luaL_loadfile(%s) file access error: %s", LUA_MAIN_LOOP, err_str); break; + default: log_printf(ERROR, "luaL_loadfile(%s) unknown error: %s", LUA_MAIN_LOOP, err_str); break; } lua_close(L); return -1; @@ -119,15 +120,19 @@ int main_loop(options_t* opt) ret = lua_pcall(L, 0, LUA_MULTRET, 0); if(ret) { + const char* err_str = luaL_checkstring(L, -1); switch(ret) { - case LUA_ERRRUN: log_printf(ERROR, "lua_pcall(): runtime error"); break; - case LUA_ERRMEM: log_printf(ERROR, "lua_pcall(): memory allocation error"); break; - case LUA_ERRERR: log_printf(ERROR, "lua_pcall(): error while running the error handler function"); break; + case LUA_ERRRUN: log_printf(ERROR, "lua_pcall() runtime error: %s", err_str); break; + case LUA_ERRMEM: log_printf(ERROR, "lua_pcall() malloc error: %s", err_str); break; + case LUA_ERRERR: log_printf(ERROR, "lua_pcall() error at error handler function: %s", err_str); break; } lua_close(L); return -1; } + + + lua_close(L); return 0; } diff --git a/src/l_log.c b/src/l_log.c index ac39487..219d843 100644 --- a/src/l_log.c +++ b/src/l_log.c @@ -45,7 +45,7 @@ static int l_log_close(lua_State *L) static int l_log_add_target(lua_State *L) { - int ret = log_add_target(luaL_checklstring(L,1,NULL)); + int ret = log_add_target(luaL_checkstring(L,1)); if(ret) { lua_pushboolean(L, 0); switch(ret) { @@ -64,7 +64,7 @@ static int l_log_add_target(lua_State *L) /* void log_printf(log_prio_t prio, const char* fmt, ...); */ static int l_log_print(lua_State *L) { - const char* prio_str = luaL_checklstring(L,1,NULL); + const char* prio_str = luaL_checkstring(L,1); log_prio_t prio; if(prio_str) { if(!strncmp("ERROR", prio_str, 6)) @@ -83,7 +83,7 @@ static int l_log_print(lua_State *L) else return luaL_error(L, "invalid log priority"); - log_printf(prio, "%s", luaL_checklstring(L, 2, NULL)); + log_printf(prio, "%s", luaL_checkstring(L, 2)); return 0; } diff --git a/src/main_loop.lua b/src/main_loop.lua index 3b025d6..295caa5 100644 --- a/src/main_loop.lua +++ b/src/main_loop.lua @@ -30,3 +30,5 @@ log.print("DEBUG", "yet another message"); log.print("ERROR", "this is an error"); log.print("NOTICE", crypt.test()); + +return "hello", "world"; -- cgit v1.2.3