Support for Lua added - patch from Mark Gossage
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7365 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
e2c90c74a9
commit
127e49e03b
27 changed files with 2266 additions and 0 deletions
18
SWIG/Examples/lua/simple/Makefile
Normal file
18
SWIG/Examples/lua/simple/Makefile
Normal file
|
|
@ -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
|
||||
18
SWIG/Examples/lua/simple/example.c
Normal file
18
SWIG/Examples/lua/simple/example.c
Normal file
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
7
SWIG/Examples/lua/simple/example.i
Normal file
7
SWIG/Examples/lua/simple/example.i
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%inline %{
|
||||
extern int gcd(int x, int y);
|
||||
extern double Foo;
|
||||
%}
|
||||
34
SWIG/Examples/lua/simple/runme.lua
Normal file
34
SWIG/Examples/lua/simple/runme.lua
Normal file
|
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue