diff options
Diffstat (limited to 'src/l_log.c')
-rw-r--r-- | src/l_log.c | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/l_log.c b/src/l_log.c index 7cac3b5..890bddb 100644 --- a/src/l_log.c +++ b/src/l_log.c @@ -76,25 +76,7 @@ static int l_log_printf(lua_State *L) lua_call(L, numargs - 1, 1); } - const char* prio_str = luaL_checkstring(L,1); - log_prio_t prio; - if(prio_str) { - if(!strncmp("ERROR", prio_str, 6)) - prio = ERROR; - else if(!strncmp("WARNING", prio_str, 6)) - prio = WARNING; - else if(!strncmp("NOTICE", prio_str, 6)) - prio = NOTICE; - else if(!strncmp("INFO", prio_str, 6)) - prio = INFO; - else if(!strncmp("DEBUG", prio_str, 6)) - prio = DEBUG; - else - return luaL_error(L, "log.printf invalid log priority"); - } - else - return luaL_error(L, "log.printf invalid log priority"); - + log_prio_t prio = luaL_checkint(L,1); log_printf(prio, "%s", luaL_checkstring(L, 2)); return 0; } @@ -111,5 +93,20 @@ static const struct luaL_reg log_funcs [] = { LUALIB_API int luaopen_log(lua_State *L) { luaL_register(L, LUA_LOGLIBNAME, log_funcs); + lua_pushliteral(L, "ERROR"); + lua_pushinteger(L, ERROR); + lua_settable(L, -3); + lua_pushliteral(L, "WARNING"); + lua_pushinteger(L, WARNING); + lua_settable(L, -3); + lua_pushliteral(L, "NOTICE"); + lua_pushinteger(L, NOTICE); + lua_settable(L, -3); + lua_pushliteral(L, "INFO"); + lua_pushinteger(L, INFO); + lua_settable(L, -3); + lua_pushliteral(L, "DEBUG"); + lua_pushinteger(L, DEBUG); + lua_settable(L, -3); return 1; } |