Initial commit

This commit is contained in:
Bassem Girgis
2018-12-20 17:34:07 -06:00
parent 7a2d899662
commit 81b4b9e273
34743 changed files with 5940233 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
TOP = ../..
SWIGEXE = $(TOP)/../swig
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
SRCS = example.c
TARGET = example
INTERFACE = example.i
LIBS =
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' lua
static:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
TARGET='mylua' INTERFACE='$(INTERFACE)' lua_static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean

View 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;
}

View File

@@ -0,0 +1,12 @@
/* File : example.i */
%module example
%include "typemaps.i"
%inline %{
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 */
%}

View 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','luaopen_example') or loadlib('example.so','luaopen_example')
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))