Thanks for all those explanations.
I now better understand some of the typemaps.
My resolution for now is putting %apply by a script.
Well, so, here is another question:
I'm wrapping the following class method, and it fails.
class wxControl : public wxWindow {
wxString GetLabel();
};
8--8--8--8--8--
wxchicken_core_wrap.cxx: In function 'void _wrap_wx_control_getslabel___(int, in
t, int, int)':
wxchicken_core_wrap.cxx:27542: error: invalid initialization of non-const refere
nce of type 'wxString' from a temporary of type 'wxString'
wxchicken_core_wrap.cxx:27551: error: invalid conversion from 'const wxChar*' to
'char*'
wxchicken_core_wrap.cxx:27551: error: initializing argument 3 of 'int C_string
(int**, int, char*)'
8--8--8--8--8--
I guess the problem is either in my typemaps,
or swig does not support reference returning?
The typemap is:
%typemap(in) wxString {
if ($input == C_SCHEME_FALSE) {
$1 = NULL;
} else {
if (!C_swig_is_string ($input)) {
swig_barf (SWIG_BARF1_BAD_ARGUMENT_TYPE, Argument #$argnum is not of
type 'char *');
}
$1 = new wxString(C_c_string($input), C_header_size($input));
}
}
%typemap(freearg) wxString {
if ($1 != NULL) {
delete $1;
}
}
%typemap(out) wxString {
if ($1 == NULL) {
$result = C_SCHEME_FALSE;
} else {
int string_len = $1-Len();
C_word *string_space = C_alloc (C_SIZEOF_STRING (string_len));
$result = C_string (string_space, string_len, $1-c_str());
}
}
%typemap(typecheck, precedence=SWIG_TYPECHECK_STRING) wxString {
$1 = C_swig_is_string ($input);
}
%apply wxString { wxString* }
Daishi
At Fri, 30 Jun 2006 01:01:47 -0500,
John Lenz wrote:
For the details on how typemaps are matched, see
http://www.swig.org/Doc1.3/Typemaps.html
mainly the section Pattern matching rules
No. Typemaps are just that... they are defined and stored and whatever
based on types. As such, the DISOWN typemap is slightly different than
most typemaps in that you want it to encode a property of the
parameter instead of the type itself. There are several possible
solutions...
1) Since typemaps encode properties of types and not parameters, change
the type of the parameter to reflect this. For example:
typedef Bar BarDisown;
%apply SWIGTYPE *DISOWN { BarDisown * };
and then everywhere in the .i file you use BarDisown instead of Bar.
2) SWIG provides a very basic way to match on the parameter, but only
based on name. So instead of applying all those things, you can just
write code like
class Foo {
void Foo(Bar DISOWN);
};
where the name of the parameter is DISOWN. SWIG will use the DISOWN
typemap for this, no need to add any apply or clear or anything. If you
don't like the name, you can do something like
%apply SWIGTYPE *DISOWN { SWIGTYPE *hey };
and just use hey everywhere.
3) Could encode DISOWN as a %feature instead of as a typemap. Features
encode properties of parameters (and classes) instead of types, and so
you have to specify the feature for every function or class (just like
you want). So you could do something like
%delobject Foo::Foo();
%delobject *::add_container();
The %feature (which is what %delobject is) is very powerful at applying
marks to specific functions and such.
This was recently added in SWIG version 1.3.28, but has not yet been
implemented for Chicken (it works for python). See the section:
http://www.swig.org/Doc1.3/Customization.html#ownership
and that whole chapter on how %feature works. I might look into
supporting this for chicken, If you would like to use it...
John
___
Chicken-users mailing list
Chicken-users@nongnu.org
http://lists.nongnu.org/mailman/listinfo/chicken-users