lua-users home
lua-l archive

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


David Given wrote:
> On 26/01/11 13:05, Mike Pall wrote:
> > Neither should be a problem for the LuaJIT FFI. The import stubs
> > are not needed and __stdcall is automatically detected. So just
> > omit any calling convention in the declaration and the FFI will
> > figure it out for you.
> 
> Gosh --- how?

The LuaJIT interpreter employs an assembler helper to call
C functions via the FFI. It remembers the stack pointer before the
call and simply restores it after the call. This allows calling
both __cdecl and __stdcall functions from the same code.

If a difference between the stack pointers before and after the
call is detected, then it must have been a stdcall. This causes
the function declaration to be fixed up. The JIT compiler can
later use this info to inline the call with the correct calling
convention.

--Mike