From e70a3c945ed8ee4831bb38e488b4932be379fc27 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 27 May 2015 02:48:07 -0400 Subject: [PATCH] Macro activates the library's default argument checking. Useful to verify during tests and the like. --- sol/stack.hpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/sol/stack.hpp b/sol/stack.hpp index df565cec..ae5d9af8 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -74,6 +74,13 @@ struct return_forward { namespace stack { namespace detail { +const bool default_check_arguments = +#ifdef SOL_CHECK_ARGUMENTS +true; +#else +false; +#endif + template inline int push_userdata_pointer(lua_State* L, Key&& metatablekey) { return push_confirmed_userdata(L, std::forward(metatablekey)); @@ -193,7 +200,7 @@ struct checker { template static bool check (lua_State* L, int index, const Handler& handler) { const type indextype = type_of(L, index); - // Allow nil to be transformed to nullptr + // Allow nil to be transformed to nullptr bool success = expected == indextype || indextype == type::nil; if (!success) { // expected type, actual type @@ -560,7 +567,7 @@ struct check_arguments { } }; -template ::value>::type> +template ::value>::type> inline R call(lua_State* L, int start, indices, types, types ta, Fx&& fx, FxArgs&&... args) { const int stacksize = lua_gettop(L); const int firstargument = start + stacksize - std::max(sizeof...(Args)-1, static_cast(0)); @@ -570,7 +577,7 @@ inline R call(lua_State* L, int start, indices, types, types t return fx(std::forward(args)..., stack::get(L, firstargument + I)...); } -template +template inline void call(lua_State* L, int start, indices, types, types ta, Fx&& fx, FxArgs&&... args) { const int stacksize = lua_gettop(L); const int firstargument = start + stacksize - std::max(sizeof...(Args)-1, static_cast(0)); @@ -583,22 +590,22 @@ inline void call(lua_State* L, int start, indices, types, types::value>::type> +template ::value>::type> inline R call(lua_State* L, int start, types tr, types ta, Fx&& fx, FxArgs&&... args) { return detail::call(L, start, ta, tr, ta, std::forward(fx), std::forward(args)...); } -template ::value>::type> +template ::value>::type> inline R call(lua_State* L, types tr, types ta, Fx&& fx, FxArgs&&... args) { return call(L, 0, ta, tr, ta, std::forward(fx), std::forward(args)...); } -template +template inline void call(lua_State* L, int start, types tr, types ta, Fx&& fx, FxArgs&&... args) { detail::call(L, start, ta, tr, ta, std::forward(fx), std::forward(args)...); } -template +template inline void call(lua_State* L, types tr, types ta, Fx&& fx, FxArgs&&... args) { call(L, 0, ta, tr, ta, std::forward(fx), std::forward(args)...); }