Change %extend example which said that char arrays were problematic to wrap, when in fact they are not
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11764 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
2c74fbf9e4
commit
09a801dd9e
4 changed files with 53 additions and 28 deletions
|
|
@ -1,6 +1,6 @@
|
|||
%module memberin_extend
|
||||
|
||||
// Tests memberin typemap. The default char * memberin typemap will be used.
|
||||
// Tests memberin typemap is not used for %extend.
|
||||
// The test extends the struct with a pseudo member variable
|
||||
|
||||
%inline %{
|
||||
|
|
|
|||
|
|
@ -4,22 +4,35 @@
|
|||
|
||||
%{
|
||||
typedef struct {
|
||||
char name[50];
|
||||
char name[50];
|
||||
} Person;
|
||||
%}
|
||||
|
||||
typedef struct {
|
||||
%extend {
|
||||
char *name;
|
||||
}
|
||||
%extend {
|
||||
char name[50];
|
||||
}
|
||||
} Person;
|
||||
|
||||
/* Specific implementation of set/get functions */
|
||||
%{
|
||||
char *Person_name_get(Person *p) {
|
||||
return p->name;
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
void make_upper(char *name) {
|
||||
char *c;
|
||||
for (c = name; *c; ++c)
|
||||
*c = (char)toupper((int)*c);
|
||||
}
|
||||
|
||||
/* Specific implementation of set/get functions forcing capitalization */
|
||||
|
||||
char *Person_name_get(Person *p) {
|
||||
make_upper(p->name);
|
||||
return p->name;
|
||||
}
|
||||
|
||||
void Person_name_set(Person *p, char *val) {
|
||||
strncpy(p->name,val,50);
|
||||
strncpy(p->name,val,50);
|
||||
make_upper(p->name);
|
||||
}
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import memberin_extend_c
|
||||
|
||||
t = memberin_extend_c.Person()
|
||||
t.name = "some name"
|
||||
if t.name != "some name":
|
||||
raise RuntimeError("some name wrong")
|
||||
t.name = "Fred Bloggs"
|
||||
if t.name != "FRED BLOGGS":
|
||||
raise RuntimeError("name wrong")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue