diff options
| author | ruki <[email protected]> | 2024-04-04 00:59:22 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-04-04 00:59:22 +0800 |
| commit | 5c56dcd60dcce02babbcba862d71f3f891a712a4 (patch) | |
| tree | 5acbf1b948f9e54d20b4ab58fdfdba04e85a2ca5 /tests | |
| parent | 89554d9ad26995b1732d8f36f197186ec23b8d40 (diff) | |
add cjson test
Diffstat (limited to 'tests')
6 files changed, 71 insertions, 3 deletions
diff --git a/tests/projects/other/native_module/test.lua b/tests/projects/other/native_module/test.lua index 0c2735866..b57362078 100644 --- a/tests/projects/other/native_module/test.lua +++ b/tests/projects/other/native_module/test.lua @@ -1,5 +1,3 @@ function main(t) - if not xmake.luajit() then - t:build() - end + t:build() end diff --git a/tests/projects/other/native_module_cjson/.gitignore b/tests/projects/other/native_module_cjson/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/native_module_cjson/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + 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 + diff --git a/tests/projects/other/native_module_cjson/src/main.cpp b/tests/projects/other/native_module_cjson/src/main.cpp new file mode 100644 index 000000000..7c775d288 --- /dev/null +++ b/tests/projects/other/native_module_cjson/src/main.cpp @@ -0,0 +1,6 @@ +#include <iostream> + +int main(int argc, char** argv) { + std::cout << "hello world!" << std::endl; + return 0; +} diff --git a/tests/projects/other/native_module_cjson/xmake.lua b/tests/projects/other/native_module_cjson/xmake.lua new file mode 100644 index 000000000..8768aca3e --- /dev/null +++ b/tests/projects/other/native_module_cjson/xmake.lua @@ -0,0 +1,12 @@ +add_rules("mode.debug", "mode.release") + +add_moduledirs("modules") + +target("test") + set_kind("binary") + add_files("src/*.cpp") + on_config(function (target) + import("lua.cjson", {always_build = true}) + print(cjson.decode('{"foo": 1, "bar": [1, 2, 3]}')) + end) + |
