summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorruki <[email protected]>2024-04-03 23:42:56 +0800
committerruki <[email protected]>2024-04-03 23:42:56 +0800
commitd08d95ac8fc9e1f316ff180aaedd61e21c384e24 (patch)
treeebcfb72223ceb58280f51cbc327f22d62b2ce749 /tests
parent817353b79fc9145c18992facd920ec8f9497000b (diff)
improve xmi.h
Diffstat (limited to 'tests')
-rw-r--r--tests/projects/other/native_module/modules/shared/foo/src/foo.c13
-rw-r--r--tests/projects/other/native_module/modules/shared/zoo/src/zoo.c32
-rw-r--r--tests/projects/other/native_module/xmake.lua2
3 files changed, 33 insertions, 14 deletions
diff --git a/tests/projects/other/native_module/modules/shared/foo/src/foo.c b/tests/projects/other/native_module/modules/shared/foo/src/foo.c
index 3024f9380..c8ac1c81c 100644
--- a/tests/projects/other/native_module/modules/shared/foo/src/foo.c
+++ b/tests/projects/other/native_module/modules/shared/foo/src/foo.c
@@ -16,14 +16,13 @@ static int sub(lua_State* lua) {
return 1;
}
-static const luaL_Reg g_funcs[] = {
- {"add", add},
- {"sub", sub},
- {NULL, NULL}
-};
-
int luaopen_foo(lua_State* lua) {
+ static const luaL_Reg funcs[] = {
+ {"add", add},
+ {"sub", sub},
+ {NULL, NULL}
+ };
lua_newtable(lua);
- luaL_setfuncs(lua, g_funcs, 0);
+ luaL_setfuncs(lua, funcs, 0);
return 1;
}
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 b9bf90ec5..a93fb0dab 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
@@ -1,12 +1,32 @@
-#include <stdlib.h>
+#include <xmi.h>
-int add(int a, int b) {
- return a + b;
+static int add(lua_State* lua) {
+#if 0
+ int a = lua_tointeger(lua, 1);
+ int b = lua_tointeger(lua, 2);
+ lua_pushinteger(lua, a + b);
+#endif
+ return 1;
}
-int sub(int a, int b) {
- return a + b;
+static int sub(lua_State* lua) {
+#if 0
+ int a = lua_tointeger(lua, 1);
+ int b = lua_tointeger(lua, 2);
+ lua_pushinteger(lua, a - b);
+#endif
+ return 1;
}
-void module_zoo() {
+int xmi_luaopen_foo(lua_State* lua) {
+ static const luaL_Reg funcs[] = {
+ {"add", add},
+ {"sub", sub},
+ {NULL, NULL}
+ };
+#if 0
+ lua_newtable(lua);
+ luaL_setfuncs(lua, funcs, 0);
+#endif
+ return 1;
}
diff --git a/tests/projects/other/native_module/xmake.lua b/tests/projects/other/native_module/xmake.lua
index 3148fc0f2..3f895bb12 100644
--- a/tests/projects/other/native_module/xmake.lua
+++ b/tests/projects/other/native_module/xmake.lua
@@ -7,7 +7,7 @@ target("test")
add_files("src/*.cpp")
on_config(function (target)
import("shared.foo")
- import("shared.zoo")
+ import("shared.zoo", {always_build = true})
import("binary.bar", {always_build = true})
print("foo: 1 + 1 = %d", foo.add(1, 1))
print("foo: 1 - 1 = %d", foo.sub(1, 1))