summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-04-03 23:55:17 +0800
committerruki <[email protected]>2024-04-03 23:55:17 +0800
commitf716446fa869ef4dc9663d69a3e4364ef2dcbb6b (patch)
tree2e8f5cdba8fd46558d199b42de79b4392a523353
parent953bb535caed3c53c8789e55c2f2a3208f1c4008 (diff)
use xmi.h
-rw-r--r--core/src/xmake/package/loadxmi.c8
-rw-r--r--core/src/xmake/xmake.lua1
-rwxr-xr-xcore/src/xmake/xmake.sh1
-rw-r--r--tests/projects/other/native_module/modules/shared/zoo/src/zoo.c2
-rw-r--r--xmake/scripts/module/xmi.h30
5 files changed, 32 insertions, 10 deletions
diff --git a/core/src/xmake/package/loadxmi.c b/core/src/xmake/package/loadxmi.c
index d45fda3bb..db4091431 100644
--- a/core/src/xmake/package/loadxmi.c
+++ b/core/src/xmake/package/loadxmi.c
@@ -29,11 +29,12 @@
* includes
*/
#include "prefix.h"
+#include "xmi.h"
/* //////////////////////////////////////////////////////////////////////////////////////
* types
*/
-typedef int (*xm_open_func_t)(lua_State* lua);
+typedef int (*xm_open_func_t)(xmi_lua_State* lua);
/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
@@ -68,5 +69,8 @@ tb_int_t xm_package_loadxmi(lua_State* lua)
}
// load module
- return func(lua);
+ xmi_lua_State xmi_lua = {0};
+ xmi_lua._lua = lua;
+ xmi_lua._lua_createtable = &lua_createtable;
+ return func(&xmi_lua);
}
diff --git a/core/src/xmake/xmake.lua b/core/src/xmake/xmake.lua
index 03e733c9a..15702c808 100644
--- a/core/src/xmake/xmake.lua
+++ b/core/src/xmake/xmake.lua
@@ -29,6 +29,7 @@ target("xmake")
add_includedirs("..", {interface = true})
add_includedirs("$(buildir)/$(plat)/$(arch)/$(mode)", {public = true})
add_includedirs("../xxhash")
+ add_includedirs("$(projectdir)/../xmake/scripts/module")
-- add header files
add_headerfiles("../(xmake/*.h)")
diff --git a/core/src/xmake/xmake.sh b/core/src/xmake/xmake.sh
index 5a3cbe1d0..62af5b2fa 100755
--- a/core/src/xmake/xmake.sh
+++ b/core/src/xmake/xmake.sh
@@ -50,6 +50,7 @@ target "xmake"
add_includedirs ".." "{public}"
add_includedirs "${buildir}/${plat}/${arch}/${mode}" "{public}"
add_includedirs "../xxhash"
+ add_includedirs "${projectdir}/xmake/scripts/module"
# add the common source files
add_files "*.c"
diff --git a/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c b/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c
index 472d5f12d..6b278fd25 100644
--- a/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c
+++ b/tests/projects/other/native_module/modules/shared/zoo/src/zoo.c
@@ -24,8 +24,8 @@ int xmiopen_zoo(lua_State* lua) {
{"sub", sub},
{NULL, NULL}
};
-#if 0
lua_newtable(lua);
+#if 0
luaL_setfuncs(lua, funcs, 0);
#endif
return 1;
diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h
index 598d23ef3..c9a2d0a6f 100644
--- a/xmake/scripts/module/xmi.h
+++ b/xmake/scripts/module/xmi.h
@@ -27,18 +27,34 @@
#include <stdlib.h>
/* //////////////////////////////////////////////////////////////////////////////////////
+ * macros
+ */
+#define xmi_lua_createtable(lua, narr, nrec) lua->_lua_createtable(lua->_lua, narr, nrec)
+#define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0)
+
+#ifndef LUA_VERSION
+# define lua_createtable xmi_lua_createtable
+# define lua_newtable xmi_lua_newtable
+
+# define luaL_Reg xmi_luaL_Reg
+# define lua_State struct xmi_lua_State_
+#endif
+
+/* //////////////////////////////////////////////////////////////////////////////////////
* types
*/
-struct lua_State_;
-typedef struct luaL_Reg_ {
+struct xmi_lua_State_;
+typedef struct xmi_luaL_Reg_ {
char const* name;
- int (*func)(struct lua_State_* lua);
-}luaL_Reg;
+ int (*func)(struct xmi_lua_State_* lua);
+}xmi_luaL_Reg;
+
+typedef struct xmi_lua_State_ {
+ void* _lua;
+ void (*_lua_createtable)(lua_State* lua, int narr, int nrec);
+}xmi_lua_State;
-typedef struct lua_State_ {
- void* ctx;
-}lua_State;
#endif