lua-users home
lua-l archive

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


__declspec(naked) is not what you want. You just gotta make sure you
compile with the same calling convention you biult your Lua binaries
with. Personally, on Windows I use stdcall. Anyway, you can't register a
C++ class member function (unless it's static) since there's an implicit
this parameter.

-----Original Message-----
From: simon [mailto:simonhaines@yahoo.com.au] 
Sent: Thursday, February 21, 2002 7:09 PM
To: Multiple recipients of list
Subject: Registering C functions in C++ (Win32)


Howdy,

I'm having a few problems getting around MSVC calling conventions when
registering a function with lua.

For example, in a c++ program, the function
int test(lua_State *L);
is internally translated to int (__cdecl)(struct
lua_State *).

You can turn off the __cdecl definition by
substituting the macro __declspec(naked), but that
imposes the restriction of not being able to return a
value (such as int, which is required).

Anybody hurdled this one in MSVC++? I'd like to keep
function call safety in the linker. The complete
compiler error message is:
error C2664: 'lua_pushcclosure' : cannot convert
parameter 2 from 'int (struct lua_State *)' to 'int
(__cdecl *)(struct lua_State *)'

It's a member function, being registered in a
constructor.

Thanks and regards,
Simon Haines

http://movies.yahoo.com.au - Yahoo! Movies
- Vote for your nominees in our online Oscars pool.