From b7b81c1297fbf56cf066951fd60192e62bd7a9b5 Mon Sep 17 00:00:00 2001 From: Daniel Wallin Date: Tue, 2 Sep 2008 23:25:05 +0200 Subject: [PATCH] Fixes #66. Adds support for __stdcall on MSVC. This is a rework of the original patch by Dave Hawkes . There's room to add more calling conventions if necessary, but it's harder than it should be. This file really needs to be refactored to get rid of some of the repetition. --- luabind/function.hpp | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/luabind/function.hpp b/luabind/function.hpp index 9b1a297..f944c36 100644 --- a/luabind/function.hpp +++ b/luabind/function.hpp @@ -142,20 +142,46 @@ namespace luabind template struct returns { + #define LUABIND_CC #define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, , 2)) #include BOOST_PP_ITERATE() + #undef LUABIND_CC + + #ifdef BOOST_MSVC + # define LUABIND_CC __stdcall + # define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, , 2)) + # include BOOST_PP_ITERATE() + # undef LUABIND_CC + #endif }; template<> struct returns { + #define LUABIND_CC #define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, , 3)) #include BOOST_PP_ITERATE() + #undef LUABIND_CC + + #ifdef BOOST_MSVC + # define LUABIND_CC __stdcall + # define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, , 3)) + # include BOOST_PP_ITERATE() + # undef LUABIND_CC + #endif }; + #define LUABIND_CC #define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, , 4)) #include BOOST_PP_ITERATE() + #undef LUABIND_CC + #ifdef BOOST_MSVC + # define LUABIND_CC __stdcall + # define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, , 4)) + # include BOOST_PP_ITERATE() + # undef LUABIND_CC + #endif #undef LUABIND_PARAMS #undef LUABIND_DECL @@ -163,10 +189,17 @@ namespace luabind #undef LUABIND_ADD_INDEX #undef LUABIND_INDEX_MAP - + #define LUABIND_CC #define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, , 5)) #include BOOST_PP_ITERATE() + #undef LUABIND_CC + #ifdef BOOST_MSVC + # define LUABIND_CC __stdcall + # define BOOST_PP_ITERATION_PARAMS_1 (4, (0, LUABIND_MAX_ARITY, , 5)) + # include BOOST_PP_ITERATE() + # undef LUABIND_CC + #endif template struct function_callback_s @@ -319,7 +352,7 @@ namespace luabind #define LUABIND_ARITY(z,n,text) + BOOST_PP_CAT(p,n)::has_arg template -overload_rep(R(*f)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), Policies*) +overload_rep(R(LUABIND_CC *f)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), Policies*) : fun(reinterpret_cast(f)) { m_params_.reserve(BOOST_PP_ITERATION()); @@ -336,7 +369,7 @@ overload_rep(R(*f)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), Policies*) #elif BOOST_PP_ITERATION_FLAGS() == 2 template -static int call(T(*f)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), lua_State* L, const Policies*) +static int call(T(LUABIND_CC *f)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), lua_State* L, const Policies*) { int nargs = lua_gettop(L); @@ -369,7 +402,7 @@ static int call(T(*f)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), lua_State* #elif BOOST_PP_ITERATION_FLAGS() == 3 template -static int call(void(*f)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), lua_State* L, const Policies*) +static int call(void(LUABIND_CC *f)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), lua_State* L, const Policies*) { int nargs = lua_gettop(L); @@ -398,7 +431,7 @@ static int call(void(*f)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), lua_Sta #elif BOOST_PP_ITERATION_FLAGS() == 4 template -int call(R(*f)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), lua_State* L, const Policies* policies) +int call(R(LUABIND_CC *f)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), lua_State* L, const Policies* policies) { return free_functions::returns::call(f, L, policies); } @@ -406,7 +439,7 @@ int call(R(*f)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), lua_State* L, con #elif BOOST_PP_ITERATION_FLAGS() == 5 template - static int match(R(*)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), lua_State* L, const Policies* policies) + static int match(R(LUABIND_CC *)(BOOST_PP_ENUM_PARAMS(BOOST_PP_ITERATION(), A)), lua_State* L, const Policies* policies) { //if (lua_gettop(L) != BOOST_PP_ITERATION()) return -1; typedef constructor ParameterTypes; -- 2.11.4.GIT