Re: opaque pointers and metatype

  • From: Cosmin Apreutesei <cosmin.apreutesei@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Tue, 4 Mar 2014 00:55:24 +0200

>> Yet another alternative is to make a type for void* like this:
>>
>>    typedef {void *p;} some_type;
> Yep, but that means you needs to pass `self.p` around when delegating to
> C functions from a method on your metatable. Which brings me back to my
> original point. You don't really need to box it.

You don't have to pass self.p, because you can pass some_type directly
where some_type* is expected and the ffi will pass the address of that
some_type. This works if some_type is an aggregate type (struct or
array) and doesn't work if it's a scalar type (pointer or number).

Other related posts: