From 61ecd1c87ebc33131a43e04935bdb8fbe4db4196 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Fri, 30 May 2014 18:20:12 -0400 Subject: [PATCH] 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. --- sol/function_types.hpp | 56 ++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/sol/function_types.hpp b/sol/function_types.hpp index 3b5c4158..01b1325b 100644 --- a/sol/function_types.hpp +++ b/sol/function_types.hpp @@ -34,8 +34,10 @@ struct static_function { template static int typed_call(types, types t, function_type* fx, lua_State* L) { - stack::pop_call(L, fx, t); - return 0; + stack::get_call(L, fx, t); + std::ptrdiff_t nargs = sizeof...(Args); + lua_pop(L, nargs); + return 0; } template @@ -46,8 +48,10 @@ struct static_function { template static int typed_call(types, types t, function_type* fx, lua_State* L) { typedef typename return_type::type return_type; - return_type r = stack::pop_call(L, fx, t); - stack::push(L, std::move(r)); + return_type r = stack::get_call(L, fx, t); + std::ptrdiff_t nargs = sizeof...(Args); + lua_pop(L, nargs); + stack::push(L, std::move(r)); return sizeof...(Ret); } @@ -71,8 +75,10 @@ struct static_member_function { template static int typed_call(types, types, T& item, function_type& ifx, lua_State* L) { auto fx = [&item, &ifx](Args&&... args) -> void { (item.*ifx)(std::forward(args)...); }; - stack::pop_call(L, fx, types()); - return 0; + stack::get_call(L, fx, types()); + std::ptrdiff_t nargs = sizeof...(Args); + lua_pop(L, nargs); + return 0; } template @@ -84,8 +90,10 @@ struct static_member_function { static int typed_call(types, types, T& item, function_type& ifx, lua_State* L) { typedef typename return_type::type return_type; auto fx = [&item, &ifx](Args&&... args) -> return_type { return (item.*ifx)(std::forward(args)...); }; - return_type r = stack::pop_call(L, fx, types()); - stack::push(L, std::move(r)); + return_type r = stack::get_call(L, fx, types()); + std::ptrdiff_t nargs = sizeof...(Args); + lua_pop(L, nargs); + stack::push(L, std::move(r)); return sizeof...(Ret); } @@ -162,8 +170,10 @@ struct functor_function : public base_function { template int operator()(types, types t, lua_State* L) { - stack::pop_call(L, fx, t); - return 0; + stack::get_call(L, fx, t); + std::ptrdiff_t nargs = sizeof...(Args); + lua_pop(L, nargs); + return 0; } template @@ -174,8 +184,10 @@ struct functor_function : public base_function { template int operator()(types, types t, lua_State* L) { typedef typename return_type::type return_type; - return_type r = stack::pop_call(L, fx, t); - stack::push(L, r); + return_type r = stack::get_call(L, fx, t); + std::ptrdiff_t nargs = sizeof...(Args); + lua_pop(L, nargs); + stack::push(L, r); return sizeof...(Ret); } @@ -206,7 +218,7 @@ struct member_function : public base_function { template int operator()(types, types t, lua_State* L) { - stack::pop_call(L, fx, t); + stack::get_call(L, fx, t); return 0; } @@ -218,8 +230,10 @@ struct member_function : public base_function { template int operator()(types, types t, lua_State* L) { typedef typename return_type::type return_type; - return_type r = stack::pop_call(L, fx, t); - stack::push(L, std::move(r)); + return_type r = stack::get_call(L, fx, t); + std::ptrdiff_t nargs = sizeof...(Args); + lua_pop(L, nargs); + stack::push(L, std::move(r)); return sizeof...(Ret); } @@ -258,8 +272,10 @@ struct userdata_function : public base_function { template int operator()(types, types t, lua_State* L) { - stack::pop_call(L, fx, t); - return 0; + stack::get_call(L, fx, t); + std::ptrdiff_t nargs = sizeof...(Args); + lua_pop(L, nargs); + return 0; } template @@ -281,8 +297,10 @@ struct userdata_function : public base_function { template int operator()(types, types t, lua_State* L) { typedef typename return_type::type return_type; - return_type r = stack::pop_call(L, fx, t); - // stack::push(L, std::move(r)); + return_type r = stack::get_call(L, fx, t); + std::ptrdiff_t nargs = sizeof...(Args); + lua_pop(L, nargs); + // stack::push(L, std::move(r)); special_push(L, r); return sizeof...(Ret); }