add Luigi's static patch for extended variables
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7679 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
c0c3495ee4
commit
d94bb6260d
3 changed files with 43 additions and 4 deletions
|
|
@ -33,3 +33,19 @@ double ExtendMe_ExtendVar_get(ExtendMe *thisptr) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
%{
|
||||||
|
class Foo
|
||||||
|
{
|
||||||
|
};
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
public:
|
||||||
|
%extend {
|
||||||
|
static const int Bar = 42;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
|
||||||
4
Examples/test-suite/python/extend_variable_runme.py
Normal file
4
Examples/test-suite/python/extend_variable_runme.py
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
from extend_variable import *
|
||||||
|
|
||||||
|
if Foo.Bar != 42:
|
||||||
|
raise RuntimeError
|
||||||
|
|
@ -1371,14 +1371,33 @@ Language::staticmembervariableHandler(Node *n)
|
||||||
static const int x = 3;
|
static const int x = 3;
|
||||||
};
|
};
|
||||||
|
|
||||||
Some discussion of this in section 9.4 of the C++ draft standard. */
|
Some discussion of this in section 9.4 of the C++ draft standard.
|
||||||
|
|
||||||
|
Also, we have to manage the case:
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
public:
|
||||||
|
%extend {
|
||||||
|
static const int x = 3;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
in which there's no actual Foo::x variable to refer to. In this case,
|
||||||
|
the best we can do is to wrap the given value verbatim.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
String *name = Getattr(n,"name");
|
String *name = Getattr(n,"name");
|
||||||
String *cname = NewStringf("%s::%s", classname,name);
|
String *cname = NewStringf("%s::%s", classname,name);
|
||||||
String* value = SwigType_namestr(cname);
|
if (Getattr(n,"feature:extend")) {
|
||||||
Setattr(n, "value", value);
|
/* the variable is a synthesized one.
|
||||||
|
There's nothing we can do; we just keep the given value */
|
||||||
|
} else {
|
||||||
|
/* we refer to the value as Foo::x */
|
||||||
|
String* value = SwigType_namestr(cname);
|
||||||
|
Setattr(n, "value", value);
|
||||||
|
}
|
||||||
|
|
||||||
SwigType *t1 = SwigType_typedef_resolve_all(Getattr(n,"type"));
|
SwigType *t1 = SwigType_typedef_resolve_all(Getattr(n,"type"));
|
||||||
SwigType *t2 = SwigType_strip_qualifiers(t1);
|
SwigType *t2 = SwigType_strip_qualifiers(t1);
|
||||||
Setattr(n, "type", t2);
|
Setattr(n, "type", t2);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue