Some derps on the compatibility arguments

checkargs is now properly propogated through the "call" functions
tests now define SOL_CHECK_ARGUMENTS to make sure
the tests will always check arguments now as well (caught one minor implementation detail missing from that!)
This commit is contained in:
ThePhD 2015-06-17 18:33:58 -04:00
parent 8ff921a247
commit ffcd1f557b
5 changed files with 21 additions and 41 deletions

View File

@ -24,7 +24,7 @@
#include "version.hpp" #include "version.hpp"
#if SOL_LUA_VERSION < 520 #if SOL_LUA_VERSION < 502
#define LUA_RIDX_GLOBALS LUA_GLOBALSINDEX #define LUA_RIDX_GLOBALS LUA_GLOBALSINDEX

View File

@ -592,22 +592,22 @@ inline void call(lua_State* L, int start, indices<I...>, types<void>, types<Args
template <bool checkargs = detail::default_check_arguments, typename R, typename... Args, typename Fx, typename... FxArgs, typename = typename std::enable_if<!std::is_void<R>::value>::type> template <bool checkargs = detail::default_check_arguments, typename R, typename... Args, typename Fx, typename... FxArgs, typename = typename std::enable_if<!std::is_void<R>::value>::type>
inline R call(lua_State* L, int start, types<R> tr, types<Args...> ta, Fx&& fx, FxArgs&&... args) { inline R call(lua_State* L, int start, types<R> tr, types<Args...> ta, Fx&& fx, FxArgs&&... args) {
return detail::call(L, start, ta, tr, ta, std::forward<Fx>(fx), std::forward<FxArgs>(args)...); return detail::call<checkargs>(L, start, ta, tr, ta, std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
} }
template <bool checkargs = detail::default_check_arguments, typename R, typename... Args, typename Fx, typename... FxArgs, typename = typename std::enable_if<!std::is_void<R>::value>::type> template <bool checkargs = detail::default_check_arguments, typename R, typename... Args, typename Fx, typename... FxArgs, typename = typename std::enable_if<!std::is_void<R>::value>::type>
inline R call(lua_State* L, types<R> tr, types<Args...> ta, Fx&& fx, FxArgs&&... args) { inline R call(lua_State* L, types<R> tr, types<Args...> ta, Fx&& fx, FxArgs&&... args) {
return call(L, 0, ta, tr, ta, std::forward<Fx>(fx), std::forward<FxArgs>(args)...); return call<checkargs>(L, 0, ta, tr, ta, std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
} }
template <bool checkargs = detail::default_check_arguments, typename... Args, typename Fx, typename... FxArgs> template <bool checkargs = detail::default_check_arguments, typename... Args, typename Fx, typename... FxArgs>
inline void call(lua_State* L, int start, types<void> tr, types<Args...> ta, Fx&& fx, FxArgs&&... args) { inline void call(lua_State* L, int start, types<void> tr, types<Args...> ta, Fx&& fx, FxArgs&&... args) {
detail::call(L, start, ta, tr, ta, std::forward<Fx>(fx), std::forward<FxArgs>(args)...); detail::call<checkargs>(L, start, ta, tr, ta, std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
} }
template <bool checkargs = detail::default_check_arguments, typename... Args, typename Fx, typename... FxArgs> template <bool checkargs = detail::default_check_arguments, typename... Args, typename Fx, typename... FxArgs>
inline void call(lua_State* L, types<void> tr, types<Args...> ta, Fx&& fx, FxArgs&&... args) { inline void call(lua_State* L, types<void> tr, types<Args...> ta, Fx&& fx, FxArgs&&... args) {
call(L, 0, ta, tr, ta, std::forward<Fx>(fx), std::forward<FxArgs>(args)...); call<checkargs>(L, 0, ta, tr, ta, std::forward<Fx>(fx), std::forward<FxArgs>(args)...);
} }
inline call_syntax get_call_syntax(lua_State* L, const std::string& meta) { inline call_syntax get_call_syntax(lua_State* L, const std::string& meta) {

View File

@ -58,7 +58,7 @@ public:
state(): state():
L(luaL_newstate(), lua_close), L(luaL_newstate(), lua_close),
reg(L.get(), LUA_REGISTRYINDEX), reg(L.get(), LUA_REGISTRYINDEX),
#if SOL_LUA_VERSION < 520 #if SOL_LUA_VERSION < 503
// Global table is just a special index // Global table is just a special index
global(L.get(), LUA_GLOBALSINDEX) { global(L.get(), LUA_GLOBALSINDEX) {
#else #else

View File

@ -118,64 +118,43 @@ class function;
class object; class object;
template <typename T, typename = void> template <typename T, typename = void>
struct lua_type_of : std::integral_constant<type, type::userdata> { struct lua_type_of : std::integral_constant<type, type::userdata> {};
};
template <> template <>
struct lua_type_of<std::string> : std::integral_constant<type, type::string> { struct lua_type_of<std::string> : std::integral_constant<type, type::string> {};
};
template <std::size_t N> template <std::size_t N>
struct lua_type_of<char[N]> : std::integral_constant<type, type::string> { struct lua_type_of<char[N]> : std::integral_constant<type, type::string> {};
};
template <> template <>
struct lua_type_of<const char*> : std::integral_constant<type, type::string> { struct lua_type_of<const char*> : std::integral_constant<type, type::string> {};
};
template <> template <>
struct lua_type_of<bool> : std::integral_constant<type, type::boolean> { struct lua_type_of<bool> : std::integral_constant<type, type::boolean> {};
};
template <> template <>
struct lua_type_of<nil_t> : std::integral_constant<type, type::nil> { struct lua_type_of<nil_t> : std::integral_constant<type, type::nil> {};
};
template <> template <>
struct lua_type_of<table> : std::integral_constant<type, type::table> { struct lua_type_of<table> : std::integral_constant<type, type::table> {};
};
template <> template <>
struct lua_type_of<object> : std::integral_constant<type, type::poly> { struct lua_type_of<object> : std::integral_constant<type, type::poly> {};
};
template <> template <>
struct lua_type_of<light_userdata> : std::integral_constant<type, type::lightuserdata> { struct lua_type_of<light_userdata> : std::integral_constant<type, type::lightuserdata> {};
};
template <> template <>
struct lua_type_of<function> : std::integral_constant<type, type::function> { struct lua_type_of<function> : std::integral_constant<type, type::function> {};
}; template <typename Signature>
struct lua_type_of<std::function<Signature>> : std::integral_constant<type, type::function>{};
template <typename T> template <typename T>
struct lua_type_of<T*> : std::integral_constant<type, type::userdata> { struct lua_type_of<T*> : std::integral_constant<type, type::userdata> {};
};
template <typename T> template <typename T>
struct lua_type_of<T, typename std::enable_if<std::is_arithmetic<T>::value>::type> : std::integral_constant<type, type::number> { struct lua_type_of<T, typename std::enable_if<std::is_arithmetic<T>::value>::type> : std::integral_constant<type, type::number> {};
};
template<typename T> template<typename T>
inline type type_of() { inline type type_of() {

View File

@ -1,4 +1,5 @@
#define CATCH_CONFIG_MAIN #define CATCH_CONFIG_MAIN
#define SOL_CHECK_ARGUMENTS
#include <catch.hpp> #include <catch.hpp>
#include <sol.hpp> #include <sol.hpp>
#include <vector> #include <vector>