summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorruki <[email protected]>2024-04-02 23:04:57 +0800
committerruki <[email protected]>2024-04-02 23:04:57 +0800
commitdf624c36f992f13bb65b8b2777718e1255ed5652 (patch)
treecbb777346b564997a09b6054c20a5611aa5fb919 /tests
parent15cb9bc95d2d8df1f9b14f3014c275f6b0032a34 (diff)
load foo module
Diffstat (limited to 'tests')
-rw-r--r--tests/projects/other/native_module/modules/shared/foo/src/add.cpp9
-rw-r--r--tests/projects/other/native_module/modules/shared/foo/src/foo.c29
-rw-r--r--tests/projects/other/native_module/modules/shared/foo/src/sub.cpp10
-rw-r--r--tests/projects/other/native_module/modules/shared/foo/xmake.lua11
4 files changed, 32 insertions, 27 deletions
diff --git a/tests/projects/other/native_module/modules/shared/foo/src/add.cpp b/tests/projects/other/native_module/modules/shared/foo/src/add.cpp
deleted file mode 100644
index e19d07e12..000000000
--- a/tests/projects/other/native_module/modules/shared/foo/src/add.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-int main(int argc, char** argv) {
- int a = atoi(argv[1]);
- int b = atoi(argv[2]);
- printf("%d", a + b);
- return 0;
-}
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
new file mode 100644
index 000000000..3024f9380
--- /dev/null
+++ b/tests/projects/other/native_module/modules/shared/foo/src/foo.c
@@ -0,0 +1,29 @@
+#include <stdlib.h>
+#include <lua.h>
+#include <lauxlib.h>
+
+static int add(lua_State* lua) {
+ int a = lua_tointeger(lua, 1);
+ int b = lua_tointeger(lua, 2);
+ lua_pushinteger(lua, a + b);
+ return 1;
+}
+
+static int sub(lua_State* lua) {
+ int a = lua_tointeger(lua, 1);
+ int b = lua_tointeger(lua, 2);
+ lua_pushinteger(lua, a - b);
+ return 1;
+}
+
+static const luaL_Reg g_funcs[] = {
+ {"add", add},
+ {"sub", sub},
+ {NULL, NULL}
+};
+
+int luaopen_foo(lua_State* lua) {
+ lua_newtable(lua);
+ luaL_setfuncs(lua, g_funcs, 0);
+ return 1;
+}
diff --git a/tests/projects/other/native_module/modules/shared/foo/src/sub.cpp b/tests/projects/other/native_module/modules/shared/foo/src/sub.cpp
deleted file mode 100644
index 980289d1a..000000000
--- a/tests/projects/other/native_module/modules/shared/foo/src/sub.cpp
+++ /dev/null
@@ -1,10 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-
-int main(int argc, char** argv) {
- int a = atoi(argv[1]);
- int b = atoi(argv[2]);
- printf("%d", a - b);
- return 0;
-}
-
diff --git a/tests/projects/other/native_module/modules/shared/foo/xmake.lua b/tests/projects/other/native_module/modules/shared/foo/xmake.lua
index 61c0a8357..e4fcc34ad 100644
--- a/tests/projects/other/native_module/modules/shared/foo/xmake.lua
+++ b/tests/projects/other/native_module/modules/shared/foo/xmake.lua
@@ -1,14 +1,9 @@
add_rules("mode.debug", "mode.release")
-add_requires("lua")
+add_requires("lua 5.4", {system = false})
-target("add")
+target("foo")
add_rules("module.shared")
- add_files("src/add.cpp")
- add_packages("lua")
-
-target("sub")
- add_rules("module.shared")
- add_files("src/sub.cpp")
+ add_files("src/foo.c")
add_packages("lua")