From 04acd2141b47b4eee1b0ba87beec05425ae8cf68 Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Thu, 20 Jul 2017 22:01:54 +0000 Subject: [PATCH] Use sol 2.17.5 instead --- third_party/sol2/sol2/sol.hpp | 2362 +++++++++++---------------------- 1 file changed, 791 insertions(+), 1571 deletions(-) diff --git a/third_party/sol2/sol2/sol.hpp b/third_party/sol2/sol2/sol.hpp index 335c7852b..a349ea9d1 100644 --- a/third_party/sol2/sol2/sol.hpp +++ b/third_party/sol2/sol2/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 2017-07-09 23:05:15.984374 UTC -// This header was generated with sol v2.18.0 (revision 2d65f6c) +// Generated 2017-06-13 20:34:08.313723 UTC +// This header was generated with sol v2.17.5 (revision 51a03b2) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -53,169 +53,8 @@ #elif defined _MSC_VER #pragma warning( push ) #pragma warning( disable : 4324 ) // structure was padded due to alignment specifier -#pragma warning( disable : 4503 ) // decorated name horse shit -#pragma warning( disable : 4702 ) // unreachable code #endif // g++ -// beginning of sol/forward.hpp - -// beginning of sol/feature_test.hpp - -#if (defined(__cplusplus) && __cplusplus == 201703L) || (defined(_MSC_VER) && _MSC_VER > 1900 && (defined(_HAS_CXX17) && _HAS_CXX17 == 1) || (_MSVC_LANG > 201402)) -#ifndef SOL_CXX17_FEATURES -#define SOL_CXX17_FEATURES 1 -#endif // C++17 features macro -#endif // C++17 features check - -#if defined(__cpp_noexcept_function_type) -#ifndef SOL_NOEXCEPT_FUNCTION_TYPE -#define SOL_NOEXCEPT_FUNCTION_TYPE 1 -#endif // noexcept is part of a function's type -#endif - -#if defined(_WIN32) || defined(_MSC_VER) -#ifndef SOL_CODECVT_SUPPORT -#define SOL_CODECVT_SUPPORT 1 -#endif // sol codecvt support -#elif defined(__GNUC__) -#if __GNUC__ >= 5 -#ifndef SOL_CODECVT_SUPPORT -#define SOL_CODECVT_SUPPORT 1 -#endif // codecvt support -#endif // g++ 5.x.x (MinGW too) -#else -#endif // Windows/VC++ vs. g++ vs Others - -#ifdef _MSC_VER -#ifdef _DEBUG -#ifndef NDEBUG -#ifndef SOL_CHECK_ARGUMENTS -#endif // Check Arguments -#ifndef SOL_SAFE_USERTYPE -#define SOL_SAFE_USERTYPE -#endif // Safe Usertypes -#endif // NDEBUG -#endif // Debug - -#ifndef _CPPUNWIND -#ifndef SOL_NO_EXCEPTIONS -#define SOL_NO_EXCEPTIONS 1 -#endif -#endif // Automatic Exceptions - -#ifndef _CPPRTTI -#ifndef SOL_NO_RTTI -#define SOL_NO_RTTI 1 -#endif -#endif // Automatic RTTI - -#elif defined(__GNUC__) || defined(__clang__) - -#ifndef NDEBUG -#ifndef __OPTIMIZE__ -#ifndef SOL_CHECK_ARGUMENTS -#endif // Check Arguments -#ifndef SOL_SAFE_USERTYPE -#define SOL_SAFE_USERTYPE -#endif // Safe Usertypes -#endif // g++ optimizer flag -#endif // Not Debug - -#ifndef __EXCEPTIONS -#ifndef SOL_NO_EXCEPTIONS -#define SOL_NO_EXCEPTIONS 1 -#endif -#endif // No Exceptions - -#ifndef __GXX_RTTI -#ifndef SOL_NO_RTII -#define SOL_NO_RTTI 1 -#endif -#endif // No RTTI - -#endif // vc++ || clang++/g++ - -#ifndef SOL_SAFE_USERTYPE -#ifdef SOL_CHECK_ARGUMENTS -#define SOL_SAFE_USERTYPE -#endif // Turn on Safety for all -#endif // Safe Usertypes - -// end of sol/feature_test.hpp - -namespace sol { - - class reference; - class stack_reference; - template - struct proxy; - template - class usertype; - template - class simple_usertype; - template - class basic_table_core; - template - using table_core = basic_table_core; - template - using stack_table_core = basic_table_core; - template - using basic_table = basic_table_core; - typedef table_core table; - typedef table_core global_table; - typedef stack_table_core stack_table; - typedef stack_table_core stack_global_table; - template - struct basic_environment; - using environment = basic_environment; - using stack_environment = basic_environment; - template - class basic_function; - template - class basic_protected_function; - using protected_function = basic_protected_function; - using stack_protected_function = basic_protected_function; - using unsafe_function = basic_function; - using safe_function = basic_protected_function; - using stack_unsafe_function = basic_function; - using stack_safe_function = basic_protected_function; -#ifdef SOL_SAFE_FUNCTIONS - using function = protected_function; - using stack_function = stack_protected_function; -#else - using function = unsafe_function; - using stack_function = stack_unsafe_function; -#endif - template - class basic_object; - template - class basic_userdata; - template - class basic_lightuserdata; - struct variadic_args; - using object = basic_object; - using stack_object = basic_object; - using userdata = basic_userdata; - using stack_userdata = basic_userdata; - using lightuserdata = basic_lightuserdata; - using stack_lightuserdata = basic_lightuserdata; - class coroutine; - class thread; - struct variadic_args; - struct variadic_results; - struct this_state; - struct this_environment; - template - struct light; - template - struct user; - template - struct as_args_t; - -} // sol - -// end of sol/forward.hpp - // beginning of sol/state.hpp // beginning of sol/state_view.hpp @@ -354,13 +193,12 @@ namespace sol { template using void_tuple_element_t = typename void_tuple_element::type; - template + template struct basic_traits { private: typedef std::conditional_t::value, int, T>& first_type; public: - static const bool is_noexcept = it_is_noexcept; static const bool is_member_function = std::is_void::value; static const bool has_c_var_arg = has_c_variadic; static const std::size_t arity = sizeof...(Args); @@ -380,238 +218,123 @@ namespace sol { }; template::value> - struct fx_traits : basic_traits {}; + struct fx_traits : basic_traits {}; // Free Functions template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(*function_pointer_type)(Args...); }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(*function_pointer_type)(Args...); }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(*function_pointer_type)(Args..., ...); }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(*function_pointer_type)(Args..., ...); }; // Member Functions /* C-Style Variadics */ template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args...); }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args..., ...); }; /* Const Volatile */ template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args...) const; }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args..., ...) const; }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args...) const volatile; }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args..., ...) const volatile; }; /* Member Function Qualifiers */ template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args...) &; }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args..., ...) &; }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args...) const &; }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args..., ...) const &; }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args...) const volatile &; }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args..., ...) const volatile &; }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args...) && ; }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args..., ...) && ; }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args...) const &&; }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args..., ...) const &&; }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args...) const volatile &&; }; template - struct fx_traits : basic_traits { + struct fx_traits : basic_traits { typedef R(T::* function_pointer_type)(Args..., ...) const volatile &&; }; -#ifdef SOL_NOEXCEPT_FUNCTION_TYPE - - template - struct fx_traits : basic_traits { - typedef R(*function_pointer_type)(Args...) noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(*function_pointer_type)(Args...) noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(*function_pointer_type)(Args..., ...) noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(*function_pointer_type)(Args..., ...) noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...) noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...) noexcept; - }; - - /* Const Volatile */ - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...) const noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...) const noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...) const volatile noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...) const volatile noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...) & noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...) & noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...) const & noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...) const & noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...) const volatile & noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...) const volatile & noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...) && noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...) && noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...) const && noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...) const && noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args...) const volatile && noexcept; - }; - - template - struct fx_traits : basic_traits { - typedef R(T::* function_pointer_type)(Args..., ...) const volatile && noexcept; - }; - -#endif // noexcept is part of a function's type - template struct fx_traits : fx_traits::function_type, false> {}; @@ -625,7 +348,6 @@ namespace sol { typedef R Arg; typedef T object_type; using signature_type = R(T::*); - static const bool is_noexcept = false; static const bool is_member_function = false; static const std::size_t arity = 1; static const std::size_t free_arity = 2; @@ -640,7 +362,6 @@ namespace sol { template using arg_at = void_tuple_element_t; }; - } // meta_detail template @@ -664,9 +385,6 @@ namespace sol { #include #include #include -#ifdef SOL_CXX17_FEATURES -#include -#endif namespace sol { template @@ -915,42 +633,6 @@ namespace sol { static std::false_type test(...); }; - struct has_key_type_impl { - template, - typename V = typename U::key_type> - static std::true_type test(int); - - template - static std::false_type test(...); - }; - - struct has_mapped_type_impl { - template, - typename V = typename U::mapped_type> - static std::true_type test(int); - - template - static std::false_type test(...); - }; - - struct has_value_type_impl { - template, - typename V = typename U::value_type> - static std::true_type test(int); - - template - static std::false_type test(...); - }; - - struct has_iterator_impl { - template, - typename V = typename U::iterator> - static std::true_type test(int); - - template - static std::false_type test(...); - }; - struct has_key_value_pair_impl { template, typename V = typename U::value_type, @@ -990,31 +672,8 @@ namespace sol { template struct has_key_value_pair : decltype(meta_detail::has_key_value_pair_impl::test(0)) {}; - template - struct has_key_type : decltype(meta_detail::has_key_type_impl::test(0)) {}; - - template - struct has_mapped_type : decltype(meta_detail::has_mapped_type_impl::test(0)) {}; - - template - struct has_iterator : decltype(meta_detail::has_iterator_impl::test(0)) {}; - - template - struct has_value_type : decltype(meta_detail::has_value_type_impl::test(0)) {}; - template - struct is_associative : meta::all, has_mapped_type> {}; - - template - using is_string_constructible = any< - std::is_same, const char*> - , std::is_same, char> - , std::is_same, std::string> - , std::is_same, std::initializer_list> -#ifdef SOL_CXX17_FEATURES - , std::is_same, std::string_view> -#endif - >; + using is_string_constructible = any, const char*>, std::is_same, char>, std::is_same, std::string>, std::is_same, std::initializer_list>>; template struct is_pair : std::false_type {}; @@ -1144,9 +803,7 @@ namespace sol { // end of sol/traits.hpp -// beginning of sol/function.hpp - -// beginning of sol/unsafe_function.hpp +// beginning of sol/object.hpp // beginning of sol/reference.hpp @@ -1162,13 +819,23 @@ namespace sol { #include #include #include -#ifdef SOL_USING_CXX_LUAJIT -#include -#endif // C++ LuaJIT ... whatever that means #else #include #endif // C++ Mangling for Lua +#if defined(_WIN32) || defined(_MSC_VER) +#ifndef SOL_CODECVT_SUPPORT +#define SOL_CODECVT_SUPPORT 1 +#endif // sol codecvt support +#elif defined(__GNUC__) +#if __GNUC__ >= 5 +#ifndef SOL_CODECVT_SUPPORT +#define SOL_CODECVT_SUPPORT 1 +#endif // codecvt support +#endif // g++ 5.x.x (MinGW too) +#else +#endif // Windows/VC++ vs. g++ vs Others + #ifdef LUAJIT_VERSION #ifndef SOL_LUAJIT #define SOL_LUAJIT @@ -1186,6 +853,61 @@ namespace sol { #define SOL_LUA_VERSION 502 #endif // Lua Version 502, 501 || luajit, 500 +#ifdef _MSC_VER +#ifdef _DEBUG +#ifndef NDEBUG +#ifndef SOL_CHECK_ARGUMENTS +#endif // Check Arguments +#ifndef SOL_SAFE_USERTYPE +#define SOL_SAFE_USERTYPE +#endif // Safe Usertypes +#endif // NDEBUG +#endif // Debug + +#ifndef _CPPUNWIND +#ifndef SOL_NO_EXCEPTIONS +#define SOL_NO_EXCEPTIONS 1 +#endif +#endif // Automatic Exceptions + +#ifndef _CPPRTTI +#ifndef SOL_NO_RTTI +#define SOL_NO_RTTI 1 +#endif +#endif // Automatic RTTI + +#elif defined(__GNUC__) || defined(__clang__) + +#ifndef NDEBUG +#ifndef __OPTIMIZE__ +#ifndef SOL_CHECK_ARGUMENTS +#endif // Check Arguments +#ifndef SOL_SAFE_USERTYPE +#define SOL_SAFE_USERTYPE +#endif // Safe Usertypes +#endif // g++ optimizer flag +#endif // Not Debug + +#ifndef __EXCEPTIONS +#ifndef SOL_NO_EXCEPTIONS +#define SOL_NO_EXCEPTIONS 1 +#endif +#endif // No Exceptions + +#ifndef __GXX_RTTI +#ifndef SOL_NO_RTII +#define SOL_NO_RTTI 1 +#endif +#endif // No RTTI + +#endif // vc++ || clang++/g++ + +#ifndef SOL_SAFE_USERTYPE +#ifdef SOL_CHECK_ARGUMENTS +#define SOL_SAFE_USERTYPE +#endif // Turn on Safety for all +#endif // Safe Usertypes + // end of sol/compatibility/version.hpp #ifndef SOL_NO_COMPAT @@ -1411,25 +1133,28 @@ inline int luaL_loadbufferx(lua_State* L, const char* buff, size_t size, const c #define lua_pushglobaltable(L) \ lua_pushvalue(L, LUA_GLOBALSINDEX) -void luaL_checkversion(lua_State *L); - -#if !defined(SOL_LUAJIT_VERSION) || SOL_LUAJIT_VERSION < 20100 -void lua_copy(lua_State *L, int from, int to); -lua_Integer lua_tointegerx(lua_State *L, int i, int *isnum); -lua_Number lua_tonumberx(lua_State *L, int i, int *isnum); -const lua_Number *lua_version(lua_State *L); -void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup); -void luaL_setmetatable(lua_State *L, const char *tname); -void *luaL_testudata(lua_State *L, int i, const char *tname); +#ifndef SOL_LUAJIT #define luaL_newlib(L, l) \ (lua_newtable((L)),luaL_setfuncs((L), (l), 0)) -#endif // LuaJIT-2.1.0-beta3 added these compatibility functions +#else +#if SOL_LUAJIT_VERSION < 20100 +#define luaL_newlib(L, l) \ + (lua_newtable((L)),luaL_setfuncs((L), (l), 0)) +#endif // LuaJIT-2.1.0-beta3 added this in itself +#endif // LuaJIT Compatibility + +void luaL_checkversion(lua_State *L); int lua_absindex(lua_State *L, int i); +void lua_copy(lua_State *L, int from, int to); void lua_rawgetp(lua_State *L, int i, const void *p); void lua_rawsetp(lua_State *L, int i, const void *p); +void *luaL_testudata(lua_State *L, int i, const char *tname); +lua_Number lua_tonumberx(lua_State *L, int i, int *isnum); void lua_getuservalue(lua_State *L, int i); void lua_setuservalue(lua_State *L, int i); +void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup); +void luaL_setmetatable(lua_State *L, const char *tname); int luaL_getsubtable(lua_State *L, int i, const char *name); void luaL_traceback(lua_State *L, lua_State *L1, const char *msg, int level); int luaL_fileresult(lua_State *L, int stat, const char *fname); @@ -1456,7 +1181,6 @@ inline int lua_absindex(lua_State *L, int i) { return i; } -#if !defined(SOL_LUAJIT_VERSION) || SOL_LUAJIT_VERSION < 20100 inline void lua_copy(lua_State *L, int from, int to) { int abs_to = lua_absindex(L, to); luaL_checkstack(L, 1, "not enough stack slots"); @@ -1464,69 +1188,6 @@ inline void lua_copy(lua_State *L, int from, int to) { lua_replace(L, abs_to); } -inline lua_Integer lua_tointegerx(lua_State *L, int i, int *isnum) { - lua_Integer n = lua_tointeger(L, i); - if (isnum != NULL) { - *isnum = (n != 0 || lua_isnumber(L, i)); - } - return n; -} - -inline lua_Number lua_tonumberx(lua_State *L, int i, int *isnum) { - lua_Number n = lua_tonumber(L, i); - if (isnum != NULL) { - *isnum = (n != 0 || lua_isnumber(L, i)); - } - return n; -} - -inline const lua_Number *lua_version(lua_State *L) { - static const lua_Number version = LUA_VERSION_NUM; - if (L == NULL) return &version; - // TODO: wonky hacks to get at the inside of the incomplete type lua_State? - //else return L->l_G->version; - else return &version; -} - -/* -** Adapted from Lua 5.2.0 -*/ -inline void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) { - luaL_checkstack(L, nup + 1, "too many upvalues"); - for (; l->name != NULL; l++) { /* fill the table with given functions */ - int i; - lua_pushstring(L, l->name); - for (i = 0; i < nup; i++) /* copy upvalues to the top */ - lua_pushvalue(L, -(nup + 1)); - lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ - lua_settable(L, -(nup + 3)); /* table must be below the upvalues, the name and the closure */ - } - lua_pop(L, nup); /* remove upvalues */ -} - -inline void luaL_setmetatable(lua_State *L, const char *tname) { - luaL_checkstack(L, 1, "not enough stack slots"); - luaL_getmetatable(L, tname); - lua_setmetatable(L, -2); -} - -inline void *luaL_testudata(lua_State *L, int i, const char *tname) { - void *p = lua_touserdata(L, i); - luaL_checkstack(L, 2, "not enough stack slots"); - if (p == NULL || !lua_getmetatable(L, i)) - return NULL; - else { - int res = 0; - luaL_getmetatable(L, tname); - res = lua_rawequal(L, -1, -2); - lua_pop(L, 2); - if (!res) - p = NULL; - } - return p; -} -#endif - inline void lua_rawgetp(lua_State *L, int i, const void *p) { int abs_i = lua_absindex(L, i); lua_pushlightuserdata(L, (void*)p); @@ -1541,6 +1202,30 @@ inline void lua_rawsetp(lua_State *L, int i, const void *p) { lua_rawset(L, abs_i); } +inline void *luaL_testudata(lua_State *L, int i, const char *tname) { + void *p = lua_touserdata(L, i); + luaL_checkstack(L, 2, "not enough stack slots"); + if (p == NULL || !lua_getmetatable(L, i)) + return NULL; + else { + int res = 0; + luaL_getmetatable(L, tname); + res = lua_rawequal(L, -1, -2); + lua_pop(L, 2); + if (!res) + p = NULL; + } + return p; +} + +inline lua_Number lua_tonumberx(lua_State *L, int i, int *isnum) { + lua_Number n = lua_tonumber(L, i); + if (isnum != NULL) { + *isnum = (n != 0 || lua_isnumber(L, i)); + } + return n; +} + inline static void push_package_table(lua_State *L) { lua_pushliteral(L, PACKAGE_KEY); lua_rawget(L, LUA_REGISTRYINDEX); @@ -1590,6 +1275,28 @@ inline void lua_setuservalue(lua_State *L, int i) { lua_setfenv(L, i); } +/* +** Adapted from Lua 5.2.0 +*/ +inline void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup) { + luaL_checkstack(L, nup + 1, "too many upvalues"); + for (; l->name != NULL; l++) { /* fill the table with given functions */ + int i; + lua_pushstring(L, l->name); + for (i = 0; i < nup; i++) /* copy upvalues to the top */ + lua_pushvalue(L, -(nup + 1)); + lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ + lua_settable(L, -(nup + 3)); /* table must be below the upvalues, the name and the closure */ + } + lua_pop(L, nup); /* remove upvalues */ +} + +inline void luaL_setmetatable(lua_State *L, const char *tname) { + luaL_checkstack(L, 1, "not enough stack slots"); + luaL_getmetatable(L, tname); + lua_setmetatable(L, -2); +} + inline int luaL_getsubtable(lua_State *L, int i, const char *name) { int abs_i = lua_absindex(L, i); luaL_checkstack(L, 3, "not enough stack slots"); @@ -1705,6 +1412,14 @@ inline void luaL_traceback(lua_State *L, lua_State *L1, } #endif +inline const lua_Number *lua_version(lua_State *L) { + static const lua_Number version = LUA_VERSION_NUM; + if (L == NULL) return &version; + // TODO: wonky hacks to get at the inside of the incomplete type lua_State? + //else return L->l_G->version; + else return &version; +} + inline static void luaL_checkversion_(lua_State *L, lua_Number ver) { const lua_Number* v = lua_version(L); if (v != lua_version(NULL)) @@ -1734,7 +1449,7 @@ inline int luaL_fileresult(lua_State *L, int stat, const char *fname) { } else { char buf[1024]; -#if defined(__GLIBC__) || defined(_POSIX_VERSION) || defined(__APPLE__) +#if defined(__GLIBC__) || defined(_POSIX_VERSION) strerror_r(en, buf, 1024); #else strerror_s(buf, 1024, en); @@ -1977,6 +1692,14 @@ inline lua_Unsigned luaL_optunsigned(lua_State *L, int i, lua_Unsigned def) { return luaL_opt(L, luaL_checkunsigned, i, def); } +inline lua_Integer lua_tointegerx(lua_State *L, int i, int *isnum) { + lua_Integer n = lua_tointeger(L, i); + if (isnum != NULL) { + *isnum = (n != 0 || lua_isnumber(L, i)); + } + return n; +} + inline void lua_len(lua_State *L, int i) { switch (lua_type(L, i)) { case LUA_TSTRING: /* fall through */ @@ -2128,51 +1851,28 @@ inline void luaL_pushresult(luaL_Buffer_52 *B) { // beginning of sol/in_place.hpp -#include - namespace sol { -#ifdef SOL_CXX17_FEATURES - using in_place_t = std::in_place_t; - constexpr std::in_place_t in_place{}; - constexpr std::in_place_t in_place_of{}; - - template using in_place_type_t = std::in_place_type_t; - template - constexpr std::in_place_type_t in_place_type{}; - - template using in_place_index_t = std::in_place_index_t; - template - constexpr in_place_index_t in_place_index{}; -#else namespace detail { - struct in_place_of_tag {}; + struct in_place_of {}; template struct in_place_of_i {}; template struct in_place_of_t {}; } // detail - struct in_place_tag { constexpr in_place_tag() = default; }; - - constexpr inline in_place_tag in_place (detail::in_place_of_tag) { return in_place_tag(); } + struct in_place_tag { struct init {}; constexpr in_place_tag(init) {} in_place_tag() = delete; }; + constexpr inline in_place_tag in_place(detail::in_place_of) { return in_place_tag(in_place_tag::init()); } template - constexpr inline in_place_tag in_place (detail::in_place_of_t) { return in_place_tag(); } + constexpr inline in_place_tag in_place(detail::in_place_of_t) { return in_place_tag(in_place_tag::init()); } template - constexpr inline in_place_tag in_place (detail::in_place_of_i) { return in_place_tag(); } + constexpr inline in_place_tag in_place(detail::in_place_of_i) { return in_place_tag(in_place_tag::init()); } - constexpr inline in_place_tag in_place_of(detail::in_place_of_tag) { return in_place_tag(); } - template - constexpr inline in_place_tag in_place_type (detail::in_place_of_t) { return in_place_tag(); } - template - constexpr inline in_place_tag in_place_index (detail::in_place_of_i) { return in_place_tag(); } - - using in_place_t = in_place_tag(&)(detail::in_place_of_tag); + using in_place_t = in_place_tag(&)(detail::in_place_of); template using in_place_type_t = in_place_tag(&)(detail::in_place_of_t); template using in_place_index_t = in_place_tag(&)(detail::in_place_of_i); -#endif } // sol @@ -3279,14 +2979,8 @@ namespace sol { // beginning of sol/string_shim.hpp -#ifdef SOL_CXX17_FEATURES -#endif // C++17 features - namespace sol { namespace string_detail { -#ifdef SOL_CXX17_FEATURES - typedef std::string_view string_shim; -#else struct string_shim { std::size_t s; const char* p; @@ -3342,42 +3036,27 @@ namespace sol { return !(*this == r); } }; -#endif // C++17 } } // end of sol/string_shim.hpp #include -#ifdef SOL_CXX17_FEATURES -#include -#endif // C++17 namespace sol { namespace detail { -#ifdef SOL_NOEXCEPT_FUNCTION_TYPE - typedef int(*lua_CFunction_noexcept) (lua_State *L) noexcept; -#endif // noexcept function type for lua_CFunction - #ifdef SOL_NO_EXCEPTIONS template - int static_trampoline(lua_State* L) noexcept { + int static_trampoline(lua_State* L) { return f(L); } -#ifdef SOL_NOEXCEPT_FUNCTION_TYPE - template - int static_trampoline_noexcept(lua_State* L) noexcept { - return f(L); - } -#endif - template - int trampoline(lua_State* L, Fx&& f, Args&&... args) noexcept { + int trampoline(lua_State* L, Fx&& f, Args&&... args) { return f(L, std::forward(args)...); } - inline int c_trampoline(lua_State* L, lua_CFunction f) noexcept { + inline int c_trampoline(lua_State* L, lua_CFunction f) { return trampoline(L, f); } #else @@ -3394,35 +3073,15 @@ namespace sol { } #if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) catch (...) { + std::exception_ptr eptr = std::current_exception(); lua_pushstring(L, "caught (...) exception"); } #endif return lua_error(L); } -#ifdef SOL_NOEXCEPT_FUNCTION_TYPE -#if 0 - template - int static_trampoline(lua_State* L) noexcept { -#else - template - int static_trampoline_noexcept(lua_State* L) noexcept { -#endif // impossible - return f(L); - } - -#else - template - int static_trampoline_noexcept(lua_State* L) noexcept { - return f(L); - } -#endif // noexcept lua_CFunction type - template int trampoline(lua_State* L, Fx&& f, Args&&... args) { - if (meta::bind_traits>::is_noexcept) { - return f(L, std::forward(args)...); - } try { return f(L, std::forward(args)...); } @@ -3445,21 +3104,6 @@ namespace sol { } #endif // Exceptions vs. No Exceptions - template - inline int typed_static_trampoline_raw(std::true_type, lua_State* L) { - return static_trampoline_noexcept(L); - } - - template - inline int typed_static_trampoline_raw(std::false_type, lua_State* L) { - return static_trampoline(L); - } - - template - inline int typed_static_trampoline(lua_State* L) { - return typed_static_trampoline_raw(std::integral_constant::is_noexcept>(), L); - } - template struct unique_usertype {}; @@ -3721,11 +3365,6 @@ namespace sol { return as_table_t(std::forward(container)); } - template - nested as_nested(T&& container) { - return as_nested(std::forward(container)); - } - struct this_state { lua_State* L; operator lua_State* () const { @@ -3972,6 +3611,64 @@ namespace sol { return lua_typename(L, static_cast(t)); } + class reference; + class stack_reference; + template + struct proxy; + template + class usertype; + template + class basic_table_core; + template + using table_core = basic_table_core; + template + using stack_table_core = basic_table_core; + template + using basic_table = basic_table_core; + typedef table_core table; + typedef table_core global_table; + typedef stack_table_core stack_table; + typedef stack_table_core stack_global_table; + template + struct basic_environment; + using environment = basic_environment; + using stack_environment = basic_environment; + template + class basic_function; + template + class basic_protected_function; + using protected_function = basic_protected_function; + using stack_protected_function = basic_protected_function; + using unsafe_function = basic_function; + using safe_function = basic_protected_function; + using stack_unsafe_function = basic_function; + using stack_safe_function = basic_protected_function; +#ifdef SOL_SAFE_FUNCTIONS + using function = protected_function; + using stack_function = stack_protected_function; +#else + using function = unsafe_function; + using stack_function = stack_unsafe_function; +#endif + template + class basic_object; + template + class basic_userdata; + template + class basic_lightuserdata; + struct variadic_args; + using object = basic_object; + using stack_object = basic_object; + using userdata = basic_userdata; + using stack_userdata = basic_userdata; + using lightuserdata = basic_lightuserdata; + using stack_lightuserdata = basic_lightuserdata; + class coroutine; + class thread; + struct variadic_args; + struct this_state; + struct this_environment; + namespace detail { template struct lua_type_of : std::integral_constant {}; @@ -4021,6 +3718,9 @@ namespace sol { template <> struct lua_type_of : std::integral_constant {}; + template <> + struct lua_type_of : std::integral_constant {}; + template <> struct lua_type_of : std::integral_constant {}; @@ -4135,29 +3835,6 @@ namespace sol { template struct lua_type_of::value>> : std::integral_constant {}; - template <> - struct lua_type_of : std::integral_constant {}; - -#ifdef SOL_CXX17_FEATURES - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template - struct lua_type_of> : std::integral_constant {}; -#else - template <> - struct lua_type_of : std::integral_constant {}; -#endif // C++ 17 (or not) features - template struct is_container : std::false_type {}; @@ -4173,24 +3850,12 @@ namespace sol { template <> struct is_container : std::false_type {}; -#ifdef SOL_CXX17_FEATURES - template <> - struct is_container : std::false_type {}; - - template <> - struct is_container : std::false_type {}; - - template <> - struct is_container : std::false_type {}; - - template <> - struct is_container : std::false_type {}; - -#endif // C++ 17 - template struct is_container>::value>> : std::true_type {}; + template <> + struct lua_type_of : std::integral_constant {}; + template class V, typename... Args> struct accumulate : std::integral_constant {}; @@ -4782,26 +4447,25 @@ namespace sol { template struct as_value_tag {}; - using unique_destructor = void(*)(void*); + using special_destruct_func = void(*)(void*); + + template + inline void special_destruct(void* memory) { + T** pointerpointer = static_cast(memory); + special_destruct_func* dx = static_cast(static_cast(pointerpointer + 1)); + Real* target = static_cast(static_cast(dx + 1)); + target->~Real(); + } template inline int unique_destruct(lua_State* L) { void* memory = lua_touserdata(L, 1); T** pointerpointer = static_cast(memory); - unique_destructor& dx = *static_cast(static_cast(pointerpointer + 1)); + special_destruct_func& dx = *static_cast(static_cast(pointerpointer + 1)); (dx)(memory); return 0; } - template - inline void usertype_unique_alloc_destroy(void* memory) { - T** pointerpointer = static_cast(memory); - unique_destructor* dx = static_cast(static_cast(pointerpointer + 1)); - Real* target = static_cast(static_cast(dx + 1)); - std::allocator alloc; - alloc.destroy(target); - } - template inline int user_alloc_destroy(lua_State* L) { void* rawdata = lua_touserdata(L, 1); @@ -5431,8 +5095,7 @@ namespace sol { // end of sol/inheritance.hpp -#ifdef SOL_CXX17_FEATURES -#endif // C++17 +#include namespace sol { namespace stack { @@ -5834,16 +5497,8 @@ namespace sol { return true; } int metatableindex = lua_gettop(L); - if (stack_detail::check_metatable>(L, metatableindex)) { - void* memory = lua_touserdata(L, index); - T** pointerpointer = static_cast(memory); - detail::unique_destructor& pdx = *static_cast(static_cast(pointerpointer + 1)); - bool success = &detail::usertype_unique_alloc_destroy == pdx; - if (!success) { - handler(L, index, type::userdata, indextype); - } - return success; - } + if (stack_detail::check_metatable>(L, metatableindex)) + return true; lua_pop(L, 1); handler(L, index, type::userdata, indextype); return false; @@ -5890,40 +5545,6 @@ namespace sol { return stack::check(L, index, no_panic, tracking); } }; - -#ifdef SOL_CXX17_FEATURES - template - struct checker, type::poly, C> { - typedef std::variant V; - typedef std::variant_size V_size; - typedef std::integral_constant V_is_empty; - - template - static bool is_one(std::integral_constant, lua_State* L, int index, Handler&& handler, record& tracking) { - if (V_is_empty::value && lua_isnone(L, index)) { - return true; - } - tracking.use(1); - handler(L, index, type::poly, type_of(L, index)); - return false; - } - - template - static bool is_one(std::integral_constant, lua_State* L, int index, Handler&& handler, record& tracking) { - typedef std::variant_alternative_t T; - if (stack::check(L, index, no_panic, tracking)) { - return true; - } - return is_one(std::integral_constant(), L, index, std::forward(handler), tracking); - } - - template - static bool check(lua_State* L, int index, Handler&& handler, record& tracking) { - return is_one(std::integral_constant(), L, index, std::forward(handler), tracking); - } - }; -#endif // C++17 - } // stack } // sol @@ -5955,9 +5576,7 @@ namespace sol { #ifdef SOL_CODECVT_SUPPORT #include -#endif // codecvt header support -#ifdef SOL_CXX17_FEATURES -#endif // C++17 +#endif namespace sol { namespace stack { @@ -6067,7 +5686,7 @@ namespace sol { typedef typename P::second_type V; return get(types(), L, index, tracking); } - + template static T get(types, lua_State* L, int relindex, record& tracking) { tracking.use(1); @@ -6097,7 +5716,7 @@ namespace sol { return g.get(L, index, tracking); } }; - + template struct getter, std::enable_if_t, meta::neg>>>::value>> { static T get(lua_State* L, int index, record& tracking) { @@ -6192,7 +5811,17 @@ namespace sol { tracking.use(1); std::size_t len; auto str = lua_tolstring(L, index, &len); - return std::string(str, len); + return std::string( str, len ); + } + }; + + template <> + struct getter { + string_detail::string_shim get(lua_State* L, int index, record& tracking) { + tracking.use(1); + size_t len; + const char* p = lua_tolstring(L, index, &len); + return string_detail::string_shim(p, len); } }; @@ -6200,11 +5829,10 @@ namespace sol { struct getter { static const char* get(lua_State* L, int index, record& tracking) { tracking.use(1); - size_t sz; - return lua_tolstring(L, index, &sz); + return lua_tostring(L, index); } }; - + template<> struct getter { static char get(lua_State* L, int index, record& tracking) { @@ -6232,7 +5860,7 @@ namespace sol { // https://sourceforge.net/p/mingw-w64/bugs/538/ // http://chat.stackoverflow.com/transcript/message/32271369#32271369 for (auto& c : r) { - uint8_t* b = reinterpret_cast(&c); + uint8_t* b = reinterpret_cast(&c); std::swap(b[0], b[1]); } #endif @@ -6413,7 +6041,7 @@ namespace sol { T* obj = static_cast(udata); return obj; } - + static T& get(lua_State* L, int index, record& tracking) { return *get_no_lua_nil(L, index, tracking); } @@ -6482,31 +6110,31 @@ namespace sol { static Real& get(lua_State* L, int index, record& tracking) { tracking.use(1); P** pref = static_cast(lua_touserdata(L, index)); - detail::unique_destructor* fx = static_cast(static_cast(pref + 1)); + detail::special_destruct_func* fx = static_cast(static_cast(pref + 1)); Real* mem = static_cast(static_cast(fx + 1)); return *mem; } }; - template - struct getter> { - typedef std::tuple(nullptr, 0))...> R; - - template - static R apply(std::index_sequence<>, lua_State*, int, record&, Args&&... args) { + template + struct getter> { + typedef std::tuple(nullptr, 0))...> R; + + template + static R apply(std::index_sequence<>, lua_State*, int, record&, TArgs&&... args) { // Fuck you too, VC++ - return R{ std::forward(args)... }; + return R{std::forward(args)...}; } - - template - static R apply(std::index_sequence, lua_State* L, int index, record& tracking, Args&&... args) { + + template + static R apply(std::index_sequence, lua_State* L, int index, record& tracking, TArgs&&... args) { // Fuck you too, VC++ - typedef std::tuple_element_t> T; - return apply(std::index_sequence(), L, index, tracking, std::forward(args)..., stack::get(L, index + tracking.used, tracking)); + typedef std::tuple_element_t> T; + return apply(std::index_sequence(), L, index, tracking, std::forward(args)..., stack::get(L, index + tracking.used, tracking)); } static R get(lua_State* L, int index, record& tracking) { - return apply(std::make_index_sequence(), L, index, tracking); + return apply(std::make_index_sequence(), L, index, tracking); } }; @@ -6516,65 +6144,6 @@ namespace sol { return std::pair(L, index)), decltype(stack::get(L, index))>{stack::get(L, index, tracking), stack::get(L, index + tracking.used, tracking)}; } }; - -#ifdef SOL_CXX17_FEATURES - template<> - struct getter { - static std::string_view get(lua_State* L, int index, record& tracking) { - tracking.use(1); - size_t sz; - const char* str = lua_tolstring(L, index, &sz); - return std::string_view(str, sz); - } - }; - - template - struct getter> { - typedef std::variant V; - typedef std::variant_size V_size; - typedef std::integral_constant V_is_empty; - - static V get_empty(std::true_type, lua_State* L, int index, record& tracking) { - return V(); - } - - static V get_empty(std::false_type, lua_State* L, int index, record& tracking) { - typedef std::variant_alternative_t<0, V> T; - // This should never be reached... - // please check your code and understand what you did to bring yourself here - std::abort(); - return V(std::in_place_index<0>, stack::get(L, index)); - } - - static V get_one(std::integral_constant, lua_State* L, int index, record& tracking) { - return get_empty(V_is_empty(), L, index, tracking); - } - - template - static V get_one(std::integral_constant, lua_State* L, int index, record& tracking) { - typedef std::variant_alternative_t T; - if (stack::check(L, index, no_panic, tracking)) { - return V(std::in_place_index, stack::get(L, index)); - } - return get_one(std::integral_constant(), L, index, tracking); - } - - static V get(lua_State* L, int index, record& tracking) { - return get_one(std::integral_constant(), L, index, tracking); - } - }; -#else - template <> - struct getter { - string_detail::string_shim get(lua_State* L, int index, record& tracking) { - tracking.use(1); - size_t len; - const char* p = lua_tolstring(L, index, &len); - return string_detail::string_shim(p, len); - } - }; -#endif // C++17-wave - } // stack } // sol @@ -6663,48 +6232,6 @@ namespace sol { return check_get(L, index, no_panic, tracking); } }; - -#ifdef SOL_CXX17_FEATURES - template - struct check_getter> { - typedef std::variant V; - typedef std::variant_size V_size; - typedef std::integral_constant V_is_empty; - - template - static optional get_empty(std::true_type, lua_State* L, int index, Handler&& handler, record& tracking) { - return nullopt; - } - - template - static optional get_empty(std::false_type, lua_State* L, int index, Handler&& handler, record& tracking) { - typedef std::variant_alternative_t<0, V> T; - // This should never be reached... - // please check your code and understand what you did to bring yourself here - handler(L, index, type::poly, type_of(L, index)); - return nullopt; - } - - template - static optional get_one(std::integral_constant, lua_State* L, int index, Handler&& handler, record& tracking) { - return get_empty(V_is_empty(), L, index, std::forward(handler), tracking); - } - - template - static optional get_one(std::integral_constant, lua_State* L, int index, Handler&& handler, record& tracking) { - typedef std::variant_alternative_t T; - if (stack::check(L, index, no_panic, tracking)) { - return V(std::in_place_index, stack::get(L, index)); - } - return get_one(std::integral_constant(), L, index, std::forward(handler), tracking); - } - - template - static optional get(lua_State* L, int index, Handler&& handler, record& tracking) { - return get_one(std::integral_constant(), L, index, std::forward(handler), tracking); - } - }; -#endif // C++17 } // stack } // sol @@ -6822,8 +6349,6 @@ namespace sol { #ifdef SOL_CODECVT_SUPPORT #endif -#ifdef SOL_CXX17_FEATURES -#endif // C++17 namespace sol { namespace stack { @@ -6937,9 +6462,6 @@ namespace sol { template >> = meta::enabler> static int push(lua_State* L, Arg&& arg) { - if (unique_usertype_traits::is_null(arg)) { - return stack::push(L, lua_nil); - } return push_deep(L, std::forward(arg)); } @@ -6950,10 +6472,10 @@ namespace sol { template static int push_deep(lua_State* L, Args&&... args) { - P** pref = static_cast(lua_newuserdata(L, sizeof(P*) + sizeof(detail::unique_destructor) + sizeof(Real))); - detail::unique_destructor* fx = static_cast(static_cast(pref + 1)); + P** pref = static_cast(lua_newuserdata(L, sizeof(P*) + sizeof(detail::special_destruct_func) + sizeof(Real))); + detail::special_destruct_func* fx = static_cast(static_cast(pref + 1)); Real* mem = static_cast(static_cast(fx + 1)); - *fx = detail::usertype_unique_alloc_destroy; + *fx = detail::special_destruct; detail::default_construct::construct(mem, std::forward(args)...); *pref = unique_usertype_traits::get(*mem); if (luaL_newmetatable(L, &usertype_traits>::metatable()[0]) == 1) { @@ -7107,23 +6629,6 @@ namespace sol { return 1; } }; -#ifdef SOL_NOEXCEPT_FUNCTION_TYPE - template<> - struct pusher> { - static int push(lua_State* L, detail::lua_CFunction_noexcept func, int n = 0) { - lua_pushcclosure(L, func, n); - return 1; - } - }; - - template<> - struct pusher { - static int push(lua_State* L, detail::lua_CFunction_noexcept func, int n = 0) { - lua_pushcclosure(L, func, n); - return 1; - } - }; -#endif // noexcept function type template<> struct pusher { @@ -7497,7 +7002,7 @@ namespace sol { if (t == nullopt) { return stack::push(L, nullopt); } - return stack::push(L, static_cast::value, O&, O&&>>(t.value())); + return stack::push(L, t.value()); } }; @@ -7529,63 +7034,6 @@ namespace sol { return 1; } }; - -#ifdef SOL_CXX17_FEATURES - template <> - struct pusher { - static int push(lua_State* L, const std::string_view& sv) { - return stack::push(L, sv.data(), sv.length()); - } - }; -#ifdef SOL_CODECVT_SUPPORT - template <> - struct pusher { - static int push(lua_State* L, const std::wstring_view& sv) { - return stack::push(L, sv.data(), sv.length()); - } - }; - - template <> - struct pusher { - static int push(lua_State* L, const std::u16string_view& sv) { - return stack::push(L, sv.data(), sv.length()); - } - }; - - template <> - struct pusher { - static int push(lua_State* L, const std::u32string_view& sv) { - return stack::push(L, sv.data(), sv.length()); - } - }; -#endif // codecvt header support - - namespace stack_detail { - - struct push_function { - lua_State* L; - - push_function(lua_State* L) : L(L) {} - - template - int operator()(T&& value) const { - return stack::push(L, std::forward(value)); - } - }; - - } // stack_detail - - template - struct pusher> { - static int push(lua_State* L, const std::variant& v) { - return std::visit(stack_detail::push_function(L), v); - } - - static int push(lua_State* L, std::variant&& v) { - return std::visit(stack_detail::push_function(L), std::move(v)); - } - }; -#endif } // stack } // sol @@ -8100,6 +7548,175 @@ namespace sol { // end of sol/stack.hpp +// beginning of sol/object_base.hpp + +namespace sol { + + template + class basic_object_base : public base_t { + private: + template + decltype(auto) as_stack(std::true_type) const { + return stack::get(base_t::lua_state(), base_t::stack_index()); + } + + template + decltype(auto) as_stack(std::false_type) const { + base_t::push(); + return stack::pop(base_t::lua_state()); + } + + template + bool is_stack(std::true_type) const { + return stack::check(base_t::lua_state(), base_t::stack_index(), no_panic); + } + + template + bool is_stack(std::false_type) const { + int r = base_t::registry_index(); + if (r == LUA_REFNIL) + return meta::any_same, lua_nil_t, nullopt_t, std::nullptr_t>::value ? true : false; + if (r == LUA_NOREF) + return false; + auto pp = stack::push_pop(*this); + return stack::check(base_t::lua_state(), -1, no_panic); + } + + public: + basic_object_base() noexcept = default; + basic_object_base(const basic_object_base&) = default; + basic_object_base(basic_object_base&&) = default; + basic_object_base& operator=(const basic_object_base&) = default; + basic_object_base& operator=(basic_object_base&&) = default; + template , basic_object_base>>> = meta::enabler> + basic_object_base(T&& arg, Args&&... args) : base_t(std::forward(arg), std::forward(args)...) { } + + template + decltype(auto) as() const { + return as_stack(std::is_same()); + } + + template + bool is() const { + return is_stack(std::is_same()); + } + }; +} // sol + +// end of sol/object_base.hpp + +// beginning of sol/userdata.hpp + +namespace sol { + template + class basic_userdata : public basic_table { + typedef basic_table base_t; + public: + basic_userdata() noexcept = default; + template , basic_userdata>>, meta::neg>, std::is_base_of>> = meta::enabler> + basic_userdata(T&& r) noexcept : base_t(std::forward(r)) { +#ifdef SOL_CHECK_ARGUMENTS + if (!is_userdata>::value) { + auto pp = stack::push_pop(*this); + type_assert(base_t::lua_state(), -1, type::userdata); + } +#endif // Safety + } + basic_userdata(const basic_userdata&) = default; + basic_userdata(basic_userdata&&) = default; + basic_userdata& operator=(const basic_userdata&) = default; + basic_userdata& operator=(basic_userdata&&) = default; + basic_userdata(const stack_reference& r) : basic_userdata(r.lua_state(), r.stack_index()) {} + basic_userdata(stack_reference&& r) : basic_userdata(r.lua_state(), r.stack_index()) {} + template >>, meta::neg, ref_index>>> = meta::enabler> + basic_userdata(lua_State* L, T&& r) : basic_userdata(L, sol::ref_index(r.registry_index())) {} + basic_userdata(lua_State* L, int index = -1) : base_t(detail::no_safety, L, index) { +#ifdef SOL_CHECK_ARGUMENTS + stack::check(L, index, type_panic); +#endif // Safety + } + basic_userdata(lua_State* L, ref_index index) : base_t(detail::no_safety, L, index) { +#ifdef SOL_CHECK_ARGUMENTS + auto pp = stack::push_pop(*this); + stack::check(L, index, type_panic); +#endif // Safety + } + }; + + template + class basic_lightuserdata : public basic_object_base { + typedef basic_object_base base_t; + public: + basic_lightuserdata() noexcept = default; + template , basic_lightuserdata>>, meta::neg>, std::is_base_of>> = meta::enabler> + basic_lightuserdata(T&& r) noexcept : base_t(std::forward(r)) { +#ifdef SOL_CHECK_ARGUMENTS + if (!is_lightuserdata>::value) { + auto pp = stack::push_pop(*this); + type_assert(base_t::lua_state(), -1, type::lightuserdata); + } +#endif // Safety + } + basic_lightuserdata(const basic_lightuserdata&) = default; + basic_lightuserdata(basic_lightuserdata&&) = default; + basic_lightuserdata& operator=(const basic_lightuserdata&) = default; + basic_lightuserdata& operator=(basic_lightuserdata&&) = default; + basic_lightuserdata(const stack_reference& r) : basic_lightuserdata(r.lua_state(), r.stack_index()) {} + basic_lightuserdata(stack_reference&& r) : basic_lightuserdata(r.lua_state(), r.stack_index()) {} + template >>, meta::neg, ref_index>>> = meta::enabler> + basic_lightuserdata(lua_State* L, T&& r) : basic_lightuserdata(L, sol::ref_index(r.registry_index())) {} + basic_lightuserdata(lua_State* L, int index = -1) : base_t(L, index) { +#ifdef SOL_CHECK_ARGUMENTS + stack::check(L, index, type_panic); +#endif // Safety + } + basic_lightuserdata(lua_State* L, ref_index index) : base_t(L, index) { +#ifdef SOL_CHECK_ARGUMENTS + auto pp = stack::push_pop(*this); + stack::check(L, index, type_panic); +#endif // Safety + } + }; + +} // sol + +// end of sol/userdata.hpp + +// beginning of sol/as_args.hpp + +namespace sol { + template + struct to_args_t { + T src; + }; + + template + auto as_args(Source&& source) { + return to_args_t{ std::forward(source) }; + } + + namespace stack { + template + struct pusher> { + int push(lua_State* L, const to_args_t& e) { + int p = 0; + for (const auto& i : e.src) { + p += stack::push(L, i); + } + return p; + } + }; + } +} // sol + +// end of sol/as_args.hpp + +// beginning of sol/variadic_args.hpp + +// beginning of sol/stack_proxy.hpp + +// beginning of sol/function.hpp + // beginning of sol/function_result.hpp // beginning of sol/proxy_base.hpp @@ -8201,7 +7818,7 @@ namespace sol { template struct wrapper { - typedef lua_bind_traits> traits_type; + typedef lua_bind_traits traits_type; typedef typename traits_type::args_list args_list; typedef typename traits_type::args_list free_args_list; typedef typename traits_type::returns_list returns_list; @@ -8220,8 +7837,8 @@ namespace sol { }; template - struct wrapper>>::value>> { - typedef lua_bind_traits>> traits_type; + struct wrapper>>::value>> { + typedef lua_bind_traits traits_type; typedef typename traits_type::args_list args_list; typedef typename traits_type::args_list free_args_list; typedef typename traits_type::returns_list returns_list; @@ -8254,7 +7871,7 @@ namespace sol { template struct wrapper>::value>> { - typedef lua_bind_traits> traits_type; + typedef lua_bind_traits traits_type; typedef typename traits_type::object_type object_type; typedef typename traits_type::return_type return_type; typedef typename traits_type::args_list args_list; @@ -8406,85 +8023,6 @@ namespace sol { }; -#ifdef SOL_NOEXCEPT_FUNCTION_TYPE //noexcept has become a part of a function's type - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - - template - struct wrapper : public member_function_wrapper { - - }; - -#endif // noexcept is part of a function's type - } // sol // end of sol/wrapper.hpp @@ -8854,14 +8392,6 @@ namespace sol { return f(L); } }; -#ifdef SOL_NOEXCEPT_FUNCTION_TYPE - template - struct agnostic_lua_call_wrapper { - static int call(lua_State* L, detail::lua_CFunction_noexcept f) { - return f(L); - } - }; -#endif // noexcept function types template struct agnostic_lua_call_wrapper { @@ -9345,7 +8875,7 @@ namespace sol { } template - int call_wrapper_entry(lua_State* L) noexcept(meta::bind_traits::is_noexcept) { + int call_wrapper_entry(lua_State* L) { return call_wrapper_function(std::is_member_function_pointer>(), L); } @@ -9358,30 +8888,15 @@ namespace sol { } }; - template - inline int c_call_raw(std::true_type, lua_State* L) { - return fx(L); - } - - template - inline int c_call_raw(std::false_type, lua_State* L) { -#ifdef __clang__ - return detail::trampoline(L, function_detail::call_wrapper_entry); -#else - return detail::typed_static_trampoline), (&function_detail::call_wrapper_entry)>(L); -#endif // fuck you clang :c - } - } // function_detail template inline int c_call(lua_State* L) { - typedef meta::unqualified_t Fu; - return function_detail::c_call_raw(std::integral_constant::value -#ifdef SOL_NOEXCEPT_FUNCTION_TYPE - || std::is_same::value -#endif - >(), L); +#ifdef __clang__ + return detail::trampoline(L, function_detail::call_wrapper_entry); +#else + return detail::static_trampoline<(&function_detail::call_wrapper_entry)>(L); +#endif // fuck you clang :c } template @@ -9414,16 +8929,16 @@ namespace sol { template struct upvalue_free_function { typedef std::remove_pointer_t> function_type; - typedef meta::bind_traits traits_type; + typedef lua_bind_traits traits_type; - static int real_call(lua_State* L) noexcept(traits_type::is_noexcept) { + static int real_call(lua_State* L) { auto udata = stack::stack_detail::get_as_upvalues(L); function_type* fx = udata.first; return call_detail::call_wrapped(L, fx); } static int call(lua_State* L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_call)>(L); } int operator()(lua_State* L) { @@ -9436,7 +8951,7 @@ namespace sol { typedef std::remove_pointer_t> function_type; typedef lua_bind_traits traits_type; - static int real_call(lua_State* L) noexcept(traits_type::is_noexcept) { + static int real_call(lua_State* L) { // Layout: // idx 1...n: verbatim data of member function pointer // idx n + 1: is the object's void pointer @@ -9450,7 +8965,7 @@ namespace sol { } static int call(lua_State* L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_call)>(L); } int operator()(lua_State* L) { @@ -9463,7 +8978,7 @@ namespace sol { typedef std::remove_pointer_t> function_type; typedef lua_bind_traits traits_type; - static int real_call(lua_State* L) noexcept(traits_type::is_noexcept) { + static int real_call(lua_State* L) { // Layout: // idx 1...n: verbatim data of member variable pointer // idx n + 1: is the object's void pointer @@ -9484,7 +8999,7 @@ namespace sol { } static int call(lua_State* L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_call)>(L); } int operator()(lua_State* L) { @@ -9497,7 +9012,7 @@ namespace sol { typedef std::remove_pointer_t> function_type; typedef lua_bind_traits traits_type; - static int real_call(lua_State* L) noexcept(traits_type::is_noexcept) { + static int real_call(lua_State* L) { // Layout: // idx 1...n: verbatim data of member variable pointer // idx n + 1: is the object's void pointer @@ -9516,7 +9031,7 @@ namespace sol { } static int call(lua_State* L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_call)>(L); } int operator()(lua_State* L) { @@ -9529,7 +9044,7 @@ namespace sol { typedef std::remove_pointer_t> function_type; typedef lua_bind_traits traits_type; - static int real_call(lua_State* L) noexcept(traits_type::is_noexcept) { + static int real_call(lua_State* L) { // Layout: // idx 1...n: verbatim data of member variable pointer auto memberdata = stack::stack_detail::get_as_upvalues(L); @@ -9538,7 +9053,7 @@ namespace sol { } static int call(lua_State* L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_call)>(L); } int operator()(lua_State* L) { @@ -9549,8 +9064,9 @@ namespace sol { template struct upvalue_this_member_variable { typedef std::remove_pointer_t> function_type; + typedef lua_bind_traits traits_type; - static int real_call(lua_State* L) noexcept(false) { + static int real_call(lua_State* L) { // Layout: // idx 1...n: verbatim data of member variable pointer auto memberdata = stack::stack_detail::get_as_upvalues(L); @@ -9566,7 +9082,7 @@ namespace sol { } static int call(lua_State* L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_call)>(L); } int operator()(lua_State* L) { @@ -9579,7 +9095,7 @@ namespace sol { typedef std::remove_pointer_t> function_type; typedef lua_bind_traits traits_type; - static int real_call(lua_State* L) noexcept(false) { + static int real_call(lua_State* L) { // Layout: // idx 1...n: verbatim data of member variable pointer auto memberdata = stack::stack_detail::get_as_upvalues(L); @@ -9593,7 +9109,7 @@ namespace sol { } static int call(lua_State* L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_call)>(L); } int operator()(lua_State* L) { @@ -9611,11 +9127,11 @@ namespace sol { namespace function_detail { template struct functor_function { - typedef std::decay_t> function_type; - function_type fx; + typedef meta::unwrapped_t> Function; + Function fx; template - functor_function(function_type f, Args&&... args) : fx(std::move(f), std::forward(args)...) {} + functor_function(Function f, Args&&... args) : fx(std::move(f), std::forward(args)...) {} int call(lua_State* L) { return call_detail::call_wrapped(L, fx); @@ -10025,15 +9541,9 @@ namespace sol { stack::push(L, f); } -#ifdef SOL_NOEXCEPT_FUNCTION_TYPE - static void select_function(std::true_type, lua_State* L, detail::lua_CFunction_noexcept f) { - stack::push(L, f); - } -#endif // noexcept function type - template >, std::is_base_of>>> = meta::enabler> static void select(lua_State* L, Fx&& fx, Args&&... args) { - select_function(std::is_function>>(), L, std::forward(fx), std::forward(args)...); + select_function(std::is_function>(), L, std::forward(fx), std::forward(args)...); } template >, std::is_base_of>>> = meta::enabler> @@ -10095,15 +9605,7 @@ namespace sol { }; template - struct pusher, - meta::neg>, - meta::neg>> -#ifdef SOL_NOEXCEPT_FUNCTION_TYPE - , meta::neg>, - meta::neg>> -#endif // noexcept function types - >::value>> { + struct pusher, meta::neg>, meta::neg>>>::value>> { template static int push(lua_State* L, F&& f) { return pusher>{}.push(L, std::forward(f)); @@ -10349,9 +9851,51 @@ namespace sol { return invoke(types(), std::make_index_sequence(), pushcount); } }; + + namespace stack { + template + struct getter> { + typedef meta::bind_traits fx_t; + typedef typename fx_t::args_list args_lists; + typedef meta::tuple_types return_types; + + template + static std::function get_std_func(types, types, lua_State* L, int index) { + sol::function f(L, index); + auto fx = [f, L, index](Args&&... args) -> meta::return_type_t { + return f.call(std::forward(args)...); + }; + return std::move(fx); + } + + template + static std::function get_std_func(types, types, lua_State* L, int index) { + sol::function f(L, index); + auto fx = [f, L, index](FxArgs&&... args) -> void { + f(std::forward(args)...); + }; + return std::move(fx); + } + + template + static std::function get_std_func(types<>, types t, lua_State* L, int index) { + return get_std_func(types(), t, L, index); + } + + static std::function get(lua_State* L, int index, record& tracking) { + tracking.last = 1; + tracking.used += 1; + type t = type_of(L, index); + if (t == type::none || t == type::lua_nil) { + return nullptr; + } + return get_std_func(return_types(), args_lists(), L, index); + } + }; + } // stack } // sol -// end of sol/unsafe_function.hpp +// end of sol/function.hpp // beginning of sol/protected_function.hpp @@ -10629,411 +10173,6 @@ namespace sol { // end of sol/protected_function.hpp -namespace sol { - - namespace stack { - template - struct getter> { - typedef meta::bind_traits fx_t; - typedef typename fx_t::args_list args_lists; - typedef meta::tuple_types return_types; - - template - static std::function get_std_func(types, types, lua_State* L, int index) { - sol::function f(L, index); - auto fx = [f, L, index](Args&&... args) -> meta::return_type_t { - return f.call(std::forward(args)...); - }; - return std::move(fx); - } - - template - static std::function get_std_func(types, types, lua_State* L, int index) { - sol::function f(L, index); - auto fx = [f, L, index](FxArgs&&... args) -> void { - f(std::forward(args)...); - }; - return std::move(fx); - } - - template - static std::function get_std_func(types<>, types t, lua_State* L, int index) { - return get_std_func(types(), t, L, index); - } - - static std::function get(lua_State* L, int index, record& tracking) { - tracking.last = 1; - tracking.used += 1; - type t = type_of(L, index); - if (t == type::none || t == type::lua_nil) { - return nullptr; - } - return get_std_func(return_types(), args_lists(), L, index); - } - }; - } // stack - -} // sol - -// end of sol/function.hpp - -namespace sol { - template - struct proxy : public proxy_base> { - private: - typedef meta::condition, Key, std::tuple>, Key&, meta::unqualified_t>>> key_type; - - template - decltype(auto) tuple_get(std::index_sequence) const { - return tbl.template traverse_get(std::get(key)...); - } - - template - void tuple_set(std::index_sequence, T&& value) { - tbl.traverse_set(std::get(key)..., std::forward(value)); - } - - public: - Table tbl; - key_type key; - - template - proxy(Table table, T&& k) : tbl(table), key(std::forward(k)) {} - - template - proxy& set(T&& item) { - tuple_set(std::make_index_sequence>::value>(), std::forward(item)); - return *this; - } - - template - proxy& set_function(Args&&... args) { - tbl.set_function(key, std::forward(args)...); - return *this; - } - - template>>, meta::is_callable>> = meta::enabler> - proxy& operator=(U&& other) { - return set_function(std::forward(other)); - } - - template>>, meta::is_callable>> = meta::enabler> - proxy& operator=(U&& other) { - return set(std::forward(other)); - } - - template - decltype(auto) get() const { - return tuple_get(std::make_index_sequence>::value>()); - } - - template - decltype(auto) get_or(T&& otherwise) const { - typedef decltype(get()) U; - optional option = get>(); - if (option) { - return static_cast(option.value()); - } - return static_cast(std::forward(otherwise)); - } - - template - decltype(auto) get_or(D&& otherwise) const { - optional option = get>(); - if (option) { - return static_cast(option.value()); - } - return static_cast(std::forward(otherwise)); - } - - template - decltype(auto) operator[](K&& k) const { - auto keys = meta::tuplefy(key, std::forward(k)); - return proxy(tbl, std::move(keys)); - } - - template - decltype(auto) call(Args&&... args) { - return get().template call(std::forward(args)...); - } - - template - decltype(auto) operator()(Args&&... args) { - return call<>(std::forward(args)...); - } - - bool valid() const { - auto pp = stack::push_pop(tbl); - auto p = stack::probe_get_field, global_table>::value>(tbl.lua_state(), key, lua_gettop(tbl.lua_state())); - lua_pop(tbl.lua_state(), p.levels); - return p; - } - - type get_type() const { - type t = type::none; - auto pp = stack::push_pop(tbl); - auto p = stack::probe_get_field, global_table>::value>(tbl.lua_state(), key, lua_gettop(tbl.lua_state())); - if (p) { - t = type_of(tbl.lua_state(), -1); - } - lua_pop(tbl.lua_state(), p.levels); - return t; - } - }; - - template - inline bool operator==(T&& left, const proxy& right) { - typedef decltype(stack::get(nullptr, 0)) U; - return right.template get>() == left; - } - - template - inline bool operator==(const proxy& right, T&& left) { - typedef decltype(stack::get(nullptr, 0)) U; - return right.template get>() == left; - } - - template - inline bool operator!=(T&& left, const proxy& right) { - typedef decltype(stack::get(nullptr, 0)) U; - return right.template get>() == left; - } - - template - inline bool operator!=(const proxy& right, T&& left) { - typedef decltype(stack::get(nullptr, 0)) U; - return right.template get>() == left; - } - - template - inline bool operator==(lua_nil_t, const proxy& right) { - return !right.valid(); - } - - template - inline bool operator==(const proxy& right, lua_nil_t) { - return !right.valid(); - } - - template - inline bool operator!=(lua_nil_t, const proxy& right) { - return right.valid(); - } - - template - inline bool operator!=(const proxy& right, lua_nil_t) { - return right.valid(); - } - - namespace stack { - template - struct pusher> { - static int push(lua_State* L, const proxy& p) { - sol::reference r = p; - return r.push(L); - } - }; - } // stack -} // sol - -// end of sol/proxy.hpp - -// beginning of sol/usertype.hpp - -// beginning of sol/usertype_metatable.hpp - -// beginning of sol/deprecate.hpp - -#ifndef SOL_DEPRECATED - #ifdef _MSC_VER - #define SOL_DEPRECATED __declspec(deprecated) - #elif __GNUC__ - #define SOL_DEPRECATED __attribute__((deprecated)) - #else - #define SOL_DEPRECATED [[deprecated]] - #endif // compilers -#endif // SOL_DEPRECATED - -namespace sol { - namespace detail { - template - struct SOL_DEPRECATED deprecate_type { - using type = T; - }; - } // detail -} // sol - -// end of sol/deprecate.hpp - -// beginning of sol/object.hpp - -// beginning of sol/object_base.hpp - -namespace sol { - - template - class basic_object_base : public base_t { - private: - template - decltype(auto) as_stack(std::true_type) const { - return stack::get(base_t::lua_state(), base_t::stack_index()); - } - - template - decltype(auto) as_stack(std::false_type) const { - base_t::push(); - return stack::pop(base_t::lua_state()); - } - - template - bool is_stack(std::true_type) const { - return stack::check(base_t::lua_state(), base_t::stack_index(), no_panic); - } - - template - bool is_stack(std::false_type) const { - int r = base_t::registry_index(); - if (r == LUA_REFNIL) - return meta::any_same, lua_nil_t, nullopt_t, std::nullptr_t>::value ? true : false; - if (r == LUA_NOREF) - return false; - auto pp = stack::push_pop(*this); - return stack::check(base_t::lua_state(), -1, no_panic); - } - - public: - basic_object_base() noexcept = default; - basic_object_base(const basic_object_base&) = default; - basic_object_base(basic_object_base&&) = default; - basic_object_base& operator=(const basic_object_base&) = default; - basic_object_base& operator=(basic_object_base&&) = default; - template , basic_object_base>>> = meta::enabler> - basic_object_base(T&& arg, Args&&... args) : base_t(std::forward(arg), std::forward(args)...) { } - - template - decltype(auto) as() const { - return as_stack(std::is_same()); - } - - template - bool is() const { - return is_stack(std::is_same()); - } - }; -} // sol - -// end of sol/object_base.hpp - -// beginning of sol/userdata.hpp - -namespace sol { - template - class basic_userdata : public basic_table { - typedef basic_table base_t; - public: - basic_userdata() noexcept = default; - template , basic_userdata>>, meta::neg>, std::is_base_of>> = meta::enabler> - basic_userdata(T&& r) noexcept : base_t(std::forward(r)) { -#ifdef SOL_CHECK_ARGUMENTS - if (!is_userdata>::value) { - auto pp = stack::push_pop(*this); - type_assert(base_t::lua_state(), -1, type::userdata); - } -#endif // Safety - } - basic_userdata(const basic_userdata&) = default; - basic_userdata(basic_userdata&&) = default; - basic_userdata& operator=(const basic_userdata&) = default; - basic_userdata& operator=(basic_userdata&&) = default; - basic_userdata(const stack_reference& r) : basic_userdata(r.lua_state(), r.stack_index()) {} - basic_userdata(stack_reference&& r) : basic_userdata(r.lua_state(), r.stack_index()) {} - template >>, meta::neg, ref_index>>> = meta::enabler> - basic_userdata(lua_State* L, T&& r) : basic_userdata(L, sol::ref_index(r.registry_index())) {} - basic_userdata(lua_State* L, int index = -1) : base_t(detail::no_safety, L, index) { -#ifdef SOL_CHECK_ARGUMENTS - stack::check(L, index, type_panic); -#endif // Safety - } - basic_userdata(lua_State* L, ref_index index) : base_t(detail::no_safety, L, index) { -#ifdef SOL_CHECK_ARGUMENTS - auto pp = stack::push_pop(*this); - stack::check(L, index, type_panic); -#endif // Safety - } - }; - - template - class basic_lightuserdata : public basic_object_base { - typedef basic_object_base base_t; - public: - basic_lightuserdata() noexcept = default; - template , basic_lightuserdata>>, meta::neg>, std::is_base_of>> = meta::enabler> - basic_lightuserdata(T&& r) noexcept : base_t(std::forward(r)) { -#ifdef SOL_CHECK_ARGUMENTS - if (!is_lightuserdata>::value) { - auto pp = stack::push_pop(*this); - type_assert(base_t::lua_state(), -1, type::lightuserdata); - } -#endif // Safety - } - basic_lightuserdata(const basic_lightuserdata&) = default; - basic_lightuserdata(basic_lightuserdata&&) = default; - basic_lightuserdata& operator=(const basic_lightuserdata&) = default; - basic_lightuserdata& operator=(basic_lightuserdata&&) = default; - basic_lightuserdata(const stack_reference& r) : basic_lightuserdata(r.lua_state(), r.stack_index()) {} - basic_lightuserdata(stack_reference&& r) : basic_lightuserdata(r.lua_state(), r.stack_index()) {} - template >>, meta::neg, ref_index>>> = meta::enabler> - basic_lightuserdata(lua_State* L, T&& r) : basic_lightuserdata(L, sol::ref_index(r.registry_index())) {} - basic_lightuserdata(lua_State* L, int index = -1) : base_t(L, index) { -#ifdef SOL_CHECK_ARGUMENTS - stack::check(L, index, type_panic); -#endif // Safety - } - basic_lightuserdata(lua_State* L, ref_index index) : base_t(L, index) { -#ifdef SOL_CHECK_ARGUMENTS - auto pp = stack::push_pop(*this); - stack::check(L, index, type_panic); -#endif // Safety - } - }; - -} // sol - -// end of sol/userdata.hpp - -// beginning of sol/as_args.hpp - -namespace sol { - template - struct as_args_t { - T src; - }; - - template - auto as_args(Source&& source) { - return as_args_t{ std::forward(source) }; - } - - namespace stack { - template - struct pusher> { - int push(lua_State* L, const as_args_t& e) { - int p = 0; - for (const auto& i : e.src) { - p += stack::push(L, i); - } - return p; - } - }; - } // stack -} // sol - -// end of sol/as_args.hpp - -// beginning of sol/variadic_args.hpp - -// beginning of sol/stack_proxy.hpp - namespace sol { struct stack_proxy : public proxy_base { private: @@ -11049,10 +10188,6 @@ namespace sol { return stack::get(L, stack_index()); } - type get_type() const noexcept { - return type_of(lua_state(), stack_index()); - } - int push() const { return push(L); } @@ -11155,27 +10290,17 @@ namespace sol { stack_proxy sp; va_iterator() : L(nullptr), index((std::numeric_limits::max)()), stacktop((std::numeric_limits::max)()) {} - va_iterator(const va_iterator& r) : L(r.L), index(r.index), stacktop(r.stacktop) {} va_iterator(lua_State* luastate, int idx, int topidx) : L(luastate), index(idx), stacktop(topidx), sp(luastate, idx) {} reference operator*() { return stack_proxy(L, index); } - reference operator*() const { - return stack_proxy(L, index); - } - pointer operator->() { sp = stack_proxy(L, index); return &sp; } - pointer operator->() const { - const_cast(sp) = stack_proxy(L, index); - return &sp; - } - va_iterator& operator++ () { ++index; return *this; @@ -11218,7 +10343,7 @@ namespace sol { return r; } - reference operator[](difference_type idx) const { + reference operator[](difference_type idx) { return stack_proxy(L, index + static_cast(idx)); } @@ -11277,7 +10402,6 @@ namespace sol { variadic_args() = default; variadic_args(lua_State* luastate, int stackindex = -1) : L(luastate), index(lua_absindex(luastate, stackindex)), stacktop(lua_gettop(luastate)) {} - variadic_args(lua_State* luastate, int stackindex, int lastindex) : L(luastate), index(lua_absindex(luastate, stackindex)), stacktop(lastindex) {} variadic_args(const variadic_args&) = default; variadic_args& operator=(const variadic_args&) = default; variadic_args(variadic_args&& o) : L(o.L), index(o.index), stacktop(o.stacktop) { @@ -11336,10 +10460,6 @@ namespace sol { return stack::get(L, index + static_cast(start)); } - type get_type(difference_type start = 0) const noexcept { - return type_of(L, index + static_cast(start)); - } - stack_proxy operator[](difference_type start) const { return stack_proxy(L, index + static_cast(start)); } @@ -11347,7 +10467,6 @@ namespace sol { lua_State* lua_state() const { return L; }; int stack_index() const { return index; }; int leftover_count() const { return stacktop - (index - 1); } - std::size_t size() const { return static_cast(leftover_count()); } int top() const { return stacktop; } }; @@ -11421,11 +10540,9 @@ namespace sol { basic_object(lua_State* L, int index = -1) noexcept : base_t(L, index) {} basic_object(lua_State* L, ref_index index) noexcept : base_t(L, index) {} template - basic_object(lua_State* L, in_place_type_t, Args&&... args) noexcept - : basic_object(std::integral_constant::value>(), L, -stack::push(L, std::forward(args)...)) {} + basic_object(lua_State* L, in_place_type_t, Args&&... args) noexcept : basic_object(std::integral_constant::value>(), L, -stack::push(L, std::forward(args)...)) {} template - basic_object(lua_State* L, in_place_t, T&& arg, Args&&... args) noexcept - : basic_object(L, in_place_type, std::forward(arg), std::forward(args)...) {} + basic_object(lua_State* L, in_place_t, T&& arg, Args&&... args) noexcept : basic_object(L, in_place, std::forward(arg), std::forward(args)...) {} basic_object& operator=(const basic_object&) = default; basic_object& operator=(basic_object&&) = default; basic_object& operator=(const base_type& b) { base_t::operator=(b); return *this; } @@ -11449,6 +10566,183 @@ namespace sol { // end of sol/object.hpp +namespace sol { + template + struct proxy : public proxy_base> { + private: + typedef meta::condition, Key, std::tuple>, Key&, meta::unqualified_t>>> key_type; + + template + decltype(auto) tuple_get(std::index_sequence) const { + return tbl.template traverse_get(std::get(key)...); + } + + template + void tuple_set(std::index_sequence, T&& value) { + tbl.traverse_set(std::get(key)..., std::forward(value)); + } + + public: + Table tbl; + key_type key; + + template + proxy(Table table, T&& k) : tbl(table), key(std::forward(k)) {} + + template + proxy& set(T&& item) { + tuple_set(std::make_index_sequence>::value>(), std::forward(item)); + return *this; + } + + template + proxy& set_function(Args&&... args) { + tbl.set_function(key, std::forward(args)...); + return *this; + } + + template>>, meta::is_callable>> = meta::enabler> + proxy& operator=(U&& other) { + return set_function(std::forward(other)); + } + + template>>, meta::is_callable>> = meta::enabler> + proxy& operator=(U&& other) { + return set(std::forward(other)); + } + + template + decltype(auto) get() const { + return tuple_get(std::make_index_sequence>::value>()); + } + + template + decltype(auto) get_or(T&& otherwise) const { + typedef decltype(get()) U; + optional option = get>(); + if (option) { + return static_cast(option.value()); + } + return static_cast(std::forward(otherwise)); + } + + template + decltype(auto) get_or(D&& otherwise) const { + optional option = get>(); + if (option) { + return static_cast(option.value()); + } + return static_cast(std::forward(otherwise)); + } + + template + decltype(auto) operator[](K&& k) const { + auto keys = meta::tuplefy(key, std::forward(k)); + return proxy(tbl, std::move(keys)); + } + + template + decltype(auto) call(Args&&... args) { + return get().template call(std::forward(args)...); + } + + template + decltype(auto) operator()(Args&&... args) { + return call<>(std::forward(args)...); + } + + bool valid() const { + auto pp = stack::push_pop(tbl); + auto p = stack::probe_get_field, global_table>::value>(tbl.lua_state(), key, lua_gettop(tbl.lua_state())); + lua_pop(tbl.lua_state(), p.levels); + return p; + } + }; + + template + inline bool operator==(T&& left, const proxy& right) { + typedef decltype(stack::get(nullptr, 0)) U; + return right.template get>() == left; + } + + template + inline bool operator==(const proxy& right, T&& left) { + typedef decltype(stack::get(nullptr, 0)) U; + return right.template get>() == left; + } + + template + inline bool operator!=(T&& left, const proxy& right) { + typedef decltype(stack::get(nullptr, 0)) U; + return right.template get>() == left; + } + + template + inline bool operator!=(const proxy& right, T&& left) { + typedef decltype(stack::get(nullptr, 0)) U; + return right.template get>() == left; + } + + template + inline bool operator==(lua_nil_t, const proxy& right) { + return !right.valid(); + } + + template + inline bool operator==(const proxy& right, lua_nil_t) { + return !right.valid(); + } + + template + inline bool operator!=(lua_nil_t, const proxy& right) { + return right.valid(); + } + + template + inline bool operator!=(const proxy& right, lua_nil_t) { + return right.valid(); + } + + namespace stack { + template + struct pusher> { + static int push(lua_State* L, const proxy& p) { + sol::reference r = p; + return r.push(L); + } + }; + } // stack +} // sol + +// end of sol/proxy.hpp + +// beginning of sol/usertype.hpp + +// beginning of sol/usertype_metatable.hpp + +// beginning of sol/deprecate.hpp + +#ifndef SOL_DEPRECATED + #ifdef _MSC_VER + #define SOL_DEPRECATED __declspec(deprecated) + #elif __GNUC__ + #define SOL_DEPRECATED __attribute__((deprecated)) + #else + #define SOL_DEPRECATED [[deprecated]] + #endif // compilers +#endif // SOL_DEPRECATED + +namespace sol { + namespace detail { + template + struct SOL_DEPRECATED deprecate_type { + using type = T; + }; + } // detail +} // sol + +// end of sol/deprecate.hpp + #include #include @@ -11630,12 +10924,12 @@ namespace sol { template inline std::string make_string(Arg&& arg) { string_detail::string_shim s = make_shim(arg); - return std::string(s.data(), s.size()); + return std::string(s.c_str(), s.size()); } template inline luaL_Reg make_reg(N&& n, lua_CFunction f) { - luaL_Reg l{ make_shim(std::forward(n)).data(), f }; + luaL_Reg l{ make_shim(std::forward(n)).c_str(), f }; return l; } @@ -11668,7 +10962,7 @@ namespace sol { #if 0//def SOL_SAFE_USERTYPE auto maybeaccessor = stack::get>(L, is_index ? -1 : -2); string_detail::string_shim accessor = maybeaccessor.value_or(string_detail::string_shim("(unknown)")); - return luaL_error(L, "sol: attempt to index (get) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.data()); + return luaL_error(L, "sol: attempt to index (get) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.c_str()); #else if (is_toplevel(L)) { if (lua_getmetatable(L, 1) == 1) { @@ -11684,7 +10978,7 @@ namespace sol { else { auto maybeaccessor = stack::get>(L, is_index ? -1 : -2); string_detail::string_shim accessor = maybeaccessor.value_or(string_detail::string_shim("(unknown)")); - return luaL_error(L, "sol: attempt to index (set) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.data()); + return luaL_error(L, "sol: attempt to index (set) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.c_str()); } } @@ -12091,20 +11385,20 @@ namespace sol { template static int call(lua_State* L) { - return detail::typed_static_trampoline), (&real_call)>(L); + return detail::static_trampoline<(&real_call)>(L); } template static int call_with(lua_State* L) { - return detail::typed_static_trampoline), (&real_call_with)>(L); + return detail::static_trampoline<(&real_call_with)>(L); } static int index_call(lua_State* L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_index_call)>(L); } static int new_index_call(lua_State* L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_new_index_call)>(L); } virtual int push_um(lua_State* L) override { @@ -12164,8 +11458,8 @@ namespace sol { bool hasdestructor = !value_table.empty() && to_string(meta_function::garbage_collect) == value_table[lastreg - 1].name; if (hasdestructor) { ref_table[lastreg - 1] = { nullptr, nullptr }; + unique_table[lastreg - 1] = { value_table[lastreg - 1].name, detail::unique_destruct }; } - unique_table[lastreg - 1] = { value_table[lastreg - 1].name, detail::unique_destruct }; // Now use um const bool& mustindex = umc.mustindex; @@ -12304,7 +11598,7 @@ namespace sol { } } string_detail::string_shim accessor = stack::get(L, keyidx); - std::string accessorkey = accessor.data(); + std::string accessorkey = accessor.c_str(); auto vit = variables.find(accessorkey); if (vit != variables.cend()) { auto& varwrap = *(vit->second); @@ -12390,7 +11684,7 @@ namespace sol { #if defined(__clang__) return detail::trampoline(L, &simple_real_index_call); #else - return detail::typed_static_trampoline), (&simple_real_index_call)>(L); + return detail::static_trampoline<(&simple_real_index_call)>(L); #endif } @@ -12399,7 +11693,7 @@ namespace sol { #if defined(__clang__) return detail::trampoline(L, &simple_real_new_index_call); #else - return detail::typed_static_trampoline), (&simple_real_new_index_call)>(L); + return detail::static_trampoline<(&simple_real_new_index_call)>(L); #endif } } @@ -12501,7 +11795,7 @@ namespace sol { template void add(lua_State* L, N&& n, constructor_wrapper c) { - object o(L, in_place_type>>, std::move(c)); + object o(L, in_place>>, std::move(c)); if (std::is_same, call_construction>::value) { callconstructfunc = std::move(o); return; @@ -12511,7 +11805,7 @@ namespace sol { template void add(lua_State* L, N&& n, constructor_list c) { - object o(L, in_place_type>>, std::move(c)); + object o(L, in_place>>, std::move(c)); if (std::is_same, call_construction>::value) { callconstructfunc = std::move(o); return; @@ -12521,7 +11815,7 @@ namespace sol { template void add(lua_State* L, N&& n, destructor_wrapper c) { - object o(L, in_place_type>>, std::move(c)); + object o(L, in_place>>, std::move(c)); if (std::is_same, call_construction>::value) { callconstructfunc = std::move(o); return; @@ -12531,7 +11825,7 @@ namespace sol { template void add(lua_State* L, N&& n, destructor_wrapper c) { - object o(L, in_place_type>>, std::move(c)); + object o(L, in_place>>, std::move(c)); if (std::is_same, call_construction>::value) { callconstructfunc = std::move(o); return; @@ -12909,7 +12203,7 @@ namespace sol { template struct container_usertype_metatable { - typedef meta::is_associative>> is_associative; + typedef meta::has_key_value_pair> is_associative; typedef meta::unqualified_t T; typedef typename T::iterator I; typedef std::conditional_t> KV; @@ -12944,25 +12238,6 @@ namespace sol { #endif // Safe getting with error } - static int delegate_call(lua_State* L) { - static std::unordered_map calls{ - { "add", &real_add_call }, - { "insert", &real_insert_call }, - { "clear", &real_clear_call }, - { "find", &real_find_call }, - { "get", &real_get_call } - }; - auto maybename = stack::check_get(L, 2); - if (maybename) { - auto& name = *maybename; - auto it = calls.find(name); - if (it != calls.cend()) { - return stack::push(L, it->second); - } - } - return stack::push(L, lua_nil); - } - static int real_index_call_associative(std::true_type, lua_State* L) { auto k = stack::check_get(L, 2); if (k) { @@ -12974,7 +12249,25 @@ namespace sol { return stack::stack_detail::push_reference(L, v.second); } } - return delegate_call(L); + else { + auto maybename = stack::check_get(L, 2); + if (maybename) { + auto& name = *maybename; + if (name == "add") { + return stack::push(L, &add_call); + } + else if (name == "insert") { + return stack::push(L, &insert_call); + } + else if (name == "clear") { + return stack::push(L, &clear_call); + } + else if (name == "find") { + return stack::push(L, &find_call); + } + } + } + return stack::push(L, lua_nil); } static int real_index_call_associative(std::false_type, lua_State* L) { @@ -12991,17 +12284,32 @@ namespace sol { std::advance(it, k); return stack::stack_detail::push_reference(L, *it); } - return delegate_call(L); + else { + auto maybename = stack::check_get(L, 2); + if (maybename) { + auto& name = *maybename; + if (name == "add") { + return stack::push(L, &add_call); + } + else if (name == "insert") { + return stack::push(L, &insert_call); + } + else if (name == "clear") { + return stack::push(L, &clear_call); + } + else if (name == "find") { + return stack::push(L, &find_call); + } + } + } + + return stack::push(L, lua_nil); } static int real_index_call(lua_State* L) { return real_index_call_associative(is_associative(), L); } - static int real_get_call(lua_State* L) { - return real_index_call_associative(is_associative(), L); - } - static int real_new_index_call_const(std::false_type, std::false_type, lua_State* L) { return luaL_error(L, "sol: cannot write to a const value type or an immutable iterator (e.g., std::set)"); } @@ -13010,12 +12318,12 @@ namespace sol { return luaL_error(L, "sol: cannot write to a const value type or an immutable iterator (e.g., std::set)"); } - static int real_new_index_call_fixed(std::true_type, lua_State* L) { + static int real_new_index_call_const(std::true_type, std::true_type, lua_State* L) { auto& src = get_src(L); #ifdef SOL_CHECK_ARGUMENTS auto maybek = stack::check_get(L, 2); if (!maybek) { - return luaL_error(L, "sol: improper key of type %s for %s", lua_typename(L, static_cast(type_of(L, 2))), detail::demangle().c_str()); + return luaL_error(L, "sol: improper key of type %s to a %s", lua_typename(L, static_cast(type_of(L, 2))), detail::demangle().c_str()); } K& k = *maybek; #else @@ -13033,33 +12341,6 @@ namespace sol { return 0; } - static int real_new_index_call_fixed(std::false_type, lua_State* L) { - auto& src = get_src(L); -#ifdef SOL_CHECK_ARGUMENTS - auto maybek = stack::check_get(L, 2); - if (!maybek) { - return luaL_error(L, "sol: improper key of type %s for %s", lua_typename(L, static_cast(type_of(L, 2))), detail::demangle().c_str()); - } - K& k = *maybek; -#else - K k = stack::get(L, 2); -#endif - using std::end; - auto it = detail::find(src, k); - if (it != end(src)) { - auto& v = *it; - v.second = stack::get(L, 3); - } - else { - return luaL_error(L, "sol: cannot insert key of type %s to into %s", lua_typename(L, static_cast(type_of(L, 2))), detail::demangle().c_str()); - } - return 0; - } - - static int real_new_index_call_const(std::true_type, std::true_type, lua_State* L) { - return real_new_index_call_fixed(std::integral_constant::value>(), L); - } - static int real_new_index_call_const(std::true_type, std::false_type, lua_State* L) { auto& src = get_src(L); #ifdef SOL_CHECK_ARGUMENTS @@ -13094,7 +12375,7 @@ namespace sol { } static int real_new_index_call(lua_State* L) { - return real_new_index_call_const(meta::neg, std::is_const, meta::neg>>>(), meta::all>(), L); + return real_new_index_call_const(meta::neg, std::is_const, meta::neg>>>(), is_associative(), L); } static int real_pairs_next_call_assoc(std::true_type, lua_State* L) { @@ -13271,43 +12552,39 @@ namespace sol { } static int add_call(lua_State*L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_add_call)>(L); } static int insert_call(lua_State*L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_insert_call)>(L); } static int clear_call(lua_State*L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_clear_call)>(L); } static int find_call(lua_State*L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_find_call)>(L); } static int length_call(lua_State*L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_length_call)>(L); } static int pairs_next_call(lua_State*L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_pairs_next_call)>(L); } static int pairs_call(lua_State*L) { - return detail::typed_static_trampoline(L); - } - - static int get_call(lua_State*L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_pairs_call)>(L); } static int index_call(lua_State*L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_index_call)>(L); } static int new_index_call(lua_State*L) { - return detail::typed_static_trampoline(L); + return detail::static_trampoline<(&real_new_index_call)>(L); } }; @@ -13316,13 +12593,12 @@ namespace sol { template inline auto container_metatable() { typedef container_usertype_metatable> meta_cumt; - std::array reg = { { + std::array reg = { { { "__index", &meta_cumt::index_call }, { "__newindex", &meta_cumt::new_index_call }, { "__pairs", &meta_cumt::pairs_call }, { "__ipairs", &meta_cumt::pairs_call }, { "__len", &meta_cumt::length_call }, - { "get", &meta_cumt::get_call }, { "clear", &meta_cumt::clear_call }, { "insert", &meta_cumt::insert_call }, { "add", &meta_cumt::add_call }, @@ -13451,7 +12727,7 @@ namespace sol { template void set(N&& n, F&& f) { auto meta = static_cast*>(base_t::registrar_data()); - meta->add(state, std::forward(n), std::forward(f)); + meta->add(state, n, f); } }; @@ -14904,13 +14180,13 @@ namespace sol { optional maybetopmsg = stack::check_get(L, 1); if (maybetopmsg) { const string_detail::string_shim& topmsg = maybetopmsg.value(); - msg.assign(topmsg.data(), topmsg.size()); + msg.assign(topmsg.c_str(), topmsg.size()); } luaL_traceback(L, L, msg.c_str(), 1); optional maybetraceback = stack::check_get(L, -1); if (maybetraceback) { const string_detail::string_shim& traceback = maybetraceback.value(); - msg.assign(traceback.data(), traceback.size()); + msg.assign(traceback.c_str(), traceback.size()); } return stack::push(L, msg); } @@ -14922,7 +14198,6 @@ namespace sol { state(lua_CFunction panic = default_at_panic) : unique_base(luaL_newstate(), lua_close), state_view(unique_base::get()) { set_panic(panic); - sol::protected_function::set_default_handler(sol::object(lua_state(), in_place, default_error_handler)); stack::luajit_exception_handler(unique_base::get()); } @@ -15197,61 +14472,6 @@ namespace sol { // end of sol/coroutine.hpp -// beginning of sol/variadic_results.hpp - -// beginning of sol/as_returns.hpp - -namespace sol { - template - struct as_returns_t { - T src; - }; - - template - auto as_returns(Source&& source) { - return as_returns_t>{ std::forward(source) }; - } - - namespace stack { - template - struct pusher> { - int push(lua_State* L, const as_returns_t& e) { - auto& src = detail::unwrap(e.src); - int p = 0; - for (const auto& i : src) { - p += stack::push(L, i); - } - return p; - } - }; - } // stack -} // sol - -// end of sol/as_returns.hpp - -namespace sol { - - struct variadic_results : public std::vector { - using std::vector::vector; - }; - - namespace stack { - template <> - struct pusher { - int push(lua_State* L, const variadic_results& e) { - int p = 0; - for (const auto& i : e) { - p += stack::push(L, i); - } - return p; - } - }; - } // stack - -} // sol - -// end of sol/variadic_results.hpp - #ifdef __GNUC__ #pragma GCC diagnostic pop #elif defined _MSC_VER