New Lua examples - Mark Gossage patch #1295168
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7471 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
39119b2d07
commit
ef13b64b7e
12 changed files with 309 additions and 0 deletions
19
SWIG/Examples/lua/functest/Makefile
Normal file
19
SWIG/Examples/lua/functest/Makefile
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../swig
|
||||
CXXSRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
LIBS =
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile CXXSRCS='$(CXXSRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile lua_clean
|
||||
|
||||
check: all
|
||||
25
SWIG/Examples/lua/functest/example.c
Normal file
25
SWIG/Examples/lua/functest/example.c
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* File : example.c */
|
||||
|
||||
/* A global variable */
|
||||
double Foo = 3.0;
|
||||
|
||||
int add1(int x, int y)
|
||||
{
|
||||
return x+y;
|
||||
}
|
||||
|
||||
void add2(int x, int *y, int *z)
|
||||
{
|
||||
*z = x+*y;
|
||||
}
|
||||
|
||||
int add3(int x, int y, int *z)
|
||||
{
|
||||
*z = x-y;
|
||||
return x+y;
|
||||
}
|
||||
|
||||
void add4(int x, int *y)
|
||||
{
|
||||
*y += x;
|
||||
}
|
||||
11
SWIG/Examples/lua/functest/example.i
Normal file
11
SWIG/Examples/lua/functest/example.i
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
|
||||
%include "typemaps.i" // you must have this for the typemaps for ptrs
|
||||
// basic function testing
|
||||
//
|
||||
extern int add1(int x, int y); // return x+y -- basic function test
|
||||
extern void add2(int x, int *INPUT, int *OUTPUT); // *z = x+*y -- argin and argout test
|
||||
extern int add3(int x, int y, int *OUTPUT); // return x+y, *z=x-y -- returning 2 values
|
||||
extern void add4(int x, int *INOUT); // *y += x -- INOUT dual purpose variable
|
||||
|
||||
20
SWIG/Examples/lua/functest/runme.lua
Normal file
20
SWIG/Examples/lua/functest/runme.lua
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
---- importing ----
|
||||
if string.sub(_VERSION,1,7)=='Lua 5.0' then
|
||||
-- lua5.0 doesnt have a nice way to do this
|
||||
lib=loadlib('example.dll','Example_Init') or loadlib('example.so','Example_Init')
|
||||
assert(lib)()
|
||||
else
|
||||
-- lua 5.1 does
|
||||
require('example')
|
||||
end
|
||||
|
||||
|
||||
x,y = 42,105
|
||||
print("add1 - simple arg passing and single return value -- ")
|
||||
print(example.add1(x,y))
|
||||
print("add2 - pointer arg passing and single return value through pointer arg -- ")
|
||||
print(example.add2(x,y))
|
||||
print("add3 - simple arg passing and double return value through return and ptr arg -- ")
|
||||
print(example.add3(x,y))
|
||||
print("add4 - dual use arg and return value -- ")
|
||||
print(example.add4(x,y))
|
||||
Loading…
Add table
Add a link
Reference in a new issue