summaryrefslogtreecommitdiff
path: root/xmake/scripts/module
diff options
context:
space:
mode:
authorruki <[email protected]>2024-04-04 00:22:19 +0800
committerruki <[email protected]>2024-04-04 00:22:19 +0800
commitfee2d1b5106761728134c179375c73f9283a7ba1 (patch)
tree5aecd901ed3691dfe9b2fc75c5c2739b5442d004 /xmake/scripts/module
parentf716446fa869ef4dc9663d69a3e4364ef2dcbb6b (diff)
improve xmiopen
Diffstat (limited to 'xmake/scripts/module')
-rw-r--r--xmake/scripts/module/xmi.h38
1 files changed, 32 insertions, 6 deletions
diff --git a/xmake/scripts/module/xmi.h b/xmake/scripts/module/xmi.h
index c9a2d0a6f..d20f8242f 100644
--- a/xmake/scripts/module/xmi.h
+++ b/xmake/scripts/module/xmi.h
@@ -29,7 +29,7 @@
/* //////////////////////////////////////////////////////////////////////////////////////
* macros
*/
-#define xmi_lua_createtable(lua, narr, nrec) lua->_lua_createtable(lua->_lua, narr, nrec)
+#define xmi_lua_createtable(lua, narr, nrec) (g_lua_ops)->_lua_createtable(lua, narr, nrec)
#define xmi_lua_newtable(lua) xmi_lua_createtable(lua, 0, 0)
#ifndef LUA_VERSION
@@ -37,24 +37,50 @@
# define lua_newtable xmi_lua_newtable
# define luaL_Reg xmi_luaL_Reg
-# define lua_State struct xmi_lua_State_
+# define lua_State xmi_lua_State
#endif
+// define lua module entry function
+#define xmiopen(name, lua) \
+__dummy = 1; \
+xmi_lua_ops_t* g_lua_ops; \
+int xmisetup(xmi_lua_ops_t* ops) { \
+ g_lua_ops = ops; \
+ return __dummy; \
+} \
+int xmiopen_##name(lua)
+
/* //////////////////////////////////////////////////////////////////////////////////////
* types
*/
-struct xmi_lua_State_;
+typedef struct xmi_lua_State_ {
+ int dummy;
+}xmi_lua_State;
+
typedef struct xmi_luaL_Reg_ {
char const* name;
int (*func)(struct xmi_lua_State_* lua);
}xmi_luaL_Reg;
-typedef struct xmi_lua_State_ {
- void* _lua;
+typedef struct xmi_lua_ops_t_ {
void (*_lua_createtable)(lua_State* lua, int narr, int nrec);
-}xmi_lua_State;
+}xmi_lua_ops_t;
+/* //////////////////////////////////////////////////////////////////////////////////////
+ * interfaces
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// setup lua interfaces
+int xmisetup(xmi_lua_ops_t* ops);
+
+#ifdef __cplusplus
+}
+#endif
#endif