Bug with pop_call when concerning certain argument orders. Popping of the end of the stack was too dangerous, so instead we use a get call and pop all stack arguments off afterwards: helps to preserve order.

This commit is contained in:
ThePhD 2014-05-30 18:20:12 -04:00
parent fb1eb21f34
commit 61ecd1c87e

View File

@ -34,8 +34,10 @@ struct static_function {
template<typename... Args> template<typename... Args>
static int typed_call(types<void>, types<Args...> t, function_type* fx, lua_State* L) { static int typed_call(types<void>, types<Args...> t, function_type* fx, lua_State* L) {
stack::pop_call(L, fx, t); stack::get_call(L, fx, t);
return 0; std::ptrdiff_t nargs = sizeof...(Args);
lua_pop(L, nargs);
return 0;
} }
template<typename... Args> template<typename... Args>
@ -46,8 +48,10 @@ struct static_function {
template<typename... Ret, typename... Args> template<typename... Ret, typename... Args>
static int typed_call(types<Ret...>, types<Args...> t, function_type* fx, lua_State* L) { static int typed_call(types<Ret...>, types<Args...> t, function_type* fx, lua_State* L) {
typedef typename return_type<Ret...>::type return_type; typedef typename return_type<Ret...>::type return_type;
return_type r = stack::pop_call(L, fx, t); return_type r = stack::get_call(L, fx, t);
stack::push(L, std::move(r)); std::ptrdiff_t nargs = sizeof...(Args);
lua_pop(L, nargs);
stack::push(L, std::move(r));
return sizeof...(Ret); return sizeof...(Ret);
} }
@ -71,8 +75,10 @@ struct static_member_function {
template<typename... Args> template<typename... Args>
static int typed_call(types<void>, types<Args...>, T& item, function_type& ifx, lua_State* L) { static int typed_call(types<void>, types<Args...>, T& item, function_type& ifx, lua_State* L) {
auto fx = [&item, &ifx](Args&&... args) -> void { (item.*ifx)(std::forward<Args>(args)...); }; auto fx = [&item, &ifx](Args&&... args) -> void { (item.*ifx)(std::forward<Args>(args)...); };
stack::pop_call(L, fx, types<Args...>()); stack::get_call(L, fx, types<Args...>());
return 0; std::ptrdiff_t nargs = sizeof...(Args);
lua_pop(L, nargs);
return 0;
} }
template<typename... Args> template<typename... Args>
@ -84,8 +90,10 @@ struct static_member_function {
static int typed_call(types<Ret...>, types<Args...>, T& item, function_type& ifx, lua_State* L) { static int typed_call(types<Ret...>, types<Args...>, T& item, function_type& ifx, lua_State* L) {
typedef typename return_type<Ret...>::type return_type; typedef typename return_type<Ret...>::type return_type;
auto fx = [&item, &ifx](Args&&... args) -> return_type { return (item.*ifx)(std::forward<Args>(args)...); }; auto fx = [&item, &ifx](Args&&... args) -> return_type { return (item.*ifx)(std::forward<Args>(args)...); };
return_type r = stack::pop_call(L, fx, types<Args...>()); return_type r = stack::get_call(L, fx, types<Args...>());
stack::push(L, std::move(r)); std::ptrdiff_t nargs = sizeof...(Args);
lua_pop(L, nargs);
stack::push(L, std::move(r));
return sizeof...(Ret); return sizeof...(Ret);
} }
@ -162,8 +170,10 @@ struct functor_function : public base_function {
template<typename... Args> template<typename... Args>
int operator()(types<void>, types<Args...> t, lua_State* L) { int operator()(types<void>, types<Args...> t, lua_State* L) {
stack::pop_call(L, fx, t); stack::get_call(L, fx, t);
return 0; std::ptrdiff_t nargs = sizeof...(Args);
lua_pop(L, nargs);
return 0;
} }
template<typename... Args> template<typename... Args>
@ -174,8 +184,10 @@ struct functor_function : public base_function {
template<typename... Ret, typename... Args> template<typename... Ret, typename... Args>
int operator()(types<Ret...>, types<Args...> t, lua_State* L) { int operator()(types<Ret...>, types<Args...> t, lua_State* L) {
typedef typename return_type<Ret...>::type return_type; typedef typename return_type<Ret...>::type return_type;
return_type r = stack::pop_call(L, fx, t); return_type r = stack::get_call(L, fx, t);
stack::push(L, r); std::ptrdiff_t nargs = sizeof...(Args);
lua_pop(L, nargs);
stack::push(L, r);
return sizeof...(Ret); return sizeof...(Ret);
} }
@ -206,7 +218,7 @@ struct member_function : public base_function {
template<typename... Args> template<typename... Args>
int operator()(types<void>, types<Args...> t, lua_State* L) { int operator()(types<void>, types<Args...> t, lua_State* L) {
stack::pop_call(L, fx, t); stack::get_call(L, fx, t);
return 0; return 0;
} }
@ -218,8 +230,10 @@ struct member_function : public base_function {
template<typename... Ret, typename... Args> template<typename... Ret, typename... Args>
int operator()(types<Ret...>, types<Args...> t, lua_State* L) { int operator()(types<Ret...>, types<Args...> t, lua_State* L) {
typedef typename return_type<Ret...>::type return_type; typedef typename return_type<Ret...>::type return_type;
return_type r = stack::pop_call(L, fx, t); return_type r = stack::get_call(L, fx, t);
stack::push(L, std::move(r)); std::ptrdiff_t nargs = sizeof...(Args);
lua_pop(L, nargs);
stack::push(L, std::move(r));
return sizeof...(Ret); return sizeof...(Ret);
} }
@ -258,8 +272,10 @@ struct userdata_function : public base_function {
template<typename... Args> template<typename... Args>
int operator()(types<void>, types<Args...> t, lua_State* L) { int operator()(types<void>, types<Args...> t, lua_State* L) {
stack::pop_call(L, fx, t); stack::get_call(L, fx, t);
return 0; std::ptrdiff_t nargs = sizeof...(Args);
lua_pop(L, nargs);
return 0;
} }
template<typename... Args> template<typename... Args>
@ -281,8 +297,10 @@ struct userdata_function : public base_function {
template<typename... Ret, typename... Args> template<typename... Ret, typename... Args>
int operator()(types<Ret...>, types<Args...> t, lua_State* L) { int operator()(types<Ret...>, types<Args...> t, lua_State* L) {
typedef typename return_type<Ret...>::type return_type; typedef typename return_type<Ret...>::type return_type;
return_type r = stack::pop_call(L, fx, t); return_type r = stack::get_call(L, fx, t);
// stack::push(L, std::move(r)); std::ptrdiff_t nargs = sizeof...(Args);
lua_pop(L, nargs);
// stack::push(L, std::move(r));
special_push(L, r); special_push(L, r);
return sizeof...(Ret); return sizeof...(Ret);
} }