summaryrefslogtreecommitdiff
path: root/xmake/templates/c/module.shared/project/modules/shared/foo/src
diff options
context:
space:
mode:
authorruki <[email protected]>2024-04-03 22:54:03 +0800
committerruki <[email protected]>2024-04-03 22:54:03 +0800
commitbefc1ba876323c2df0030b9828bcdfad93b4a092 (patch)
tree8f981b8539dd5c6712afd88569bf41724b8deeda /xmake/templates/c/module.shared/project/modules/shared/foo/src
parentdb4196b069499e6fcf0d66c66a97665414c0011d (diff)
add module.shared template
Diffstat (limited to 'xmake/templates/c/module.shared/project/modules/shared/foo/src')
-rw-r--r--xmake/templates/c/module.shared/project/modules/shared/foo/src/foo.c29
1 files changed, 29 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;
+}