diff options
| author | ruki <[email protected]> | 2024-04-03 22:54:03 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-04-03 22:54:03 +0800 |
| commit | befc1ba876323c2df0030b9828bcdfad93b4a092 (patch) | |
| tree | 8f981b8539dd5c6712afd88569bf41724b8deeda /xmake/templates/c++/module.shared/project/modules/shared | |
| parent | db4196b069499e6fcf0d66c66a97665414c0011d (diff) | |
add module.shared template
Diffstat (limited to 'xmake/templates/c++/module.shared/project/modules/shared')
| -rw-r--r-- | xmake/templates/c++/module.shared/project/modules/shared/foo/src/foo.cpp | 33 | ||||
| -rw-r--r-- | xmake/templates/c++/module.shared/project/modules/shared/foo/xmake.lua | 9 |
2 files changed, 42 insertions, 0 deletions
diff --git a/xmake/templates/c++/module.shared/project/modules/shared/foo/src/foo.cpp b/xmake/templates/c++/module.shared/project/modules/shared/foo/src/foo.cpp new file mode 100644 index 000000000..b6eb451ba --- /dev/null +++ b/xmake/templates/c++/module.shared/project/modules/shared/foo/src/foo.cpp @@ -0,0 +1,33 @@ +#include <stdlib.h> +extern "C" { +#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} +}; + +extern "C" { + int luaopen_foo(lua_State* lua) { + lua_newtable(lua); + luaL_setfuncs(lua, g_funcs, 0); + return 1; + } +} diff --git a/xmake/templates/c++/module.shared/project/modules/shared/foo/xmake.lua b/xmake/templates/c++/module.shared/project/modules/shared/foo/xmake.lua new file mode 100644 index 000000000..deef51363 --- /dev/null +++ b/xmake/templates/c++/module.shared/project/modules/shared/foo/xmake.lua @@ -0,0 +1,9 @@ +add_rules("mode.debug", "mode.release") + +add_requires("lua 5.4") + +target("foo") + add_rules("module.shared") + add_files("src/foo.cpp") + add_packages("lua") + |
