[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: LuaJIT FFI callbacks (was Re: Calling lua functions from C when using luajit ffi.)
- From: Mike Pall <mikelu-1111@...>
- Date: Tue, 15 Nov 2011 17:07:39 +0100
Tim Caswell wrote:
> Well, it seems this works for most callbacks, but not all. In the
> docs I see it says it doesn't work with "functions with pass-by-value
> aggregate argument or result types". I'm not sure what that means.
Structs, unions, vectors and complex numbers are aggregates.
Pass-by-value semantics means passing or returning the value of
such an aggregate, i.e. copying the whole contents. This is
opposed to pass-by-reference, where you pass or return a pointer
to an aggregate.
[There are certain, limited use cases for pass-by-value structs.
Whether using this for public facing APIs is a good idea or not is
a topic of hot debate. The views differ wildly between the C and
the C++ communities, too. But this is very off-topic here.
Maybe I should just mention, that this is a weak spot in most ABI
definitions and it causes lots of implementation problems for
compilers ...]
> My function signature is:
>
> typedef uv_buf_t (*uv_alloc_cb)(uv_handle_t* handle, size_t suggested_size);
>
> When it tries to convert a lua function to this I get:
>
> /home/tim/luvit/examples/uvffi/uv.lua:46: bad argument #2 to
> 'uv_read_start' (cannot convert 'function' to 'struct 2967 (*)()')
>
> Am I doing something wrong, or is this kind of function not supported?
uv_buf_t, aka 'struct 2967' is an aggregate. Sorry, but that's not
a supported result type for a callback function.
--Mike