Re: opaque pointers and metatype

  • From: Richard Hundt <richardhundt@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Sun, 02 Mar 2014 14:05:34 +0100

On 3/2/14 3:39 AM, Cosmin Apreutesei wrote:
> Hi,
>
> What do you guys do when you have to use metatype on opaque pointers?
>
> Take the following example:
>
>    struct OpaqueStruct * handle;
You should be able to:

ffi.cdef[[
    typedef struct OpaqueStruct_ OpaqueStruct_t;
    void create(OpaqueStruct_t*);
    void destroy(OpaqueStruct_t*);
]]

now you can just say:

local handle = ffi.new('OpaqueStruct_t')
ffi.C.create(handle)
ffi.C.destroy(handle)

I did something similar with czmq, the main difference was that
`zctx_new` actually returns a `void*`, but should work in your case
(haven't tested it).

-R

Other related posts: