lua-users home
lua-l archive

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



On Fri, Jun 22, 2012 at 7:39 PM, William Ahern <william@25thandclement.com> wrote:
You can do it for a limited number of arguments and without compound type by
defining a huge map of function pointers. I'm not sure what the equation is,
but obviously the permutations grow quickly.

Intuitively, though, I think it should be practical for 3 or 4 parameters.
Given the integer promotions rules (you don't need to worry about char or
short), and assuming that a void pointer parameter signature can stand in
for any object pointer (likely on most platforms), then it's not too far
fetched. Just really frustrating when the caller wants to pass that one
extra parameter which can't be supported. The argument limit would seem
completely arbitrary from the user's perspective.

Floats, doubles, complex floats, complex doubles, integers/pointers, int64 (for 32bit), and the various SSE vectors (which I haven't even touched yet) are all different categories. 3 or 4 params + return gives you an extreme number of combinations. Also for returns the different sizes and signed/unsigned have to be all treated specially as C code does not unset the higher bits (for x86).

Also callbacks require a closure, which means you are copying a compiled chunk and then searching and replacing a magic value.

At the moment the JITed code in luaffi is quite clean. The slow part is due to the calls in C to unmarshal everything, where the simpler ones need to be inlined.

It will never be as fast as the lua C API (unless it bypasses that and looks into the VM directly), but should get close enough for reasonable use. The intended use case isn't for speed though. If you want speed use luajit. The usefulness of the ffi API is that it is very easy and quick to get going.

-- James