Forwarded from the SWIG mailing list, so we have a copy in our archives.
Kevin
-------- Original Message --------
Subject: Re: [Swig] Re: Object return problem
Date: Sun, 09 Oct 2005 18:31:40 -0400
From: Kevin Smith <wxruby@qualitycode.com>
To: Charlie Savage <cfis@interserv.com>
CC: Swig@cs.uchicago.edu
References: <4347277E.1030700@mindspring.com>
<4349911B.70200@interserv.com>
Hi guys,
I just figured out the answer. wxWindow uses directors (as almost all
our wxruby classes do), and the swig error message hints at the problem.
We need to use directorout typemaps, rather than just plain "out". I
inserted this, and it seemed to work:
%typemap(directorout) wxString {
$result = wxString(STR2CSTR($1), wxConvUTF8);
}
Typemaps are sure a confusing feature. They''re great, and powerful. But
I hope for SWIG v3 they can be completely overhauled to be more
consistent and straightforward.
I''ll forward this message to the wxruby list, too.
Kevin
Charlie Savage wrote:> Hi Roy,
>
> Not sure of the answer. Could you post the method signature of
> wxWindow::GetTitle and the relevant parts of the .i file that is
> processing it?
>
> Also, is the Ruby wxWindows SWIG binding you are working on available
> online someplace?
>
> Charlie
>
> Roy Sutton wrote:
>
>> Hello all! I''m working on wxRuby (a Ruby wrapping for
wxWindows) and
>> we''re running into some problems. We have a function
prototype that
>> looks like this:
>>
>> virtual wxString GetTitle() ;
>>
>> When attempting to swig this I get:
>>
>> swig\classes\include\wxWindow.h(9): Warning(471): Unable to use return
>> type wxString in director method wxWindow::GetTitle (skipping method).
>>
>> We have several typemaps for wxString, including an
''out'' typemap:
>>
>> %typemap(in) wxString& {
>> $1 = new wxString(STR2CSTR($input), wxConvUTF8);
>> }
>>
>> %typemap(in) const wxString& {
>> $1 = new wxString(STR2CSTR($input), wxConvUTF8);
>> }
>>
>> %typemap(in) wxString* {
>> $1 = new wxString(STR2CSTR($input), wxConvUTF8);
>> }
>>
>> /**
>> %typemap(freearg) wxString & {
>> delete $1;
>> }
>>
>> %typemap(freearg) const wxString& {
>> delete $1;
>> }
>>
>> %typemap(freearg) wxString* {
>> delete $1;
>> }
>> */
>> %typemap(directorin) wxString, const wxString &, wxString &
"$input =
>> rb_str_new2((const char *)$1.mb_str());";
>>
>> %typemap(directorin) wxString *, const wxString * "TODO:
>> $1_name->mb_str()";
>>
>>
>> %typemap(out) wxString {
>> $result = rb_str_new2((const char *)$1.mb_str());
>> }
>>
>> %typemap(out) wxString& {
>> $result = rb_str_new2((const char *)$1.mb_str());
>> }
>>
>> %typemap(out) const wxString& {
>> $result = rb_str_new2((const char *)$1.mb_str());
>> }
>>
>> %apply wxString& { wxString* }
>>
>>
>> %typemap(varout) wxString {
>> $result = rb_str_new2((const char *)$1.mb_str());
>> }
>>
>> %typemap(typecheck, precedence=SWIG_TYPECHECK_STRING) wxString {
>> $1 = (TYPE($input) == T_STRING);
>> }
>>
>> %typemap(typecheck, precedence=SWIG_TYPECHECK_STRING) wxString & {
>> $1 = (TYPE($input) == T_STRING);
>> }
>>
>>
>> %typemap(typecheck, precedence=SWIG_TYPECHECK_STRING) wxString const
& {
>> $1 = (TYPE($input) == T_STRING);
>> }
>>
>> %typemap(typecheck, precedence=SWIG_TYPECHECK_STRING) wxString *{
>> $1 = (TYPE($input) == T_STRING);
>> }
>>
>> Anyone have any inkling what we''re doing wrong here? Any
comments on
>> general improvements to our typemaps would be appreciated.
>> Unfortunately my swig-fu isn''t as advanced as it could be!
>>
>> Roy
>>
>> _______________________________________________
>> Swig maillist - Swig@cs.uchicago.edu
>> http://mailman.cs.uchicago.edu/mailman/listinfo/swig
>>
>
> _______________________________________________
> Swig maillist - Swig@cs.uchicago.edu
> http://mailman.cs.uchicago.edu/mailman/listinfo/swig
_______________________________________________
Swig maillist - Swig@cs.uchicago.edu
http://mailman.cs.uchicago.edu/mailman/listinfo/swig