lua-users home
lua-l archive

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


An update:
The good. I've added support for the following:
- fastcall
- variable length arrays and structs
- auto allocating structs from a table constructor for functions that
take a struct*
- callbacks

The bad:
- 64bit support is broken. It was actually broken before, but you
would only hit it if your allocator returned pointers > 4GB.

The callbacks are done by jitting an appropriate stub whose lifetime
is tied to the lua function. Also its currently hard coded to use the
lua_State that was present when the lua function was converted to a
function pointer.

It supports the three x86 calling conventions, but you will have to
annotate the type with the appropriate convention for stdcall and
fastcall (__stdcall, __fastcall) as this can't be auto-determined.

Also vararg callbacks aren't supported and never will be as there
isn't enough information to figure out how to push the arguments into
lua.

The combo with creating structs as needed makes for some interesting
possibilities:

ffi.cdef [[
struct fptr {
    int (*p)(int);
};
int call_fptr(struct fptr* s, int val);
]]

local mul = 3
assert(c.call_fptr({function(a) return mul*a end}, 5) == 15)

-- James