update swig on windows

This commit is contained in:
Bassem Girgis
2019-08-04 21:38:19 -05:00
parent 8414b7136b
commit 76ad52be58
5943 changed files with 91790 additions and 71892 deletions

View File

@@ -0,0 +1,25 @@
TOP = ../..
SWIGEXE = $(TOP)/../swig
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
SWIGOPT =
LIBS =
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_run
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='base' INTERFACE='base.i' lua_cpp
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='foo' INTERFACE='foo.i' lua_cpp
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='bar' INTERFACE='bar.i' lua_cpp
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' LIBS='$(LIBS)' TARGET='spam' INTERFACE='spam.i' lua_cpp
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' lua_clean

View File

@@ -0,0 +1,36 @@
This example tests the %import directive and working with multiple modules.
Use 'lua runme.lua' to run a test.
Overview:
---------
The example defines 4 different extension modules--each wrapping
a separate C++ class.
base.i - Base class
foo.i - Foo class derived from Base
bar.i - Bar class derived from Base
spam.i - Spam class derived from Bar
Each module uses %import to refer to another module. For
example, the 'foo.i' module uses '%import base.i' to get
definitions for its base class.
If everything is okay, all of the modules will load properly and
type checking will work correctly. Caveat: Some compilers, for example
gcc-3.2.x, generate broken vtables with the inline methods in this test.
This is not a SWIG problem and can usually be solved with non-inlined
destructors compiled into separate shared objects/DLLs.
Unix:
-----
- Run make
- Run the test as described above
Windows:
--------
Sorry, no files here.
If you know how, you could copy the python or ruby example dsw & dsp and try editing that

View File

@@ -0,0 +1,21 @@
#include "base.h"
class Bar : public Base {
public:
Bar() { }
~Bar() { }
virtual const char * A() const {
return "Bar::A";
}
const char * B() const {
return "Bar::B";
}
virtual Base *toBase() {
return static_cast<Base *>(this);
}
static Bar *fromBase(Base *b) {
return dynamic_cast<Bar *>(b);
}
};

View File

@@ -0,0 +1,9 @@
%module bar
%{
#include "bar.h"
%}
%import base.i
%include "bar.h"

View File

@@ -0,0 +1,16 @@
class Base {
public:
Base() { }
virtual ~Base() { }
virtual const char * A() const {
return "Base::A";
}
const char * B() const {
return "Base::B";
}
virtual Base *toBase() {
return static_cast<Base *>(this);
}
};

View File

@@ -0,0 +1,6 @@
%module base
%{
#include "base.h"
%}
%include base.h

View File

@@ -0,0 +1,21 @@
#include "base.h"
class Foo : public Base {
public:
Foo() { }
~Foo() { }
virtual const char * A() const {
return "Foo::A";
}
const char * B() const {
return "Foo::B";
}
virtual Base *toBase() {
return static_cast<Base *>(this);
}
static Foo *fromBase(Base *b) {
return dynamic_cast<Foo *>(b);
}
};

View File

@@ -0,0 +1,8 @@
%module foo
%{
#include "foo.h"
%}
%import base.i
%include "foo.h"

View File

@@ -0,0 +1,103 @@
# Test various properties of classes defined in separate modules
print("Testing the %import directive")
if string.sub(_VERSION,1,7)=='Lua 5.0' then
-- lua5.0 doesn't have a nice way to do this
function loadit(a)
lib=loadlib(a..'.dll','luaopen_'..a) or loadlib(a..'.so','luaopen_'..a)
assert(lib)()
end
loadit('base')
loadit('foo')
loadit('bar')
loadit('spam')
else
-- lua 5.1 does
require 'base'
require 'foo'
require 'bar'
require 'spam'
end
-- Create some objects
print("Creating some objects")
a = base.Base()
b = foo.Foo()
c = bar.Bar()
d = spam.Spam()
-- Try calling some methods
print("Testing some methods")
print("Should see 'Base::A' ---> ",a:A())
print("Should see 'Base::B' ---> ",a:B())
print("Should see 'Foo::A' ---> ",b:A())
print("Should see 'Foo::B' ---> ",b:B())
print("Should see 'Bar::A' ---> ",c:A())
print("Should see 'Bar::B' ---> ",c:B())
print("Should see 'Spam::A' ---> ",d:A())
print("Should see 'Spam::B' ---> ",d:B())
-- Try some casts
print("\nTesting some casts")
x = a:toBase()
print("Should see 'Base::A' ---> ",x:A())
print("Should see 'Base::B' ---> ",x:B())
x = b:toBase()
print("Should see 'Foo::A' ---> ",x:A())
print("Should see 'Base::B' ---> ",x:B())
x = c:toBase()
print("Should see 'Bar::A' ---> ",x:A())
print("Should see 'Base::B' ---> ",x:B())
x = d:toBase()
print("Should see 'Spam::A' ---> ",x:A())
print("Should see 'Base::B' ---> ",x:B())
x = d:toBar()
print("Should see 'Bar::B' ---> ",x:B())
print "\nTesting some dynamic casts\n"
x = d:toBase()
print " Spam -> Base -> Foo : "
y = foo.Foo_fromBase(x)
if y then
print "bad swig"
else
print "good swig"
end
print " Spam -> Base -> Bar : "
y = bar.Bar_fromBase(x)
if y then
print "good swig"
else
print "bad swig"
end
print " Spam -> Base -> Spam : "
y = spam.Spam_fromBase(x)
if y then
print "good swig"
else
print "bad swig"
end
print " Foo -> Spam : "
y = spam.Spam_fromBase(b)
if y then
print "bad swig"
else
print "good swig"
end

View File

@@ -0,0 +1,24 @@
#include "bar.h"
class Spam : public Bar {
public:
Spam() { }
~Spam() { }
virtual const char * A() const {
return "Spam::A";
}
const char * B() const {
return "Spam::B";
}
virtual Base *toBase() {
return static_cast<Base *>(this);
}
virtual Bar *toBar() {
return static_cast<Bar *>(this);
}
static Spam *fromBase(Base *b) {
return dynamic_cast<Spam *>(b);
}
};

View File

@@ -0,0 +1,9 @@
%module spam
%{
#include "spam.h"
%}
%import bar.i
%include "spam.h"