aboutsummaryrefslogtreecommitdiff
path: root/src/lua/log.c
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2025-04-14 17:40:07 +0200
committerFederico Angelilli <code@fedang.net>2025-04-14 17:40:07 +0200
commitdc9e9c06421eb9156baf425ac14ec8f50cb8b5ae (patch)
tree71aa14140797cfa28c0abaed724c79a989cb621e /src/lua/log.c
parent9c9139d0eb4244c66123fdbfd211105ede8c4b42 (diff)
Update logging
Diffstat (limited to 'src/lua/log.c')
-rw-r--r--src/lua/log.c31
1 files changed, 11 insertions, 20 deletions
diff --git a/src/lua/log.c b/src/lua/log.c
index b49c003..6811ec3 100644
--- a/src/lua/log.c
+++ b/src/lua/log.c
@@ -2,7 +2,6 @@
#include <string.h>
#include "log.h"
-#include "../any_log.h"
static lua_CFunction lua_log_getinfo = NULL;
@@ -10,15 +9,15 @@ static lua_CFunction lua_log_stringformat = NULL;
static lua_CFunction lua_log_tostring = NULL;
-static inline void lua_log_debuginfo(lua_State *state, const char **source, const char **func,
- char buffer[], size_t size)
+static inline void lua_log_debuginfo(lua_State *state, char buffer[], size_t size)
{
lua_pushcfunction(state, lua_log_getinfo);
// Ignore the first frame (the c function itself)
lua_pushnumber(state, 2);
+
// S: source, l: currentline, n: name
- lua_pushstring(state, "Sln");
+ lua_pushstring(state, "Sl");
if (lua_pcall(state, 2, 1, 0) == LUA_OK) {
lua_getfield(state, -1, "short_src");
@@ -29,16 +28,10 @@ static inline void lua_log_debuginfo(lua_State *state, const char **source, cons
if (!strncmp(shortsrc, "[string ", 8)) {
int length = strlen(shortsrc);
- snprintf(buffer, size, "lua %.*s", length - 9, shortsrc + 8);
+ snprintf(buffer, size, "%.*s", length - 9, shortsrc + 8);
} else {
- snprintf(buffer, size, "lua %s:%d", shortsrc, line);
+ snprintf(buffer, size, "%s:%d", shortsrc, line);
}
-
- lua_getfield(state, -3, "name");
- const char *name = lua_tostring(state, -1);
-
- *source = buffer;
- *func = name ? name : "...";
} else {
log_trace("Failed to retrieve Lua debug information");
}
@@ -61,11 +54,10 @@ 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 *source = "?", *func = "?";
- char buffer[4096];
- lua_log_debuginfo(state, &source, &func, buffer, sizeof(buffer));
+ char buffer[4096] = { "lua?" };
+ lua_log_debuginfo(state, buffer, sizeof(buffer));
- any_log_format(level, source, func, "%s", message);
+ any_log_format(level, "lua_api", buffer, "%s", message);
return 0;
}
@@ -113,11 +105,10 @@ 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 *source = "?", *func = "?";
- char buffer[4096];
- lua_log_debuginfo(state, &source, &func, buffer, sizeof(buffer));
+ char buffer[4096] = { "lua?" };
+ lua_log_debuginfo(state, buffer, sizeof(buffer));
- any_log_value(level, source, func, message,
+ any_log_value(level, "lua_api", buffer, message,
"g:value", ANY_LOG_FORMATTER(lua_print_value), state,
NULL);
return 0;