diff options
| author | Federico Angelilli <code@fedang.net> | 2025-08-23 00:01:31 +0200 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2025-08-23 00:01:31 +0200 |
| commit | a262dc8acd581052ee6b5d5430af69148540a843 (patch) | |
| tree | c6eafa7d46f717fdf22eb5565d62e82d80de5fe1 /src/lua/log.c | |
| parent | efdf4a4883937c8a2fad278fbd4ffc207ef981dc (diff) | |
Move to luajit and fix logsrefactor
Diffstat (limited to 'src/lua/log.c')
| -rw-r--r-- | src/lua/log.c | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/src/lua/log.c b/src/lua/log.c index 2b6d068..ee85369 100644 --- a/src/lua/log.c +++ b/src/lua/log.c @@ -18,12 +18,7 @@ static void lua_log_debuginfo(lua_State *state, const char **module, const char lua_pushnumber(state, 2); // S: source, l: currentline, n: name - const char *query = -#ifdef _RELEASE - "Sl"; -#else - "Sln"; -#endif + const char *query = "Sln"; lua_pushstring(state, query); if (lua_pcall(state, 2, 1, 0) == LUA_OK) { @@ -33,21 +28,21 @@ static void lua_log_debuginfo(lua_State *state, const char **module, const char lua_getfield(state, -2, "currentline"); int line = lua_tointeger(state, -1); -#ifndef _RELEASE lua_getfield(state, -3, "name"); const char *name = lua_tostring(state, -1); - if (name) - *func = name; -#endif if (!strncmp(shortsrc, "[string ", 8)) { int length = strlen(shortsrc); snprintf(buffer, size, "%.*s", length - 9, shortsrc + 8); + + *func = buffer; + *module = "lua"; } else { snprintf(buffer, size, "%s:%d", shortsrc, line); - } - *module = buffer; + *func = name ? name : "?"; + *module = buffer; + } } else { log_trace("Failed to retrieve Lua debug information"); } @@ -70,11 +65,11 @@ static int lua_log_wrapper(lua_State *state, int skip_args, any_log_level_t leve lua_call(state, n_args, 1); const char *message = lua_tostring(state, -1); - const char *module = "?", *func = ""; + const char *module, *func; char buffer[4096]; lua_log_debuginfo(state, &module, &func, buffer, sizeof(buffer)); - any_log_format(level, "lua", module, func, "%s", message); + any_log_format(level, module, func, "%s", message); return 0; } @@ -122,11 +117,11 @@ static int lua_log_wrapperv(lua_State *state, any_log_level_t level) lua_remove(state, 1); luaL_checktype(state, 1, LUA_TTABLE); - const char *module = "?", *func = ""; + const char *module, *func; char buffer[4096]; lua_log_debuginfo(state, &module, &func, buffer, sizeof(buffer)); - any_log_value(level, "lua", module, func, message, + any_log_value(level, module, func, message, "g:value", ANY_LOG_FORMATTER(lua_print_value), state, NULL); return 0; @@ -206,7 +201,7 @@ void lua_print_value_at(FILE *stream, lua_State *state, int index) first = false; if (lua_isnumber(state, -2)) { - fprintf(stream, "[%lld] = ", lua_tointeger(state, -2)); + fprintf(stream, "[%ld] = ", lua_tointeger(state, -2)); } else { fprintf(stream, "%s = ", lua_tostring(state, -2)); } |
