add more cases
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7686 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
e5f50bd942
commit
ab790f802a
6 changed files with 136 additions and 56 deletions
|
|
@ -1,67 +1,77 @@
|
||||||
%module(directors="1") director_basic
|
%module(directors="1") director_basic
|
||||||
%{
|
%{
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class Foo {
|
class Foo {
|
||||||
public:
|
public:
|
||||||
virtual ~Foo() {}
|
virtual ~Foo() {}
|
||||||
virtual std::string ping() { return "Foo::ping()"; }
|
virtual std::string ping() { return "Foo::ping()"; }
|
||||||
virtual std::string pong() { return "Foo::pong();" + ping(); }
|
virtual std::string pong() { return "Foo::pong();" + ping(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%include "std_string.i"
|
%include "std_string.i"
|
||||||
|
|
||||||
%feature("director") Foo;
|
%feature("director") Foo;
|
||||||
|
|
||||||
|
|
||||||
class Foo {
|
class Foo {
|
||||||
public:
|
public:
|
||||||
virtual ~Foo() {}
|
virtual ~Foo() {}
|
||||||
virtual std::string ping() { return "Foo::ping()"; }
|
virtual std::string ping() { return "Foo::ping()"; }
|
||||||
virtual std::string pong() { return "Foo::pong();" + ping(); }
|
virtual std::string pong() { return "Foo::pong();" + ping(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
%{
|
%{
|
||||||
#include <complex>
|
#include <complex>
|
||||||
%}
|
%}
|
||||||
%feature("director");
|
%feature("director");
|
||||||
|
|
||||||
// basic renaming
|
// basic renaming
|
||||||
%rename(rg) A::gg;
|
%rename(rg) A::gg;
|
||||||
%feature("nodirector") hi::A1::gg;
|
%feature("nodirector") hi::A1::gg;
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
|
|
||||||
struct A{
|
struct A{
|
||||||
A(std::complex<int> i, double d=0.0) {}
|
A(std::complex<int> i, double d=0.0) {}
|
||||||
A(int i, bool j=false) {}
|
A(int i, bool j=false) {}
|
||||||
virtual ~A() {}
|
virtual ~A() {}
|
||||||
|
|
||||||
virtual int f(int i=0) {return i;}
|
|
||||||
virtual int gg(int i=0) {return i;}
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace hi {
|
virtual int f(int i=0) {return i;}
|
||||||
|
virtual int gg(int i=0) {return i;}
|
||||||
|
};
|
||||||
|
|
||||||
struct A1 : public A {
|
namespace hi {
|
||||||
A1(std::complex<int> i, double d=0.0) : A(i, d) {}
|
|
||||||
A1(int i, bool j=false) : A(i, j) {}
|
struct A1 : public A {
|
||||||
|
A1(std::complex<int> i, double d=0.0) : A(i, d) {}
|
||||||
virtual int ff(int i = 0) {return i;}
|
A1(int i, bool j=false) : A(i, j) {}
|
||||||
};
|
|
||||||
}
|
virtual int ff(int i = 0) {return i;}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
%feature("director") MyClass;
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
|
||||||
|
typedef void VoidType;
|
||||||
|
|
||||||
|
struct Bar
|
||||||
|
{
|
||||||
|
int x;
|
||||||
|
Bar(int _x = 0) : x(_x)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%}
|
|
||||||
|
|
||||||
|
|
||||||
%feature("director") MyClass;
|
|
||||||
|
|
||||||
%inline %{
|
|
||||||
|
|
||||||
typedef void VoidType;
|
|
||||||
|
|
||||||
class MyClass {
|
class MyClass {
|
||||||
public:
|
public:
|
||||||
|
|
@ -76,6 +86,22 @@ public:
|
||||||
virtual ~MyClass()
|
virtual ~MyClass()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual Bar vmethod(Bar b)
|
||||||
|
{
|
||||||
|
b.x += 13;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bar cmethod(const Bar &b)
|
||||||
|
{
|
||||||
|
return vmethod(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
static MyClass *get_self(MyClass *c)
|
||||||
|
{
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -452,3 +452,7 @@ template_typedef_import.py
|
||||||
li_cwstring.py
|
li_cwstring.py
|
||||||
compactdefaultargs.py
|
compactdefaultargs.py
|
||||||
refcount.py
|
refcount.py
|
||||||
|
li_implicit.py
|
||||||
|
director_wstring.py
|
||||||
|
immutable.py
|
||||||
|
inherit.py
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
import director_basic
|
import director_basic
|
||||||
|
|
||||||
class MyFoo(director_basic.Foo):
|
class PyFoo(director_basic.Foo):
|
||||||
def ping(self):
|
def ping(self):
|
||||||
return "MyFoo::ping()"
|
return "PyFoo::ping()"
|
||||||
|
|
||||||
|
|
||||||
a = MyFoo()
|
a = PyFoo()
|
||||||
|
|
||||||
if a.ping() != "MyFoo::ping()":
|
if a.ping() != "PyFoo::ping()":
|
||||||
raise RuntimeError, a.ping()
|
raise RuntimeError, a.ping()
|
||||||
|
|
||||||
if a.pong() != "Foo::pong();MyFoo::ping()":
|
if a.pong() != "Foo::pong();PyFoo::ping()":
|
||||||
raise RuntimeError, a.pong()
|
raise RuntimeError, a.pong()
|
||||||
|
|
||||||
b = director_basic.Foo()
|
b = director_basic.Foo()
|
||||||
|
|
@ -26,3 +26,28 @@ a = director_basic.A1(1)
|
||||||
if a.rg(2) != 2:
|
if a.rg(2) != 2:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class PyClass(director_basic.MyClass):
|
||||||
|
def vmethod(self, b):
|
||||||
|
b.x += 31
|
||||||
|
return b
|
||||||
|
|
||||||
|
|
||||||
|
b = director_basic.Bar(3)
|
||||||
|
d = director_basic.MyClass()
|
||||||
|
c = PyClass()
|
||||||
|
|
||||||
|
cc = PyClass.get_self(c)
|
||||||
|
dd = PyClass.get_self(d)
|
||||||
|
|
||||||
|
bc = cc.cmethod(b)
|
||||||
|
bd = dd.cmethod(b)
|
||||||
|
|
||||||
|
if bc.x != 34:
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
||||||
|
if bd.x != 16:
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
|
||||||
14
Examples/test-suite/python/li_cmalloc_runme.py
Normal file
14
Examples/test-suite/python/li_cmalloc_runme.py
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
from li_cmalloc import *
|
||||||
|
|
||||||
|
p = malloc_int()
|
||||||
|
free_int(p)
|
||||||
|
|
||||||
|
ok = 0
|
||||||
|
try:
|
||||||
|
p = calloc_int(-1)
|
||||||
|
free_int(p)
|
||||||
|
except:
|
||||||
|
ok = 1
|
||||||
|
|
||||||
|
if ok != 1:
|
||||||
|
raise RuntimeError
|
||||||
10
Examples/test-suite/python/li_cpointer_runme.py
Normal file
10
Examples/test-suite/python/li_cpointer_runme.py
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
from li_cpointer import *
|
||||||
|
|
||||||
|
|
||||||
|
p = new_intp()
|
||||||
|
intp_assign(p,3)
|
||||||
|
|
||||||
|
if intp_value(p) != 3:
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
delete_intp(p)
|
||||||
|
|
@ -265,6 +265,7 @@ cvar.var_namet = pc
|
||||||
if cvar.var_namet != "hola":
|
if cvar.var_namet != "hola":
|
||||||
raise RuntimeError, "bad pointer case"
|
raise RuntimeError, "bad pointer case"
|
||||||
|
|
||||||
|
delete_pchar(pc)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Now when things should fail
|
# Now when things should fail
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue