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 | |
| parent | 89554d9ad26995b1732d8f36f197186ec23b8d40 (diff) | |
add cjson test
| -rw-r--r-- | tests/projects/other/native_module/test.lua | 4 | ||||
| -rw-r--r-- | tests/projects/other/native_module_cjson/.gitignore | 8 | ||||
| -rw-r--r-- | tests/projects/other/native_module_cjson/modules/lua/cjson/src/foo.c | 26 | ||||
| -rw-r--r-- | tests/projects/other/native_module_cjson/modules/lua/cjson/xmake.lua | 18 | ||||
| -rw-r--r-- | tests/projects/other/native_module_cjson/src/main.cpp | 6 | ||||
| -rw-r--r-- | tests/projects/other/native_module_cjson/xmake.lua | 12 | ||||
| -rw-r--r-- | xmake/scripts/module/lauxlib.h | 31 | ||||
| -rw-r--r-- | xmake/scripts/module/lua.h | 31 |
8 files changed, 133 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) + diff --git a/xmake/scripts/module/lauxlib.h b/xmake/scripts/module/lauxlib.h new file mode 100644 index 000000000..58f7c8b40 --- /dev/null +++ b/xmake/scripts/module/lauxlib.h @@ -0,0 +1,31 @@ +/*!A cross-platform build utility based on Lua + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright (C) 2015-present, TBOOX Open Source Group. + * + * @author ruki + * @file luaxlib.h + * + */ +#ifndef XMI_LUAXLIB_H +#define XMI_LUAXLIB_H + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "xmi.h" + +#endif + + diff --git a/xmake/scripts/module/lua.h b/xmake/scripts/module/lua.h new file mode 100644 index 000000000..92d799d57 --- /dev/null +++ b/xmake/scripts/module/lua.h @@ -0,0 +1,31 @@ +/*!A cross-platform build utility based on Lua + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright (C) 2015-present, TBOOX Open Source Group. + * + * @author ruki + * @file lua.h + * + */ +#ifndef XMI_LUA_H +#define XMI_LUA_H + +/* ////////////////////////////////////////////////////////////////////////////////////// + * includes + */ +#include "xmi.h" + +#endif + + |
