From 796fd6903e360f9ee223fe96a12b8f3c1bf21e73 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Thu, 28 Nov 2013 18:27:27 -0500 Subject: [PATCH] Switched pop to get and wrote a new pop function --- sol/stack.hpp | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/sol/stack.hpp b/sol/stack.hpp index 86d1e736..35fb4112 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -30,37 +30,37 @@ namespace sol { namespace stack { namespace detail { template -inline T pop_unsigned(lua_State* L, std::true_type) { +inline T get_unsigned(lua_State* L, std::true_type) { return lua_tounsigned(L, -1); } template -inline T pop_unsigned(lua_State* L, std::false_type) { +inline T get_unsigned(lua_State* L, std::false_type) { return lua_tointeger(L, -1); } template -inline T pop_arithmetic(lua_State* L, std::false_type) { +inline T get_arithmetic(lua_State* L, std::false_type) { // T is a floating point return lua_tonumber(L, -1); } template -inline T pop_arithmetic(lua_State* L, std::true_type) { +inline T get_arithmetic(lua_State* L, std::true_type) { // T is an integral - return pop_unsigned(L, std::is_unsigned{}); + return get_unsigned(L, std::is_unsigned{}); } template -inline T pop_helper(lua_State* L, std::true_type) { +inline T get_helper(lua_State* L, std::true_type) { // T is a class type return T(L, -1); } template -inline T pop_helper(lua_State* L, std::false_type) { +inline T get_helper(lua_State* L, std::false_type) { // T is a fundamental type - return pop_arithmetic(L, std::is_integral{}); + return get_arithmetic(L, std::is_integral{}); } template @@ -87,32 +87,32 @@ inline void push_arithmetic(lua_State* L, T x, std::false_type) { } // detail template -inline T pop(lua_State* L) { - auto result = detail::pop_helper(L, std::is_class{}); - lua_pop(L, 1); - return result; +inline T get(lua_State* L) { + return detail::get_helper(L, std::is_class{}); } template<> -inline bool pop(lua_State* L) { - bool result = lua_toboolean(L, -1) != 0; - lua_pop(L, 1); - return result; +inline bool get(lua_State* L) { + return lua_toboolean(L, -1) != 0; } template<> -inline std::string pop(lua_State* L) { +inline std::string get(lua_State* L) { std::string::size_type len; auto str = lua_tolstring(L, -1, &len); - lua_pop(L, 1); return { str, len }; } template<> -inline const char* pop(lua_State* L) { - auto result = lua_tostring(L, -1); +inline const char* get(lua_State* L) { + return lua_tostring(L, -1); +} + +template +inline T pop(lua_State* L) { + auto r = get(L); lua_pop(L, 1); - return result; + return r; } template