lua-users home
lua-l archive

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

On Wed, Jan 26, 2011 at 4:25 PM, David Given <> wrote:
> (I was also rather hoping you'd have a
> cunning way of detecting fastcall. I hate x86.)

Though not applicable to the FFI, my approach to detecting
cdecl/stdcall/fastcall is to find a function in the API which takes 1
or 2 parameters, and then call it via a special assembly stub which
puts one set of values in the fastcall registers, and a different set
of values on the stack, then check for a difference in stack pointer
to detect stdcall, and externally observe the behavioural difference
between the fastcall values and the cdecl/stdcall values to detect
fastcall. For example, given a Lua API with unknown calling
convention, call lua_settop in way that sets the top to 1 if it was
fastcall, or 0 if it was stdcall/cdecl, then call lua_gettop to detect
whether it was fastcall.