summaryrefslogtreecommitdiff
path: root/tests/projects/other/native_module_cjson/modules/lua
diff options
context:
space:
mode:
authorruki <[email protected]>2024-04-04 00:59:22 +0800
committerruki <[email protected]>2024-04-04 00:59:22 +0800
commit5c56dcd60dcce02babbcba862d71f3f891a712a4 (patch)
tree5acbf1b948f9e54d20b4ab58fdfdba04e85a2ca5 /tests/projects/other/native_module_cjson/modules/lua
parent89554d9ad26995b1732d8f36f197186ec23b8d40 (diff)
add cjson test
Diffstat (limited to 'tests/projects/other/native_module_cjson/modules/lua')
-rw-r--r--tests/projects/other/native_module_cjson/modules/lua/cjson/src/foo.c26
-rw-r--r--tests/projects/other/native_module_cjson/modules/lua/cjson/xmake.lua18
2 files changed, 44 insertions, 0 deletions
diff --git a/tests/projects/other/native_module_cjson/modules/lua/cjson/src/foo.c b/tests/projects/other/native_module_cjson/modules/lua/cjson/src/foo.c
new file mode 100644
index 000000000..0555b071f
--- /dev/null
+++ b/tests/projects/other/native_module_cjson/modules/lua/cjson/src/foo.c
@@ -0,0 +1,26 @@
+#include <xmi.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;
+}
+
+int luaopen(foo, lua_State* lua) {
+ static const luaL_Reg funcs[] = {
+ {"add", add},
+ {"sub", sub},
+ {NULL, NULL}
+ };
+ lua_newtable(lua);
+ luaL_setfuncs(lua, funcs, 0);
+ return 1;
+}
diff --git a/tests/projects/other/native_module_cjson/modules/lua/cjson/xmake.lua b/tests/projects/other/native_module_cjson/modules/lua/cjson/xmake.lua
new file mode 100644
index 000000000..4455613bc
--- /dev/null
+++ b/tests/projects/other/native_module_cjson/modules/lua/cjson/xmake.lua
@@ -0,0 +1,18 @@
+add_rules("mode.debug", "mode.release")
+
+target("cjson")
+ add_rules("module.shared")
+ set_warnings("all")
+ if is_plat("windows") then
+ set_languages("c89")
+ end
+ add_files("../../../../../../../core/src/lua-cjson/lua-cjson/*.c|fpconv.c")
+ -- Use internal strtod() / g_fmt() code for performance and disable multi-thread
+ add_defines("NDEBUG", "USE_INTERNAL_FPCONV")
+ add_defines("XM_CONFIG_API_HAVE_LUA_CJSON")
+ if is_plat("windows") then
+ -- Windows sprintf()/strtod() handle NaN/inf differently. Not supported.
+ add_defines("DISABLE_INVALID_NUMBERS")
+ add_defines("inline=__inline")
+ end
+