On 09/01/2012 06:23 AM, Trung Ngo wrote:
> Hi,
> I'm trying to interface my vala code with a C++ library that makes use
> of Glib::ustring for UTF-8 support. Is there any way to convert
> glibmm's Glib::ustring to Vala's string?
Most of the time, strings in GLib are simply C strings that happen to be
UTF-8 encoded. The C type you'll want to use is const gchar* (which is
identical to const char*)
Example C++ code:
////////////////////////////////////
extern Glib::ustring my_str;
extern "C"
const gchar *
get_my_str ()
{
return my_str.c_str();
}
////////////////////////////////////
This should work as a function declaration in your VAPI file:
////////////////////////////////////
[CCode (cheader_filename = "stringfunc.h")]
public string get_my_str ();
////////////////////////////////////
NB: As JM said, Vala doesn't interface with C++ code particularly well.
If your library is object-oriented, you'll have to create a fair bit of
wrapper code to expose a clean C interface (ideally using GObject/GType)
that you can then access from Vala.
Ideally, one would want to use SWIG and/or GObject-Introspection to do
the heavy lifting, but as far as I can tell, Glibmm doesn't support
GObject-Introspection, and SWIG doesn't support generating C/GObject
bindings.
Cheers
Thomas
_______________________________________________
vala-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/vala-list