diff options
| author | ruki <[email protected]> | 2026-08-09 18:25:05 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-08-09 18:25:05 +0800 |
| commit | ced7f2ae519bc9eca92bcf4f177fe177ddd0e747 (patch) | |
| tree | af4d584b3c7badc1df56038cdb29099b4f3e99fd /xmake/templates/c++/module/shared | |
| parent | 6ac4ea833193a4319a1eb6e5f588d1877fd48064 (diff) | |
| parent | 5f5daf64c504e1103a355f45bf925a5149b03e24 (diff) | |
Merge pull request #7699 from xmake-io/templates
move templates dir
Diffstat (limited to 'xmake/templates/c++/module/shared')
5 files changed, 57 insertions, 0 deletions
diff --git a/xmake/templates/c++/module/shared/.gitignore b/xmake/templates/c++/module/shared/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/xmake/templates/c++/module/shared/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/xmake/templates/c++/module/shared/modules/shared/foo/src/foo.cpp b/xmake/templates/c++/module/shared/modules/shared/foo/src/foo.cpp new file mode 100644 index 000000000..adde214ca --- /dev/null +++ b/xmake/templates/c++/module/shared/modules/shared/foo/src/foo.cpp @@ -0,0 +1,22 @@ +#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/xmake/templates/c++/module/shared/modules/shared/foo/xmake.lua b/xmake/templates/c++/module/shared/modules/shared/foo/xmake.lua new file mode 100644 index 000000000..9b3423d41 --- /dev/null +++ b/xmake/templates/c++/module/shared/modules/shared/foo/xmake.lua @@ -0,0 +1,6 @@ +add_rules("mode.debug", "mode.release") + +target("foo") + add_rules("module.shared") + add_files("src/foo.cpp") + diff --git a/xmake/templates/c++/module/shared/src/main.cpp b/xmake/templates/c++/module/shared/src/main.cpp new file mode 100644 index 000000000..9b6abffea --- /dev/null +++ b/xmake/templates/c++/module/shared/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/xmake/templates/c++/module/shared/xmake.lua b/xmake/templates/c++/module/shared/xmake.lua new file mode 100644 index 000000000..43aafe904 --- /dev/null +++ b/xmake/templates/c++/module/shared/xmake.lua @@ -0,0 +1,15 @@ +add_rules("mode.debug", "mode.release") + +add_moduledirs("modules") + +target("${TARGET_NAME}") + set_kind("binary") + add_files("src/*.cpp") + on_config(function (target) + import("shared.foo") + print("shared: 1 + 1 = %s", foo.add(1, 1)) + print("shared: 1 - 1 = %s", foo.sub(1, 1)) + end) + +${FAQ} + |
