aboutsummaryrefslogtreecommitdiff
path: root/src/lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/lua')
-rw-r--r--src/lua/api.c3
-rw-r--r--src/lua/log.c34
2 files changed, 27 insertions, 10 deletions
diff --git a/src/lua/api.c b/src/lua/api.c
index 3f68b1e..e2fdd30 100644
--- a/src/lua/api.c
+++ b/src/lua/api.c
@@ -1,6 +1,5 @@
#include "api.h"
-
-int lua_log_library(lua_State *state);
+#include "log.h"
bool lua_api_init(lua_api_t *lua)
{
diff --git a/src/lua/log.c b/src/lua/log.c
index 6811ec3..2b6d068 100644
--- a/src/lua/log.c
+++ b/src/lua/log.c
@@ -9,7 +9,8 @@ static lua_CFunction lua_log_stringformat = NULL;
static lua_CFunction lua_log_tostring = NULL;
-static inline void lua_log_debuginfo(lua_State *state, char buffer[], size_t size)
+static void lua_log_debuginfo(lua_State *state, const char **module, const char **func,
+ char buffer[], size_t size)
{
lua_pushcfunction(state, lua_log_getinfo);
@@ -17,7 +18,13 @@ static inline void lua_log_debuginfo(lua_State *state, char buffer[], size_t siz
lua_pushnumber(state, 2);
// S: source, l: currentline, n: name
- lua_pushstring(state, "Sl");
+ const char *query =
+#ifdef _RELEASE
+ "Sl";
+#else
+ "Sln";
+#endif
+ lua_pushstring(state, query);
if (lua_pcall(state, 2, 1, 0) == LUA_OK) {
lua_getfield(state, -1, "short_src");
@@ -26,12 +33,21 @@ static inline void lua_log_debuginfo(lua_State *state, char buffer[], size_t siz
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);
} else {
snprintf(buffer, size, "%s:%d", shortsrc, line);
}
+
+ *module = buffer;
} else {
log_trace("Failed to retrieve Lua debug information");
}
@@ -54,10 +70,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);
- char buffer[4096] = { "lua?" };
- lua_log_debuginfo(state, buffer, sizeof(buffer));
+ const char *module = "?", *func = "";
+ char buffer[4096];
+ lua_log_debuginfo(state, &module, &func, buffer, sizeof(buffer));
- any_log_format(level, "lua_api", buffer, "%s", message);
+ any_log_format(level, "lua", module, func, "%s", message);
return 0;
}
@@ -105,10 +122,11 @@ static int lua_log_wrapperv(lua_State *state, any_log_level_t level)
lua_remove(state, 1);
luaL_checktype(state, 1, LUA_TTABLE);
- char buffer[4096] = { "lua?" };
- lua_log_debuginfo(state, buffer, sizeof(buffer));
+ const char *module = "?", *func = "";
+ char buffer[4096];
+ lua_log_debuginfo(state, &module, &func, buffer, sizeof(buffer));
- any_log_value(level, "lua_api", buffer, message,
+ any_log_value(level, "lua", module, func, message,
"g:value", ANY_LOG_FORMATTER(lua_print_value), state,
NULL);
return 0;