summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anylike.org>2009-12-25 15:36:39 +0000
committerChristian Pointner <equinox@anylike.org>2009-12-25 15:36:39 +0000
commitd148e7d1e14949f2565a4765eba1113fae449ebb (patch)
tree3afc10c99c77a4ff342cb20d9b4866cb85518e84
parentluaL_error instead of lua_error (diff)
moved from useless checklstring to checkstring
getting error message from stack at loadfile and call
-rw-r--r--src/anylike.c19
-rw-r--r--src/l_log.c6
-rw-r--r--src/main_loop.lua2
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";