summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-02-06 23:00:01 +0800
committerruki <[email protected]>2025-02-06 23:00:01 +0800
commitd0425ec0b0126b02c6c03b7db52372109157335b (patch)
tree6c58a1d48191d17e0a1665b4d9e378c7968b9363
parent48850b4c5a6c1022d3ea9e65d1904f59b45001f4 (diff)
fix register lua funcs
-rw-r--r--core/src/xmake/prefix.h19
-rw-r--r--tests/projects/xmake_cli/xmake/src/main.c3
2 files changed, 14 insertions, 8 deletions
diff --git a/core/src/xmake/prefix.h b/core/src/xmake/prefix.h
index 5d6fba582..3c5c0679f 100644
--- a/core/src/xmake/prefix.h
+++ b/core/src/xmake/prefix.h
@@ -117,14 +117,21 @@ static __tb_inline__ tb_pointer_t xm_lua_topointer(lua_State* lua, tb_int_t idx)
static __tb_inline__ tb_void_t xm_lua_register(lua_State *lua, tb_char_t const* libname, luaL_Reg const* l)
{
#if LUA_VERSION_NUM >= 504
- lua_getglobal(lua, libname);
- if (lua_isnil(lua, -1))
+ if (libname)
{
- lua_pop(lua, 1);
- lua_newtable(lua);
+ lua_getglobal(lua, libname);
+ if (lua_isnil(lua, -1))
+ {
+ lua_pop(lua, 1);
+ lua_newtable(lua);
+ }
+ luaL_setfuncs(lua, l, 0);
+ lua_setglobal(lua, libname);
+ }
+ else
+ {
+ luaL_setfuncs(lua, l, 0);
}
- luaL_setfuncs(lua, l, 0);
- lua_setglobal(lua, libname);
#else
luaL_register(lua, libname, l);
#endif
diff --git a/tests/projects/xmake_cli/xmake/src/main.c b/tests/projects/xmake_cli/xmake/src/main.c
index 975f51c38..7d1cda3e2 100644
--- a/tests/projects/xmake_cli/xmake/src/main.c
+++ b/tests/projects/xmake_cli/xmake/src/main.c
@@ -1,6 +1,5 @@
#include <xmake/xmake.h>
-tb_int_t main(tb_int_t argc, tb_char_t** argv)
-{
+tb_int_t main(tb_int_t argc, tb_char_t** argv) {
return xm_engine_run("xmake", argc, argv, tb_null, tb_null);
}