Hi Ryan,
Doubi wrote:
I'm implementing a function (LoadURL) which takes a single argument of
const wxString&. wxString is implemented in the main Wx typemap, but not
a const version. If I try neglecting the const in my .xs file I'm told:
WebKit.c: In function ‘void XS_Wx__WebView_LoadURL(PerlInterpreter*, CV*)’:
WebKit.c:217: error: conversion from ‘wxString*’ to ‘const wxString’ is
ambiguous
/usr/local/include/wx-2.8/wx/string.h:692: note: candidates are:
wxString::wxString(wxChar, size_t) <near match>
/usr/local/include/wx-2.8/wx/string.h:682: note: wxString::wxString(int)
<near match>
WebKit.c: In function ‘void boot_Wx__WebKit(PerlInterpreter*, CV*)’:
WebKit.c:419: warning: deprecated conversion from string constant to
‘char*’
When I try mapping const wxString to T_WXSTRING just like the non-const
version (I saw that both T_WXCHAR and T_CONST_WXCHAR have the same
inputs and outputs in the typemap) I'm even more erroneous:
WebKit.c: In function ‘void XS_Wx__WebView_LoadURL(PerlInterpreter*, CV*)’:
WebKit.c:215: error: passing ‘const wxString’ as ‘this’ argument of
‘wxString& wxString::operator=(const wxString&)’ discards qualifiers
WebKit.c:217: error: conversion from ‘const wxString*’ to ‘const
wxString’ is ambiguous
/usr/local/include/wx-2.8/wx/string.h:692: note: candidates are:
wxString::wxString(wxChar, size_t) <near match>
/usr/local/include/wx-2.8/wx/string.h:682: note: wxString::wxString(int)
<near match>
WebKit.c: In function ‘void boot_Wx__WebKit(PerlInterpreter*, CV*)’:
WebKit.c:419: warning: deprecated conversion from string constant to
‘char*’
Apparently the wxString class isn't set up correctly to be used with
constness? Just guessing. The "passing const... as 'this'..." error
indicates you're trying to use the copy constructor on an already
instantiated, const variable? Just guessing. Little time and I'm not a
C++ guru to begin with.
... Clearly I'm swinging in the dark here <:-) I'm working my way slowly
towards understanding everything that's actually going on so I can have
a proper go at this.
In the meantime I wondered if there was a reason const wxString hadn't
been implemented before?
Maybe because something's wrong with how the wxString class behaves wrt.
constness. Not sure.
I grepped and found it in some of the main Wx package .xs files, but
always inside a structure like " %name{Wx::TextCtrlBase} class
wxTextCtrlBase {... " and I don't recognise that syntax /at all/. The Wx
package features strongly when doing a Google Code Search for "%name{".
What is it?
It's a sort of preprocessor directive that's part of the XS++ syntax.
Have a look at the documentation for ExtUtils::XSpp. The ExtUtils::XSpp
also contains a very simple example distribution. Maybe check that out
before you try to understand the much, much more complicated Wx use of
the XS++ preprocessor.
Note that any of the .xsp files you'll find in Wx are meant to be
processed by xspp to produce regular XS. The typemap.xsp is typemap's
XS++ brother.
Until the most recent Wx release, XS++ was part of Wx and it only got
split out recently because it's useful for other C++ bindings as well.
Therefore, Wx has by far the most complicated use of XS++ you'll find.
Cheers,
Steffen