summaryrefslogtreecommitdiff
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
parentdb4196b069499e6fcf0d66c66a97665414c0011d (diff)
add module.shared template
-rw-r--r--xmake/templates/c++/module.shared/.gitignore8
-rw-r--r--xmake/templates/c++/module.shared/project/modules/shared/foo/src/foo.cpp33
-rw-r--r--xmake/templates/c++/module.shared/project/modules/shared/foo/xmake.lua9
-rw-r--r--xmake/templates/c++/module.shared/project/src/main.cpp6
-rw-r--r--xmake/templates/c++/module.shared/project/xmake.lua15
-rw-r--r--xmake/templates/c++/module.shared/template.lua2
-rw-r--r--xmake/templates/c/module.shared/.gitignore8
-rw-r--r--xmake/templates/c/module.shared/project/modules/shared/foo/src/foo.c29
-rw-r--r--xmake/templates/c/module.shared/project/modules/shared/foo/xmake.lua9
-rw-r--r--xmake/templates/c/module.shared/project/src/main.c6
-rw-r--r--xmake/templates/c/module.shared/project/xmake.lua15
-rw-r--r--xmake/templates/c/module.shared/template.lua2
12 files changed, 142 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/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")
+
diff --git a/xmake/templates/c++/module.shared/project/src/main.cpp b/xmake/templates/c++/module.shared/project/src/main.cpp
new file mode 100644
index 000000000..7c775d288
--- /dev/null
+++ b/xmake/templates/c++/module.shared/project/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/project/xmake.lua b/xmake/templates/c++/module.shared/project/xmake.lua
new file mode 100644
index 000000000..34496aa5b
--- /dev/null
+++ b/xmake/templates/c++/module.shared/project/xmake.lua
@@ -0,0 +1,15 @@
+add_rules("mode.debug", "mode.release")
+
+add_moduledirs("modules")
+
+target("${TARGETNAME}")
+ 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}
+
diff --git a/xmake/templates/c++/module.shared/template.lua b/xmake/templates/c++/module.shared/template.lua
new file mode 100644
index 000000000..7869165b7
--- /dev/null
+++ b/xmake/templates/c++/module.shared/template.lua
@@ -0,0 +1,2 @@
+template("module.shared")
+ add_configfiles("xmake.lua")
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/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")
+
diff --git a/xmake/templates/c/module.shared/project/src/main.c b/xmake/templates/c/module.shared/project/src/main.c
new file mode 100644
index 000000000..113930e1a
--- /dev/null
+++ b/xmake/templates/c/module.shared/project/src/main.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main(int argc, char** argv) {
+ printf("hello world!\n");
+ return 0;
+}
diff --git a/xmake/templates/c/module.shared/project/xmake.lua b/xmake/templates/c/module.shared/project/xmake.lua
new file mode 100644
index 000000000..e39ac665d
--- /dev/null
+++ b/xmake/templates/c/module.shared/project/xmake.lua
@@ -0,0 +1,15 @@
+add_rules("mode.debug", "mode.release")
+
+add_moduledirs("modules")
+
+target("${TARGETNAME}")
+ set_kind("binary")
+ add_files("src/*.c")
+ 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}
+
diff --git a/xmake/templates/c/module.shared/template.lua b/xmake/templates/c/module.shared/template.lua
new file mode 100644
index 000000000..7869165b7
--- /dev/null
+++ b/xmake/templates/c/module.shared/template.lua
@@ -0,0 +1,2 @@
+template("module.shared")
+ add_configfiles("xmake.lua")