From a262dc8acd581052ee6b5d5430af69148540a843 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Sat, 23 Aug 2025 00:01:31 +0200 Subject: Move to luajit and fix logs --- src/lua/api.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/lua/api.c') diff --git a/src/lua/api.c b/src/lua/api.c index e2fdd30..47194ad 100644 --- a/src/lua/api.c +++ b/src/lua/api.c @@ -4,12 +4,26 @@ bool lua_api_init(lua_api_t *lua) { lua->state = luaL_newstate(); + if (!lua->state) + return false; + luaL_openlibs(lua->state); - luaL_requiref(lua->state, "log", lua_log_library, 1); - lua_pop(lua->state, 1); + + lua_api_require(lua, "log", lua_log_library); return true; } +void lua_api_require(lua_api_t *lua, const char *name, lua_library_t lib_fn) +{ + lua_pushcfunction(lua->state, lib_fn); + lua_pushstring(lua->state, name); + lua_call(lua->state, 1, 1); + + lua_pushvalue(lua->state, -1); + lua_setglobal(lua->state, name); + lua_pop(lua->state, 1); +} + void lua_api_close(lua_api_t *lua) { lua_close(lua->state); -- cgit v1.2.3