Skip to content

Commit

Permalink
fix register lua funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Feb 6, 2025
1 parent 48850b4 commit d0425ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
19 changes: 13 additions & 6 deletions core/src/xmake/prefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/projects/xmake_cli/xmake/src/main.c
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit d0425ec

Please sign in to comment.