summaryrefslogtreecommitdiff
path: root/Examples/lua/simple
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2005-08-15 20:58:56 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2005-08-15 20:58:56 +0000
commit3941e1914116215fc2fc2731b8aa792403d7915d (patch)
tree5475f0a0f8630376957eb04e3d6d276f6b494624 /Examples/lua/simple
parentf498799a5bd984d7fc0967415c83402b2d1d9ca7 (diff)
downloadswig-3941e1914116215fc2fc2731b8aa792403d7915d.tar.gz
Support for Lua added - patch from Mark Gossage
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7365 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Examples/lua/simple')
-rw-r--r--Examples/lua/simple/Makefile18
-rw-r--r--Examples/lua/simple/example.c18
-rw-r--r--Examples/lua/simple/example.i7
-rw-r--r--Examples/lua/simple/runme.lua34
4 files changed, 77 insertions, 0 deletions
diff --git a/Examples/lua/simple/Makefile b/Examples/lua/simple/Makefile
new file mode 100644
index 000000000..9fbe1b6c3
--- /dev/null
+++ b/Examples/lua/simple/Makefile
@@ -0,0 +1,18 @@
+TOP = ../..
+SWIG = $(TOP)/../swig
+SRCS = example.c
+TARGET = example
+INTERFACE = example.i
+
+all::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua
+
+static::
+ $(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
+ TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static
+
+clean::
+ $(MAKE) -f $(TOP)/Makefile lua_clean
+
+check: all
diff --git a/Examples/lua/simple/example.c b/Examples/lua/simple/example.c
new file mode 100644
index 000000000..1c2af789c
--- /dev/null
+++ b/Examples/lua/simple/example.c
@@ -0,0 +1,18 @@
+/* File : example.c */
+
+/* A global variable */
+double Foo = 3.0;
+
+/* Compute the greatest common divisor of positive integers */
+int gcd(int x, int y) {
+ int g;
+ g = y;
+ while (x > 0) {
+ g = x;
+ x = y % x;
+ y = g;
+ }
+ return g;
+}
+
+
diff --git a/Examples/lua/simple/example.i b/Examples/lua/simple/example.i
new file mode 100644
index 000000000..86ae9f361
--- /dev/null
+++ b/Examples/lua/simple/example.i
@@ -0,0 +1,7 @@
+/* File : example.i */
+%module example
+
+%inline %{
+extern int gcd(int x, int y);
+extern double Foo;
+%} \ No newline at end of file
diff --git a/Examples/lua/simple/runme.lua b/Examples/lua/simple/runme.lua
new file mode 100644
index 000000000..71ec6054a
--- /dev/null
+++ b/Examples/lua/simple/runme.lua
@@ -0,0 +1,34 @@
+-- file: runme.lua
+
+-- importing (lua doesnt have a nice way to do this)
+if example==nil then
+ assert(loadlib("example.dll","Example_Init"))()
+end
+
+-- Call our gcd() function
+print("hello world")
+
+x = 42
+y = 105
+g = example.gcd(x,y)
+print("The gcd of",x,"and",y,"is",g)
+
+-- Manipulate the Foo global variable
+
+-- Output its current value
+print("Foo = ", example.Foo)
+
+-- Change its value
+example.Foo = 3.1415926
+
+-- See if the change took effect
+print("Foo = ", example.Foo)
+
+
+
+
+
+
+
+
+