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/foo | |
| parent | db4196b069499e6fcf0d66c66a97665414c0011d (diff) | |
add module.shared template
Diffstat (limited to 'xmake/templates/c/module.shared/project/modules/shared/foo')
| -rw-r--r-- | xmake/templates/c/module.shared/project/modules/shared/foo/src/foo.c | 29 | ||||
| -rw-r--r-- | xmake/templates/c/module.shared/project/modules/shared/foo/xmake.lua | 9 |
2 files changed, 38 insertions, 0 deletions
diff --git a/xmake/templates/c/module.shared/project/modules/shared/foo/src/foo.c b/xmake/templates/c/module.shared/project/modules/shared/foo/src/foo.c new file mode 100644 index 000000000..3024f9380 --- /dev/null +++ b/xmake/templates/c/module.shared/project/modules/shared/foo/src/foo.c @@ -0,0 +1,29 @@ +#include <stdlib.h> +#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} +}; + +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..ad4590ffa --- /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.c") + add_packages("lua") + |
