summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-09-27 22:35:24 +0800
committerruki <[email protected]>2021-09-27 22:35:24 +0800
commit9128fe7d5b84a27831ae2535a16547bb0b9b7d8e (patch)
tree299f6a0ff0c871ca149cf327ef9665bae55e6f31
parentd00138d98064b84db0c76dde99587b5ea425fdf4 (diff)
add lua_c swig test
-rw-r--r--tests/projects/swig/lua_c/src/example.c25
-rw-r--r--tests/projects/swig/lua_c/src/example.i6
-rw-r--r--tests/projects/swig/lua_c/xmake.lua8
-rw-r--r--tests/projects/swig/python_c/src/example.c10
-rw-r--r--tests/projects/swig/python_cpp/src/example.cpp10
5 files changed, 49 insertions, 10 deletions
diff --git a/tests/projects/swig/lua_c/src/example.c b/tests/projects/swig/lua_c/src/example.c
new file mode 100644
index 000000000..c4afe9779
--- /dev/null
+++ b/tests/projects/swig/lua_c/src/example.c
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include "lua.h"
+#include "lualib.h"
+#include "lauxlib.h"
+
+extern int luaopen_example(lua_State* L); // declare the wrapped module
+
+int main(int argc,char* argv[])
+{
+ lua_State *L;
+ if (argc<2)
+ {
+ printf("%s: <filename.lua>\n",argv[0]);
+ return 0;
+ }
+ L=lua_open();
+ luaopen_base(L); // load basic libs (eg. print)
+ luaopen_example(L); // load the wrappered module
+ if (luaL_loadfile(L,argv[1])==0) // load and run the file
+ lua_pcall(L,0,0,0);
+ else
+ printf("unable to load %s\n",argv[1]);
+ lua_close(L);
+ return 0;
+}
diff --git a/tests/projects/swig/lua_c/src/example.i b/tests/projects/swig/lua_c/src/example.i
new file mode 100644
index 000000000..f17b34a82
--- /dev/null
+++ b/tests/projects/swig/lua_c/src/example.i
@@ -0,0 +1,6 @@
+%module example
+%{
+#include "example.h"
+%}
+int gcd(int x, int y);
+extern double Foo;
diff --git a/tests/projects/swig/lua_c/xmake.lua b/tests/projects/swig/lua_c/xmake.lua
new file mode 100644
index 000000000..fc6e3dd7b
--- /dev/null
+++ b/tests/projects/swig/lua_c/xmake.lua
@@ -0,0 +1,8 @@
+add_rules("mode.release", "mode.debug")
+add_requires("lua")
+
+target("example")
+ add_rules("swig.c")
+ add_files("src/example.i", {moduletype = "lua", scriptdir = "share"})
+ add_files("src/example.c")
+ add_packages("lua")
diff --git a/tests/projects/swig/python_c/src/example.c b/tests/projects/swig/python_c/src/example.c
index 31c659bfa..b0ddc9c26 100644
--- a/tests/projects/swig/python_c/src/example.c
+++ b/tests/projects/swig/python_c/src/example.c
@@ -2,13 +2,13 @@ double My_variable = 3.0;
/* Compute factorial of n */
int fact(int n) {
- if (n <= 1)
- return 1;
- else
- return n*fact(n-1);
+ if (n <= 1)
+ return 1;
+ else
+ return n*fact(n-1);
}
/* Compute n mod m */
int my_mod(int n, int m) {
- return(n % m);
+ return(n % m);
}
diff --git a/tests/projects/swig/python_cpp/src/example.cpp b/tests/projects/swig/python_cpp/src/example.cpp
index 31c659bfa..b0ddc9c26 100644
--- a/tests/projects/swig/python_cpp/src/example.cpp
+++ b/tests/projects/swig/python_cpp/src/example.cpp
@@ -2,13 +2,13 @@ double My_variable = 3.0;
/* Compute factorial of n */
int fact(int n) {
- if (n <= 1)
- return 1;
- else
- return n*fact(n-1);
+ if (n <= 1)
+ return 1;
+ else
+ return n*fact(n-1);
}
/* Compute n mod m */
int my_mod(int n, int m) {
- return(n % m);
+ return(n % m);
}