Re: [Vala] Generating bindings for non-GLib/GObject based API

On Sun, Apr 25, 2010 at 11:46:17 +0200, Michael Wild wrote:
On 23. Apr, 2010, at 22:29 , Jan Hudec wrote:
Actually I believe

   [CCode (cname = "void", ...)]
   class Thing ...

should work. It will give you void * passed around, so it's some kind of
pointer and C implicitly casts to and from void *, so no errors and no

I don't think that I'd like that one particularly... I'd rather prefer to
use a Vala wrapper class then.

You can also just make it

   [CCode (cname = "struct unknown_type", ...)]
   class Thing ...

with the real value for "unknown_type" from the library header. That will
make the code more type-safe on the C side, but vala will check the types
enough and it would be relying on something not officially documented.

Unfortunately that's impossible. The official standard states that there is
a opaque type Thing, but nothing more. Every implementor is free to do as
he pleases... Some even typedef it to an integer handle.

The void case would be OK if you knew it is always a pointer. But if it's
a handle of any type, than you'll have to make it a "[SimpleType] struct"
(SimpleType means it's passed by value).

Than you can try whether setting a copy_function and destroy_function on
a simple type will do what you need and otherwise you'll just have to wrap
it in a normal vala object.

                                                 Jan 'Bulb' Hudec <bulb ucw cz>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]