diff options
Diffstat (limited to '3rdparty/sol2/sol/stack_check.hpp')
-rw-r--r-- | 3rdparty/sol2/sol/stack_check.hpp | 65 |
1 files changed, 48 insertions, 17 deletions
diff --git a/3rdparty/sol2/sol/stack_check.hpp b/3rdparty/sol2/sol/stack_check.hpp index bf9faa1ed52..5a8610f270a 100644 --- a/3rdparty/sol2/sol/stack_check.hpp +++ b/3rdparty/sol2/sol/stack_check.hpp @@ -34,7 +34,7 @@ namespace sol { namespace stack_detail { template <typename T, bool poptable = true> inline bool check_metatable(lua_State* L, int index = -2) { - const auto& metakey = usertype_traits<T>::metatable; + const auto& metakey = usertype_traits<T>::metatable(); luaL_getmetatable(L, &metakey[0]); const type expectedmetatabletype = static_cast<type>(lua_type(L, -1)); if (expectedmetatabletype != type::nil) { @@ -77,6 +77,34 @@ namespace sol { } }; + template<typename T> + struct checker<T, type::number, std::enable_if_t<std::is_integral<T>::value>> { + template <typename Handler> + static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { + tracking.use(1); + bool success = lua_isinteger(L, index) == 1; + if (!success) { + // expected type, actual type + handler(L, index, type::number, type_of(L, index)); + } + return success; + } + }; + + template<typename T> + struct checker<T, type::number, std::enable_if_t<std::is_floating_point<T>::value>> { + template <typename Handler> + static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { + tracking.use(1); + bool success = lua_isnumber(L, index) == 1; + if (!success) { + // expected type, actual type + handler(L, index, type::number, type_of(L, index)); + } + return success; + } + }; + template <type expected, typename C> struct checker<nil_t, expected, C> { template <typename Handler> @@ -239,21 +267,7 @@ namespace sol { }; template <typename T, typename C> - struct checker<T*, type::userdata, C> { - template <typename Handler> - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - const type indextype = type_of(L, index); - // Allow nil to be transformed to nullptr - if (indextype == type::nil) { - tracking.use(1); - return true; - } - return checker<meta::unqualified_t<T>, type::userdata, C>{}.check(types<meta::unqualified_t<T>>(), L, indextype, index, std::forward<Handler>(handler), tracking); - } - }; - - template <typename T, typename C> - struct checker<T, type::userdata, C> { + struct checker<detail::as_value_tag<T>, type::userdata, C> { template <typename U, typename Handler> static bool check(types<U>, lua_State* L, type indextype, int index, Handler&& handler, record& tracking) { tracking.use(1); @@ -292,11 +306,28 @@ namespace sol { lua_pop(L, 1); return true; } + }; + + template <typename T, typename C> + struct checker<T, type::userdata, C> { + template <typename Handler> + static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { + const type indextype = type_of(L, index); + return checker<detail::as_value_tag<T>, type::userdata, C>{}.check(types<T>(), L, indextype, index, std::forward<Handler>(handler), tracking); + } + }; + template <typename T, typename C> + struct checker<T*, type::userdata, C> { template <typename Handler> static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { const type indextype = type_of(L, index); - return check(types<T>(), L, indextype, index, std::forward<Handler>(handler), tracking); + // Allow nil to be transformed to nullptr + if (indextype == type::nil) { + tracking.use(1); + return true; + } + return checker<meta::unqualified_t<T>, type::userdata, C>{}.check(L, index, std::forward<Handler>(handler), tracking); } }; |