From f8705202e22b637e7bb4ffbaf761254006068e19 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Sun, 6 Nov 2016 16:34:05 -0500 Subject: [PATCH] Update single and update safe usertype checking --- single/sol/sol.hpp | 43 +++++++++++++++------------- sol/call.hpp | 25 +++++++++------- sol/container_usertype_metatable.hpp | 14 ++++----- 3 files changed, 44 insertions(+), 38 deletions(-) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 4b1acbda..b681f7e3 100644 --- a/single/sol/sol.hpp +++ b/single/sol/sol.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2016-11-06 03:40:31.664320 UTC -// This header was generated with sol v2.14.12 (revision 1c73fb0) +// Generated 2016-11-06 21:33:58.899927 UTC +// This header was generated with sol v2.15.0 (revision 34fe8a1) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -7704,10 +7704,11 @@ namespace sol { static int call(lua_State* L, Fx&& f) { typedef std::conditional_t::value, object_type, T> Ta; #ifdef SOL_SAFE_USERTYPE - object_type* o = static_cast(stack::get(L, 1)); - if (o == nullptr) { + auto maybeo = stack::check_get(L, 1); + if (!maybeo || maybeo.value() == nullptr) { return luaL_error(L, "sol: received null for 'self' argument (use ':' for accessing member functions, make sure member variables are preceeded by the actual object with '.' syntax)"); } + object_type* o = static_cast(maybeo.value()); return call(L, std::forward(f), *o); #else object_type& o = static_cast(*stack::get>(L, 1)); @@ -7733,13 +7734,14 @@ namespace sol { static int call_assign(std::true_type, lua_State* L, V&& f) { typedef std::conditional_t::value, object_type, T> Ta; #ifdef SOL_SAFE_USERTYPE - object_type* o = static_cast(stack::get(L, 1)); - if (o == nullptr) { + auto maybeo = stack::check_get(L, 1); + if (!maybeo || maybeo.value() == nullptr) { if (is_variable) { return luaL_error(L, "sol: received nil for 'self' argument (bad '.' access?)"); } return luaL_error(L, "sol: received nil for 'self' argument (pass 'self' as first argument)"); } + object_type* o = static_cast(maybeo.value()); return call_assign(std::true_type(), L, f, *o); #else object_type& o = static_cast(*stack::get>(L, 1)); @@ -7791,13 +7793,14 @@ namespace sol { static int call(lua_State* L, V&& f) { typedef std::conditional_t::value, object_type, T> Ta; #ifdef SOL_SAFE_USERTYPE - object_type* o = static_cast(stack::get(L, 1)); - if (o == nullptr) { + auto maybeo = stack::check_get(L, 1); + if (!maybeo || maybeo.value() == nullptr) { if (is_variable) { return luaL_error(L, "sol: 'self' argument is nil (bad '.' access?)"); } return luaL_error(L, "sol: 'self' argument is nil (pass 'self' as first argument)"); } + object_type* o = static_cast(maybeo.value()); return call(L, f, *o); #else object_type& o = static_cast(*stack::get>(L, 1)); @@ -7943,20 +7946,20 @@ namespace sol { typedef meta::pop_front_type_t args_list; typedef T Ta; #ifdef SOL_SAFE_USERTYPE - object_type* po = static_cast(stack::get(L, 1)); - if (po == nullptr) { + auto maybeo = stack::check_get(L, 1); + if (!maybeo || maybeo.value() == nullptr) { if (is_variable) { return luaL_error(L, "sol: 'self' argument is nil (bad '.' access?)"); } return luaL_error(L, "sol: 'self' argument is nil (pass 'self' as first argument)"); } - object_type& o = *po; + object_type* o = static_cast(maybeo.value()); #else - object_type& o = static_cast(*stack::get>(L, 1)); + object_type* o = static_cast(stack::get>(L, 1)); #endif // Safety typedef typename wrap::returns_list returns_list; typedef typename wrap::caller caller; - return stack::call_into_lua(returns_list(), args_list(), L, boost + (is_variable ? 3 : 2), caller(), f, o); + return stack::call_into_lua(returns_list(), args_list(), L, boost + (is_variable ? 3 : 2), caller(), f, *o); } template @@ -10953,11 +10956,11 @@ namespace sol { static auto& get_src(lua_State* L) { #ifdef SOL_SAFE_USERTYPE - auto p = stack::get(L, 1); - if (p == nullptr) { - luaL_error(L, "sol: 'self' argument is nil (pass 'self' as first argument or call on proper type)"); + auto p = stack::check_get(L, 1); + if (!p || p.value() == nullptr) { + luaL_error(L, "sol: 'self' argument is not the proper type (pass 'self' as first argument with ':' or call on proper type)"); } - return *p; + return *p.value(); #else return stack::get(L, 1); #endif @@ -11137,11 +11140,11 @@ namespace sol { static auto& get_src(lua_State* L) { #ifdef SOL_SAFE_USERTYPE - auto p = stack::get(L, 1); - if (p == nullptr) { + auto p = stack::check_get(L, 1); + if (!p || p.value() == nullptr) { luaL_error(L, "sol: 'self' argument is nil (pass 'self' as first argument or call on proper type)"); } - return *p; + return *p.value(); #else return stack::get(L, 1); #endif diff --git a/sol/call.hpp b/sol/call.hpp index 9f6a3af8..ac5f67e7 100644 --- a/sol/call.hpp +++ b/sol/call.hpp @@ -276,10 +276,11 @@ namespace sol { static int call(lua_State* L, Fx&& f) { typedef std::conditional_t::value, object_type, T> Ta; #ifdef SOL_SAFE_USERTYPE - object_type* o = static_cast(stack::get(L, 1)); - if (o == nullptr) { + auto maybeo = stack::check_get(L, 1); + if (!maybeo || maybeo.value() == nullptr) { return luaL_error(L, "sol: received null for 'self' argument (use ':' for accessing member functions, make sure member variables are preceeded by the actual object with '.' syntax)"); } + object_type* o = static_cast(maybeo.value()); return call(L, std::forward(f), *o); #else object_type& o = static_cast(*stack::get>(L, 1)); @@ -305,13 +306,14 @@ namespace sol { static int call_assign(std::true_type, lua_State* L, V&& f) { typedef std::conditional_t::value, object_type, T> Ta; #ifdef SOL_SAFE_USERTYPE - object_type* o = static_cast(stack::get(L, 1)); - if (o == nullptr) { + auto maybeo = stack::check_get(L, 1); + if (!maybeo || maybeo.value() == nullptr) { if (is_variable) { return luaL_error(L, "sol: received nil for 'self' argument (bad '.' access?)"); } return luaL_error(L, "sol: received nil for 'self' argument (pass 'self' as first argument)"); } + object_type* o = static_cast(maybeo.value()); return call_assign(std::true_type(), L, f, *o); #else object_type& o = static_cast(*stack::get>(L, 1)); @@ -363,13 +365,14 @@ namespace sol { static int call(lua_State* L, V&& f) { typedef std::conditional_t::value, object_type, T> Ta; #ifdef SOL_SAFE_USERTYPE - object_type* o = static_cast(stack::get(L, 1)); - if (o == nullptr) { + auto maybeo = stack::check_get(L, 1); + if (!maybeo || maybeo.value() == nullptr) { if (is_variable) { return luaL_error(L, "sol: 'self' argument is nil (bad '.' access?)"); } return luaL_error(L, "sol: 'self' argument is nil (pass 'self' as first argument)"); } + object_type* o = static_cast(maybeo.value()); return call(L, f, *o); #else object_type& o = static_cast(*stack::get>(L, 1)); @@ -515,20 +518,20 @@ namespace sol { typedef meta::pop_front_type_t args_list; typedef T Ta; #ifdef SOL_SAFE_USERTYPE - object_type* po = static_cast(stack::get(L, 1)); - if (po == nullptr) { + auto maybeo = stack::check_get(L, 1); + if (!maybeo || maybeo.value() == nullptr) { if (is_variable) { return luaL_error(L, "sol: 'self' argument is nil (bad '.' access?)"); } return luaL_error(L, "sol: 'self' argument is nil (pass 'self' as first argument)"); } - object_type& o = *po; + object_type* o = static_cast(maybeo.value()); #else - object_type& o = static_cast(*stack::get>(L, 1)); + object_type* o = static_cast(stack::get>(L, 1)); #endif // Safety typedef typename wrap::returns_list returns_list; typedef typename wrap::caller caller; - return stack::call_into_lua(returns_list(), args_list(), L, boost + (is_variable ? 3 : 2), caller(), f, o); + return stack::call_into_lua(returns_list(), args_list(), L, boost + (is_variable ? 3 : 2), caller(), f, *o); } template diff --git a/sol/container_usertype_metatable.hpp b/sol/container_usertype_metatable.hpp index 268f8db1..2cbc97f0 100644 --- a/sol/container_usertype_metatable.hpp +++ b/sol/container_usertype_metatable.hpp @@ -97,11 +97,11 @@ namespace sol { static auto& get_src(lua_State* L) { #ifdef SOL_SAFE_USERTYPE - auto p = stack::get(L, 1); - if (p == nullptr) { - luaL_error(L, "sol: 'self' argument is nil (pass 'self' as first argument or call on proper type)"); + auto p = stack::check_get(L, 1); + if (!p || p.value() == nullptr) { + luaL_error(L, "sol: 'self' argument is not the proper type (pass 'self' as first argument with ':' or call on proper type)"); } - return *p; + return *p.value(); #else return stack::get(L, 1); #endif @@ -281,11 +281,11 @@ namespace sol { static auto& get_src(lua_State* L) { #ifdef SOL_SAFE_USERTYPE - auto p = stack::get(L, 1); - if (p == nullptr) { + auto p = stack::check_get(L, 1); + if (!p || p.value() == nullptr) { luaL_error(L, "sol: 'self' argument is nil (pass 'self' as first argument or call on proper type)"); } - return *p; + return *p.value(); #else return stack::get(L, 1); #endif