// The MIT License (MIT) // Copyright (c) 2013-2018 Rapptz, ThePhD and contributors // Permission is hereby granted, free of charge, to any person obtaining a copy of // this software and associated documentation files (the "Software"), to deal in // the Software without restriction, including without limitation the rights to // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of // the Software, and to permit persons to whom the Software is furnished to do so, // subject to the following conditions: // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. // Generated 2018-12-22 20:32:28.534178 UTC // This header was generated with sol v2.20.6 (revision 88cafb2) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP #define SOL_SINGLE_INCLUDE_HPP // beginning of sol/sol.hpp #ifndef SOL_HPP #define SOL_HPP #if defined(UE_BUILD_DEBUG) || defined(UE_BUILD_DEVELOPMENT) || defined(UE_BUILD_TEST) || defined(UE_BUILD_SHIPPING) || defined(UE_SERVER) #define SOL_INSIDE_UNREAL 1 #endif // Unreal Engine 4 bullshit #if defined(SOL_INSIDE_UNREAL) && SOL_INSIDE_UNREAL #ifdef check #define SOL_INSIDE_UNREAL_REMOVED_CHECK 1 #undef check #endif #endif // Unreal Engine 4 Bullshit #if defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wshadow" #pragma GCC diagnostic ignored "-Wconversion" #if __GNUC__ > 6 #pragma GCC diagnostic ignored "-Wnoexcept-type" #endif #elif defined(__clang__) #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 #pragma warning(disable : 4127) // 'conditional expression is constant' yeah that's the point your old compilers don't have `if constexpr` you jerk #pragma warning(disable : 4505) // some other nonsense warning #endif // clang++ vs. g++ vs. VC++ // beginning of sol/forward.hpp #ifndef SOL_FORWARD_HPP #define 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) || (defined(_MSVC_LANG) && (_MSVC_LANG > 201402L)))) #ifndef SOL_CXX17_FEATURES #define SOL_CXX17_FEATURES 1 #endif // C++17 features macro #endif // C++17 features check #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES #if defined(__cpp_noexcept_function_type) || ((defined(_MSC_VER) && _MSC_VER > 1911) && (defined(_MSVC_LANG) && ((_MSVC_LANG >= 201403L)))) #ifndef SOL_NOEXCEPT_FUNCTION_TYPE #define SOL_NOEXCEPT_FUNCTION_TYPE 1 #endif // noexcept is part of a function's type #endif // compiler-specific checks #if defined(__clang__) && defined(__APPLE__) #if defined(__has_include) #if __has_include() #define SOL_STD_VARIANT 1 #endif // has include nonsense #endif // __has_include #else #define SOL_STD_VARIANT 1 #endif // Clang screws up variant #endif // C++17 only // beginning of sol/config.hpp #ifdef _MSC_VER #if defined(_DEBUG) && !defined(NDEBUG) #ifndef SOL_IN_DEBUG_DETECTED #define SOL_IN_DEBUG_DETECTED 1 #endif #endif // VC++ Debug macros #if !defined(_CPPUNWIND) #if !defined(SOL_NO_EXCEPTIONS) #define SOL_NO_EXCEPTIONS 1 #endif #endif // Automatic Exceptions #if !defined(_CPPRTTI) #if !defined(SOL_NO_RTTI) #define SOL_NO_RTTI 1 #endif #endif // Automatic RTTI #elif defined(__GNUC__) || defined(__clang__) #if !defined(NDEBUG) && !defined(__OPTIMIZE__) #if !defined(SOL_IN_DEBUG_DETECTED) #define SOL_IN_DEBUG_DETECTED 1 #endif #endif // Not Debug && g++ optimizer flag #if !defined(__EXCEPTIONS) #if !defined(SOL_NO_EXCEPTIONS) #define SOL_NO_EXCEPTIONS 1 #endif #endif // No Exceptions #if !defined(__GXX_RTTI) #if !defined(SOL_NO_RTTI) #define SOL_NO_RTTI 1 #endif #endif // No RTTI #endif // vc++ || clang++/g++ #if defined(SOL_CHECK_ARGUMENTS) && SOL_CHECK_ARGUMENTS // Checks low-level getter function // (and thusly, affects nearly entire framework) #if !defined(SOL_SAFE_GETTER) #define SOL_SAFE_GETTER 1 #endif // Checks access on usertype functions // local my_obj = my_type.new() // my_obj.my_member_function() // -- bad syntax and crash #if !defined(SOL_SAFE_USERTYPE) #define SOL_SAFE_USERTYPE 1 #endif // Checks sol::reference derived boundaries // sol::function ref(L, 1); // sol::userdata sref(L, 2); #if !defined(SOL_SAFE_REFERENCES) #define SOL_SAFE_REFERENCES 1 #endif // Changes all typedefs of sol::function to point to the // protected_function version, instead of unsafe_function #if !defined(SOL_SAFE_FUNCTION) #define SOL_SAFE_FUNCTION 1 #endif // Checks function parameters and // returns upon call into/from Lua // local a = 1 // local b = "woof" // my_c_function(a, b) #if !defined(SOL_SAFE_FUNCTION_CALLS) #define SOL_SAFE_FUNCTION_CALLS 1 #endif // Checks conversions // int v = lua["bark"]; // int v2 = my_sol_function(); #if !defined(SOL_SAFE_PROXIES) #define SOL_SAFE_PROXIES 1 #endif // Check overflowing number conversions // for things like 64 bit integers that don't fit in a typical lua_Number // for Lua 5.1 and 5.2 #if !defined(SOL_SAFE_NUMERICS) #define SOL_SAFE_NUMERICS 1 #endif // Turn off Number Precision Checks // if this is defined, we do not do range // checks on integers / unsigned integers that might // be bigger than what Lua can represent #if !defined(SOL_NO_CHECK_NUMBER_PRECISION) // off by default #define SOL_NO_CHECK_NUMBER_PRECISION 0 #endif // Print any exceptions / errors that occur // in debug mode to the default error stream / console #if !defined(SOL_SAFE_STACK_CHECK) #define SOL_SAFE_STACK_CHECK 1 #endif #endif // Turn on Safety for all if top-level macro is defined #if defined(SOL_IN_DEBUG_DETECTED) && SOL_IN_DEBUG_DETECTED #if !defined(SOL_SAFE_REFERENCES) // Ensure that references are forcefully type-checked upon construction #define SOL_SAFE_REFERENCES 1 #endif // Safe usertypes checks for errors such as // obj = my_type.new() // obj.f() -- note the '.' instead of ':' // usertypes should be safe no matter what #if !defined(SOL_SAFE_USERTYPE) #define SOL_SAFE_USERTYPE 1 #endif #if !defined(SOL_SAFE_FUNCTION_CALLS) // Function calls from Lua should be automatically safe in debug mode #define SOL_SAFE_FUNCTION_CALLS 1 #endif // Print any exceptions / errors that occur // in debug mode to the default error stream / console #if !defined(SOL_PRINT_ERRORS) #define SOL_PRINT_ERRORS 1 #endif // Print any exceptions / errors that occur // in debug mode to the default error stream / console #if !defined(SOL_SAFE_STACK_CHECK) #define SOL_SAFE_STACK_CHECK 1 #endif #endif // DEBUG: Turn on all debug safety features for VC++ / g++ / clang++ and similar #if !defined(SOL_PRINT_ERRORS) #define SOL_PRINT_ERRORS 0 #endif #if !defined(SOL_DEFAULT_PASS_ON_ERROR) #define SOL_DEFAULT_PASS_ON_ERROR 0 #endif #if !defined(SOL_ENABLE_INTEROP) #define SOL_ENABLE_INTEROP 0 #endif #if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) || defined(__OBJC__) || defined(nil) #if !defined(SOL_NO_NIL) #define SOL_NO_NIL 1 #endif #endif // avoiding nil defines / keywords #if defined(SOL_USE_BOOST) && SOL_USE_BOOST #if !defined(SOL_UNORDERED_MAP_COMPATIBLE_HASH) #define SOL_UNORDERED_MAP_COMPATIBLE_HASH 1 #endif // SOL_UNORDERED_MAP_COMPATIBLE_HASH #endif #ifndef SOL_STACK_STRING_OPTIMIZATION_SIZE #define SOL_STACK_STRING_OPTIMIZATION_SIZE 1024 #endif // Optimized conversion routines using a KB or so off the stack #if !defined(SOL_SAFE_STACK_CHECK) #define SOL_SAFE_STACK_CHECK 0 #endif // use luaL_checkstack to check stack overflow / overrun // end of sol/config.hpp // beginning of sol/config_setup.hpp // end of sol/config_setup.hpp // end of sol/feature_test.hpp #include #include namespace sol { template class basic_reference; using reference = basic_reference; using main_reference = basic_reference; class stack_reference; struct proxy_base_tag; template struct proxy_base; template struct proxy; template class basic_table_core; template using table_core = basic_table_core; template using main_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 main_table_core main_table; typedef main_table_core main_global_table; typedef stack_table_core stack_table; typedef stack_table_core stack_global_table; template class basic_usertype; template using usertype = basic_usertype; template using stack_usertype = basic_usertype; template class basic_metatable; using metatable = basic_metatable; using stack_metatable = basic_metatable; template struct basic_environment; using environment = basic_environment; using main_environment = basic_environment; using stack_environment = basic_environment; template class basic_function; template class basic_protected_function; using unsafe_function = basic_function; using safe_function = basic_protected_function; using main_unsafe_function = basic_function; using main_safe_function = basic_protected_function; using stack_unsafe_function = basic_function; using stack_safe_function = basic_protected_function; using stack_aligned_unsafe_function = basic_function; using stack_aligned_safe_function = basic_protected_function; using protected_function = safe_function; using main_protected_function = main_safe_function; using stack_protected_function = stack_safe_function; using stack_aligned_protected_function = stack_aligned_safe_function; #if defined(SOL_SAFE_FUNCTION) && SOL_SAFE_FUNCTION using function = protected_function; using main_function = main_protected_function; using stack_function = stack_protected_function; #else using function = unsafe_function; using main_function = main_unsafe_function; using stack_function = stack_unsafe_function; #endif using stack_aligned_function = stack_aligned_unsafe_function; using stack_aligned_stack_handler_function = basic_protected_function; struct unsafe_function_result; struct protected_function_result; using safe_function_result = protected_function_result; #if defined(SOL_SAFE_FUNCTION) && SOL_SAFE_FUNCTION using function_result = safe_function_result; #else using function_result = unsafe_function_result; #endif template class basic_object; template class basic_userdata; template class basic_lightuserdata; template class basic_coroutine; template class basic_thread; using object = basic_object; using userdata = basic_userdata; using lightuserdata = basic_lightuserdata; using thread = basic_thread; using coroutine = basic_coroutine; using main_object = basic_object; using main_userdata = basic_userdata; using main_lightuserdata = basic_lightuserdata; using main_coroutine = basic_coroutine; using stack_object = basic_object; using stack_userdata = basic_userdata; using stack_lightuserdata = basic_lightuserdata; using stack_thread = basic_thread; using stack_coroutine = basic_coroutine; struct stack_proxy_base; struct stack_proxy; struct variadic_args; struct variadic_results; struct stack_count; struct this_state; struct this_main_state; struct this_environment; template struct as_table_t; template struct as_container_t; template struct nested; template struct light; template struct user; template struct as_args_t; template struct protect_t; template struct filter_wrapper; template struct usertype_traits; template struct unique_usertype_traits; template struct types { typedef std::make_index_sequence indices; static constexpr std::size_t size() { return sizeof...(Args); } }; template struct derive : std::false_type { typedef types<> type; }; template struct base : std::false_type { typedef types<> type; }; template struct weak_derive { static bool value; }; template bool weak_derive::value = false; namespace stack { struct record; } } // namespace sol #define SOL_BASE_CLASSES(T, ...) \ namespace sol { \ template <> \ struct base : std::true_type { \ typedef ::sol::types<__VA_ARGS__> type; \ }; \ } \ void a_sol3_detail_function_decl_please_no_collide() #define SOL_DERIVED_CLASSES(T, ...) \ namespace sol { \ template <> \ struct derive : std::true_type { \ typedef ::sol::types<__VA_ARGS__> type; \ }; \ } \ void a_sol3_detail_function_decl_please_no_collide() #endif // SOL_FORWARD_HPP // end of sol/forward.hpp // beginning of sol/object.hpp // beginning of sol/make_reference.hpp // beginning of sol/reference.hpp // beginning of sol/types.hpp // beginning of sol/error.hpp // beginning of sol/compatibility.hpp // beginning of sol/compatibility/version.hpp #if defined(SOL_USING_CXX_LUA) && SOL_USING_CXX_LUA #include #include #include #if defined(SOL_USING_CXX_LUAJIT) && SOL_USING_CXX_LUAJIT #include #endif // C++ LuaJIT ... whatever that means #if (!defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) || !(SOL_EXCEPTIONS_SAFE_PROPAGATION)) && (!defined(SOL_EXCEPTIONS_ALWAYS_UNSAFE) || !(SOL_EXCEPTIONS_ALWAYS_UNSAFE)) #define SOL_EXCEPTIONS_SAFE_PROPAGATION 1 #endif // Exceptions can be propagated safely using C++-compiled Lua #else #include #endif // C++ Mangling for Lua #ifdef LUAJIT_VERSION #ifndef SOL_LUAJIT #define SOL_LUAJIT 1 #ifndef SOL_LUAJIT_VERSION #define SOL_LUAJIT_VERSION LUAJIT_VERSION_NUM #endif // SOL_LUAJIT_VERSION definition, if not present #endif // sol luajit #endif // luajit #if SOL_LUAJIT && SOL_LUAJIT_VERSION >= 20100 #if !defined(SOL_EXCEPTIONS_SAFE_PROPAGATION) && (!defined(SOL_EXCEPTIONS_ALWAYS_UNSAFE) && !(SOL_EXCEPTIONS_ALWAYS_UNSAFE)) #define SOL_EXCEPTIONS_SAFE_PROPAGATION 1 #endif // Do not catch (...) clauses #endif // LuaJIT beta 02.01.00 have better exception handling on all platforms since beta3 #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 502 #define SOL_LUA_VERSION LUA_VERSION_NUM #elif defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501 #define SOL_LUA_VERSION LUA_VERSION_NUM #elif !defined(LUA_VERSION_NUM) || !(LUA_VERSION_NUM) #define SOL_LUA_VERSION 500 #else #define SOL_LUA_VERSION 502 #endif // Lua Version 502, 501 || luajit, 500 // end of sol/compatibility/version.hpp #if !defined(SOL_NO_COMPAT) || !(SOL_NO_COMPAT) #if defined(SOL_USING_CXX_LUA) && SOL_USING_CXX_LUA #ifndef COMPAT53_LUA_CPP #define COMPAT53_LUA_CPP 1 #endif // Build Lua Compat layer as C++ #endif #ifndef COMPAT53_INCLUDE_SOURCE #define COMPAT53_INCLUDE_SOURCE 1 #endif // Build Compat Layer Inline // beginning of sol/compatibility/compat-5.3.h #ifndef KEPLER_PROJECT_COMPAT53_H_ #define KEPLER_PROJECT_COMPAT53_H_ #include #include #include #if defined(__cplusplus) && !defined(COMPAT53_LUA_CPP) extern "C" { #endif #if defined(__cplusplus) && !defined(COMPAT53_LUA_CPP) } #endif #ifndef COMPAT53_PREFIX /* we chose this name because many other lua bindings / libs have * their own compatibility layer, and that use the compat53 declaration * frequently, causing all kinds of linker / compiler issues */ # define COMPAT53_PREFIX kp_compat53 #endif // COMPAT53_PREFIX #ifndef COMPAT53_API # if defined(COMPAT53_INCLUDE_SOURCE) && COMPAT53_INCLUDE_SOURCE # if defined(__GNUC__) || defined(__clang__) # define COMPAT53_API __attribute__((__unused__)) static # else # define COMPAT53_API static # endif /* Clang/GCC */ # else /* COMPAT53_INCLUDE_SOURCE */ /* we are not including source, so everything is extern */ # define COMPAT53_API extern # endif /* COMPAT53_INCLUDE_SOURCE */ #endif /* COMPAT53_PREFIX */ #define COMPAT53_CONCAT_HELPER(a, b) a##b #define COMPAT53_CONCAT(a, b) COMPAT53_CONCAT_HELPER(a, b) /* declarations for Lua 5.1 */ #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501 /* XXX not implemented: * lua_arith (new operators) * lua_upvalueid * lua_upvaluejoin * lua_version * lua_yieldk */ #ifndef LUA_OK # define LUA_OK 0 #endif #ifndef LUA_OPADD # define LUA_OPADD 0 #endif #ifndef LUA_OPSUB # define LUA_OPSUB 1 #endif #ifndef LUA_OPMUL # define LUA_OPMUL 2 #endif #ifndef LUA_OPDIV # define LUA_OPDIV 3 #endif #ifndef LUA_OPMOD # define LUA_OPMOD 4 #endif #ifndef LUA_OPPOW # define LUA_OPPOW 5 #endif #ifndef LUA_OPUNM # define LUA_OPUNM 6 #endif #ifndef LUA_OPEQ # define LUA_OPEQ 0 #endif #ifndef LUA_OPLT # define LUA_OPLT 1 #endif #ifndef LUA_OPLE # define LUA_OPLE 2 #endif /* LuaJIT/Lua 5.1 does not have the updated * error codes for thread status/function returns (but some patched versions do) * define it only if it's not found */ #if !defined(LUA_ERRGCMM) /* Use + 2 because in some versions of Lua (Lua 5.1) * LUA_ERRFILE is defined as (LUA_ERRERR+1) * so we need to avoid it (LuaJIT might have something at this * integer value too) */ # define LUA_ERRGCMM (LUA_ERRERR + 2) #endif /* LUA_ERRGCMM define */ typedef size_t lua_Unsigned; typedef struct luaL_Buffer_53 { luaL_Buffer b; /* make incorrect code crash! */ char *ptr; size_t nelems; size_t capacity; lua_State *L2; } luaL_Buffer_53; #define luaL_Buffer luaL_Buffer_53 /* In PUC-Rio 5.1, userdata is a simple FILE* * In LuaJIT, it's a struct where the first member is a FILE* * We can't support the `closef` member */ typedef struct luaL_Stream { FILE *f; } luaL_Stream; #define lua_absindex COMPAT53_CONCAT(COMPAT53_PREFIX, _absindex) COMPAT53_API int lua_absindex(lua_State *L, int i); #define lua_arith COMPAT53_CONCAT(COMPAT53_PREFIX, _arith) COMPAT53_API void lua_arith(lua_State *L, int op); #define lua_compare COMPAT53_CONCAT(COMPAT53_PREFIX, _compare) COMPAT53_API int lua_compare(lua_State *L, int idx1, int idx2, int op); #define lua_copy COMPAT53_CONCAT(COMPAT53_PREFIX, _copy) COMPAT53_API void lua_copy(lua_State *L, int from, int to); #define lua_getuservalue(L, i) \ (lua_getfenv((L), (i)), lua_type((L), -1)) #define lua_setuservalue(L, i) \ (luaL_checktype((L), -1, LUA_TTABLE), lua_setfenv((L), (i))) #define lua_len COMPAT53_CONCAT(COMPAT53_PREFIX, _len) COMPAT53_API void lua_len(lua_State *L, int i); #define lua_pushstring(L, s) \ (lua_pushstring((L), (s)), lua_tostring((L), -1)) #define lua_pushlstring(L, s, len) \ ((((len) == 0) ? lua_pushlstring((L), "", 0) : lua_pushlstring((L), (s), (len))), lua_tostring((L), -1)) #ifndef luaL_newlibtable # define luaL_newlibtable(L, l) \ (lua_createtable((L), 0, sizeof((l))/sizeof(*(l))-1)) #endif #ifndef luaL_newlib # define luaL_newlib(L, l) \ (luaL_newlibtable((L), (l)), luaL_register((L), NULL, (l))) #endif #define lua_pushglobaltable(L) \ lua_pushvalue((L), LUA_GLOBALSINDEX) #define lua_rawgetp COMPAT53_CONCAT(COMPAT53_PREFIX, _rawgetp) COMPAT53_API int lua_rawgetp(lua_State *L, int i, const void *p); #define lua_rawsetp COMPAT53_CONCAT(COMPAT53_PREFIX, _rawsetp) COMPAT53_API void lua_rawsetp(lua_State *L, int i, const void *p); #define lua_rawlen(L, i) lua_objlen((L), (i)) #define lua_tointeger(L, i) lua_tointegerx((L), (i), NULL) #define lua_tonumberx COMPAT53_CONCAT(COMPAT53_PREFIX, _tonumberx) COMPAT53_API lua_Number lua_tonumberx(lua_State *L, int i, int *isnum); #define luaL_checkversion COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkversion) COMPAT53_API void luaL_checkversion(lua_State *L); #define lua_load COMPAT53_CONCAT(COMPAT53_PREFIX, _load_53) COMPAT53_API int lua_load(lua_State *L, lua_Reader reader, void *data, const char* source, const char* mode); #define luaL_loadfilex COMPAT53_CONCAT(COMPAT53_PREFIX, L_loadfilex) COMPAT53_API int luaL_loadfilex(lua_State *L, const char *filename, const char *mode); #define luaL_loadbufferx COMPAT53_CONCAT(COMPAT53_PREFIX, L_loadbufferx) COMPAT53_API int luaL_loadbufferx(lua_State *L, const char *buff, size_t sz, const char *name, const char *mode); #define luaL_checkstack COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkstack_53) COMPAT53_API void luaL_checkstack(lua_State *L, int sp, const char *msg); #define luaL_getsubtable COMPAT53_CONCAT(COMPAT53_PREFIX, L_getsubtable) COMPAT53_API int luaL_getsubtable(lua_State* L, int i, const char *name); #define luaL_len COMPAT53_CONCAT(COMPAT53_PREFIX, L_len) COMPAT53_API lua_Integer luaL_len(lua_State *L, int i); #define luaL_setfuncs COMPAT53_CONCAT(COMPAT53_PREFIX, L_setfuncs) COMPAT53_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup); #define luaL_setmetatable COMPAT53_CONCAT(COMPAT53_PREFIX, L_setmetatable) COMPAT53_API void luaL_setmetatable(lua_State *L, const char *tname); #define luaL_testudata COMPAT53_CONCAT(COMPAT53_PREFIX, L_testudata) COMPAT53_API void *luaL_testudata(lua_State *L, int i, const char *tname); #define luaL_traceback COMPAT53_CONCAT(COMPAT53_PREFIX, L_traceback) COMPAT53_API void luaL_traceback(lua_State *L, lua_State *L1, const char *msg, int level); #define luaL_fileresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_fileresult) COMPAT53_API int luaL_fileresult(lua_State *L, int stat, const char *fname); #define luaL_execresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_execresult) COMPAT53_API int luaL_execresult(lua_State *L, int stat); #define lua_callk(L, na, nr, ctx, cont) \ ((void)(ctx), (void)(cont), lua_call((L), (na), (nr))) #define lua_pcallk(L, na, nr, err, ctx, cont) \ ((void)(ctx), (void)(cont), lua_pcall((L), (na), (nr), (err))) #define lua_resume(L, from, nargs) \ ((void)(from), lua_resume((L), (nargs))) #define luaL_buffinit COMPAT53_CONCAT(COMPAT53_PREFIX, _buffinit_53) COMPAT53_API void luaL_buffinit(lua_State *L, luaL_Buffer_53 *B); #define luaL_prepbuffsize COMPAT53_CONCAT(COMPAT53_PREFIX, _prepbufsize_53) COMPAT53_API char *luaL_prepbuffsize(luaL_Buffer_53 *B, size_t s); #define luaL_addlstring COMPAT53_CONCAT(COMPAT53_PREFIX, _addlstring_53) COMPAT53_API void luaL_addlstring(luaL_Buffer_53 *B, const char *s, size_t l); #define luaL_addvalue COMPAT53_CONCAT(COMPAT53_PREFIX, _addvalue_53) COMPAT53_API void luaL_addvalue(luaL_Buffer_53 *B); #define luaL_pushresult COMPAT53_CONCAT(COMPAT53_PREFIX, _pushresult_53) COMPAT53_API void luaL_pushresult(luaL_Buffer_53 *B); #undef luaL_buffinitsize #define luaL_buffinitsize(L, B, s) \ (luaL_buffinit((L), (B)), luaL_prepbuffsize((B), (s))) #undef luaL_prepbuffer #define luaL_prepbuffer(B) \ luaL_prepbuffsize((B), LUAL_BUFFERSIZE) #undef luaL_addchar #define luaL_addchar(B, c) \ ((void)((B)->nelems < (B)->capacity || luaL_prepbuffsize((B), 1)), \ ((B)->ptr[(B)->nelems++] = (c))) #undef luaL_addsize #define luaL_addsize(B, s) \ ((B)->nelems += (s)) #undef luaL_addstring #define luaL_addstring(B, s) \ luaL_addlstring((B), (s), strlen((s))) #undef luaL_pushresultsize #define luaL_pushresultsize(B, s) \ (luaL_addsize((B), (s)), luaL_pushresult((B))) #if defined(LUA_COMPAT_APIINTCASTS) #define lua_pushunsigned(L, n) \ lua_pushinteger((L), (lua_Integer)(n)) #define lua_tounsignedx(L, i, is) \ ((lua_Unsigned)lua_tointegerx((L), (i), (is))) #define lua_tounsigned(L, i) \ lua_tounsignedx((L), (i), NULL) #define luaL_checkunsigned(L, a) \ ((lua_Unsigned)luaL_checkinteger((L), (a))) #define luaL_optunsigned(L, a, d) \ ((lua_Unsigned)luaL_optinteger((L), (a), (lua_Integer)(d))) #endif #endif /* Lua 5.1 only */ /* declarations for Lua 5.1 and 5.2 */ #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM <= 502 typedef int lua_KContext; typedef int(*lua_KFunction)(lua_State *L, int status, lua_KContext ctx); #define lua_dump(L, w, d, s) \ ((void)(s), lua_dump((L), (w), (d))) #define lua_getfield(L, i, k) \ (lua_getfield((L), (i), (k)), lua_type((L), -1)) #define lua_gettable(L, i) \ (lua_gettable((L), (i)), lua_type((L), -1)) #define lua_geti COMPAT53_CONCAT(COMPAT53_PREFIX, _geti) COMPAT53_API int lua_geti(lua_State *L, int index, lua_Integer i); #define lua_isinteger COMPAT53_CONCAT(COMPAT53_PREFIX, _isinteger) COMPAT53_API int lua_isinteger(lua_State *L, int index); #define lua_tointegerx COMPAT53_CONCAT(COMPAT53_PREFIX, _tointegerx_53) COMPAT53_API lua_Integer lua_tointegerx(lua_State *L, int i, int *isnum); #define lua_numbertointeger(n, p) \ ((*(p) = (lua_Integer)(n)), 1) #define lua_rawget(L, i) \ (lua_rawget((L), (i)), lua_type((L), -1)) #define lua_rawgeti(L, i, n) \ (lua_rawgeti((L), (i), (n)), lua_type((L), -1)) #define lua_rotate COMPAT53_CONCAT(COMPAT53_PREFIX, _rotate) COMPAT53_API void lua_rotate(lua_State *L, int idx, int n); #define lua_seti COMPAT53_CONCAT(COMPAT53_PREFIX, _seti) COMPAT53_API void lua_seti(lua_State *L, int index, lua_Integer i); #define lua_stringtonumber COMPAT53_CONCAT(COMPAT53_PREFIX, _stringtonumber) COMPAT53_API size_t lua_stringtonumber(lua_State *L, const char *s); #define luaL_tolstring COMPAT53_CONCAT(COMPAT53_PREFIX, L_tolstring) COMPAT53_API const char *luaL_tolstring(lua_State *L, int idx, size_t *len); #define luaL_getmetafield(L, o, e) \ (luaL_getmetafield((L), (o), (e)) ? lua_type((L), -1) : LUA_TNIL) #define luaL_newmetatable(L, tn) \ (luaL_newmetatable((L), (tn)) ? (lua_pushstring((L), (tn)), lua_setfield((L), -2, "__name"), 1) : 0) #define luaL_requiref COMPAT53_CONCAT(COMPAT53_PREFIX, L_requiref_53) COMPAT53_API void luaL_requiref(lua_State *L, const char *modname, lua_CFunction openf, int glb); #endif /* Lua 5.1 and Lua 5.2 */ /* declarations for Lua 5.2 */ #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 502 /* XXX not implemented: * lua_isyieldable * lua_getextraspace * lua_arith (new operators) * lua_pushfstring (new formats) */ #define lua_getglobal(L, n) \ (lua_getglobal((L), (n)), lua_type((L), -1)) #define lua_getuservalue(L, i) \ (lua_getuservalue((L), (i)), lua_type((L), -1)) #define lua_pushlstring(L, s, len) \ (((len) == 0) ? lua_pushlstring((L), "", 0) : lua_pushlstring((L), (s), (len))) #define lua_rawgetp(L, i, p) \ (lua_rawgetp((L), (i), (p)), lua_type((L), -1)) #define LUA_KFUNCTION(_name) \ static int (_name)(lua_State *L, int status, lua_KContext ctx); \ static int (_name ## _52)(lua_State *L) { \ lua_KContext ctx; \ int status = lua_getctx(L, &ctx); \ return (_name)(L, status, ctx); \ } \ static int (_name)(lua_State *L, int status, lua_KContext ctx) #define lua_pcallk(L, na, nr, err, ctx, cont) \ lua_pcallk((L), (na), (nr), (err), (ctx), cont ## _52) #define lua_callk(L, na, nr, ctx, cont) \ lua_callk((L), (na), (nr), (ctx), cont ## _52) #define lua_yieldk(L, nr, ctx, cont) \ lua_yieldk((L), (nr), (ctx), cont ## _52) #ifdef lua_call # undef lua_call # define lua_call(L, na, nr) \ (lua_callk)((L), (na), (nr), 0, NULL) #endif #ifdef lua_pcall # undef lua_pcall # define lua_pcall(L, na, nr, err) \ (lua_pcallk)((L), (na), (nr), (err), 0, NULL) #endif #ifdef lua_yield # undef lua_yield # define lua_yield(L, nr) \ (lua_yieldk)((L), (nr), 0, NULL) #endif #endif /* Lua 5.2 only */ /* other Lua versions */ #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501 || LUA_VERSION_NUM > 504 # error "unsupported Lua version (i.e. not Lua 5.1, 5.2, or 5.3)" #endif /* other Lua versions except 5.1, 5.2, and 5.3 */ /* helper macro for defining continuation functions (for every version * *except* Lua 5.2) */ #ifndef LUA_KFUNCTION #define LUA_KFUNCTION(_name) \ static int (_name)(lua_State *L, int status, lua_KContext ctx) #endif #if defined(COMPAT53_INCLUDE_SOURCE) && COMPAT53_INCLUDE_SOURCE == 1 // beginning of sol/compatibility/compat-5.3.c #include #include #include #include /* don't compile it again if it already is included via compat53.h */ #ifndef KEPLER_PROJECT_COMPAT53_C_ #define KEPLER_PROJECT_COMPAT53_C_ /* definitions for Lua 5.1 only */ #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501 #ifndef COMPAT53_FOPEN_NO_LOCK # if defined(_MSC_VER) # define COMPAT53_FOPEN_NO_LOCK 1 # else /* otherwise */ # define COMPAT53_FOPEN_NO_LOCK 0 # endif /* VC++ only so far */ #endif /* No-lock fopen_s usage if possible */ #if defined(_MSC_VER) && COMPAT53_FOPEN_NO_LOCK # include #endif /* VC++ _fsopen for share-allowed file read */ #ifndef COMPAT53_HAVE_STRERROR_R # if defined(__GLIBC__) || defined(_POSIX_VERSION) || defined(__APPLE__) || \ (!defined (__MINGW32__) && defined(__GNUC__) && (__GNUC__ < 6)) # define COMPAT53_HAVE_STRERROR_R 1 # else /* none of the defines matched: define to 0 */ # define COMPAT53_HAVE_STRERROR_R 0 # endif /* have strerror_r of some form */ #endif /* strerror_r */ #ifndef COMPAT53_HAVE_STRERROR_S # if defined(_MSC_VER) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \ (defined(__STDC_LIB_EXT1__) && __STDC_LIB_EXT1__) # define COMPAT53_HAVE_STRERROR_S 1 # else /* not VC++ or C11 */ # define COMPAT53_HAVE_STRERROR_S 0 # endif /* strerror_s from VC++ or C11 */ #endif /* strerror_s */ #ifndef COMPAT53_LUA_FILE_BUFFER_SIZE # define COMPAT53_LUA_FILE_BUFFER_SIZE 4096 #endif /* Lua File Buffer Size */ static char* compat53_strerror(int en, char* buff, size_t sz) { #if COMPAT53_HAVE_STRERROR_R /* use strerror_r here, because it's available on these specific platforms */ if (sz > 0) { buff[0] = '\0'; /* we don't care whether the GNU version or the XSI version is used: */ if (strerror_r(en, buff, sz)) { /* Yes, we really DO want to ignore the return value! * GCC makes that extra hard, not even a (void) cast will do. */ } if (buff[0] == '\0') { /* Buffer is unchanged, so we probably have called GNU strerror_r which * returned a static constant string. Chances are that strerror will * return the same static constant string and therefore be thread-safe. */ return strerror(en); } } return buff; /* sz is 0 *or* strerror_r wrote into the buffer */ #elif COMPAT53_HAVE_STRERROR_S /* for MSVC and other C11 implementations, use strerror_s since it's * provided by default by the libraries */ strerror_s(buff, sz, en); return buff; #else /* fallback, but strerror is not guaranteed to be threadsafe due to modifying * errno itself and some impls not locking a static buffer for it ... but most * known systems have threadsafe errno: this might only change if the locale * is changed out from under someone while this function is being called */ (void)buff; (void)sz; return strerror(en); #endif } COMPAT53_API int lua_absindex(lua_State *L, int i) { if (i < 0 && i > LUA_REGISTRYINDEX) i += lua_gettop(L) + 1; return i; } static void compat53_call_lua(lua_State *L, char const code[], size_t len, int nargs, int nret) { lua_rawgetp(L, LUA_REGISTRYINDEX, (void*)code); if (lua_type(L, -1) != LUA_TFUNCTION) { lua_pop(L, 1); if (luaL_loadbuffer(L, code, len, "=none")) lua_error(L); lua_pushvalue(L, -1); lua_rawsetp(L, LUA_REGISTRYINDEX, (void*)code); } lua_insert(L, -nargs - 1); lua_call(L, nargs, nret); } static const char compat53_arith_code[] = "local op,a,b=...\n" "if op==0 then return a+b\n" "elseif op==1 then return a-b\n" "elseif op==2 then return a*b\n" "elseif op==3 then return a/b\n" "elseif op==4 then return a%b\n" "elseif op==5 then return a^b\n" "elseif op==6 then return -a\n" "end\n"; COMPAT53_API void lua_arith(lua_State *L, int op) { if (op < LUA_OPADD || op > LUA_OPUNM) luaL_error(L, "invalid 'op' argument for lua_arith"); luaL_checkstack(L, 5, "not enough stack slots"); if (op == LUA_OPUNM) lua_pushvalue(L, -1); lua_pushnumber(L, op); lua_insert(L, -3); compat53_call_lua(L, compat53_arith_code, sizeof(compat53_arith_code) - 1, 3, 1); } static const char compat53_compare_code[] = "local a,b=...\n" "return a<=b\n"; COMPAT53_API int lua_compare(lua_State *L, int idx1, int idx2, int op) { int result = 0; switch (op) { case LUA_OPEQ: return lua_equal(L, idx1, idx2); case LUA_OPLT: return lua_lessthan(L, idx1, idx2); case LUA_OPLE: luaL_checkstack(L, 5, "not enough stack slots"); idx1 = lua_absindex(L, idx1); idx2 = lua_absindex(L, idx2); lua_pushvalue(L, idx1); lua_pushvalue(L, idx2); compat53_call_lua(L, compat53_compare_code, sizeof(compat53_compare_code) - 1, 2, 1); result = lua_toboolean(L, -1); lua_pop(L, 1); return result; default: luaL_error(L, "invalid 'op' argument for lua_compare"); } return 0; } COMPAT53_API 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"); lua_pushvalue(L, from); lua_replace(L, abs_to); } COMPAT53_API void lua_len(lua_State *L, int i) { switch (lua_type(L, i)) { case LUA_TSTRING: lua_pushnumber(L, (lua_Number)lua_objlen(L, i)); break; case LUA_TTABLE: if (!luaL_callmeta(L, i, "__len")) lua_pushnumber(L, (lua_Number)lua_objlen(L, i)); break; case LUA_TUSERDATA: if (luaL_callmeta(L, i, "__len")) break; /* FALLTHROUGH */ default: luaL_error(L, "attempt to get length of a %s value", lua_typename(L, lua_type(L, i))); } } COMPAT53_API int lua_rawgetp(lua_State *L, int i, const void *p) { int abs_i = lua_absindex(L, i); lua_pushlightuserdata(L, (void*)p); lua_rawget(L, abs_i); return lua_type(L, -1); } COMPAT53_API void lua_rawsetp(lua_State *L, int i, const void *p) { int abs_i = lua_absindex(L, i); luaL_checkstack(L, 1, "not enough stack slots"); lua_pushlightuserdata(L, (void*)p); lua_insert(L, -2); lua_rawset(L, abs_i); } COMPAT53_API 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; } COMPAT53_API void luaL_checkversion(lua_State *L) { (void)L; } COMPAT53_API void luaL_checkstack(lua_State *L, int sp, const char *msg) { if (!lua_checkstack(L, sp + LUA_MINSTACK)) { if (msg != NULL) luaL_error(L, "stack overflow (%s)", msg); else { lua_pushliteral(L, "stack overflow"); lua_error(L); } } } COMPAT53_API 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"); lua_pushstring(L, name); lua_gettable(L, abs_i); if (lua_istable(L, -1)) return 1; lua_pop(L, 1); lua_newtable(L); lua_pushstring(L, name); lua_pushvalue(L, -2); lua_settable(L, abs_i); return 0; } COMPAT53_API lua_Integer luaL_len(lua_State *L, int i) { lua_Integer res = 0; int isnum = 0; luaL_checkstack(L, 1, "not enough stack slots"); lua_len(L, i); res = lua_tointegerx(L, -1, &isnum); lua_pop(L, 1); if (!isnum) luaL_error(L, "object length is not an integer"); return res; } COMPAT53_API 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 */ } COMPAT53_API 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); } COMPAT53_API 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; } static int compat53_countlevels(lua_State *L) { lua_Debug ar; int li = 1, le = 1; /* find an upper bound */ while (lua_getstack(L, le, &ar)) { li = le; le *= 2; } /* do a binary search */ while (li < le) { int m = (li + le) / 2; if (lua_getstack(L, m, &ar)) li = m + 1; else le = m; } return le - 1; } static int compat53_findfield(lua_State *L, int objidx, int level) { if (level == 0 || !lua_istable(L, -1)) return 0; /* not found */ lua_pushnil(L); /* start 'next' loop */ while (lua_next(L, -2)) { /* for each pair in table */ if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */ if (lua_rawequal(L, objidx, -1)) { /* found object? */ lua_pop(L, 1); /* remove value (but keep name) */ return 1; } else if (compat53_findfield(L, objidx, level - 1)) { /* try recursively */ lua_remove(L, -2); /* remove table (but keep name) */ lua_pushliteral(L, "."); lua_insert(L, -2); /* place '.' between the two names */ lua_concat(L, 3); return 1; } } lua_pop(L, 1); /* remove value */ } return 0; /* not found */ } static int compat53_pushglobalfuncname(lua_State *L, lua_Debug *ar) { int top = lua_gettop(L); lua_getinfo(L, "f", ar); /* push function */ lua_pushvalue(L, LUA_GLOBALSINDEX); if (compat53_findfield(L, top + 1, 2)) { lua_copy(L, -1, top + 1); /* move name to proper place */ lua_pop(L, 2); /* remove pushed values */ return 1; } else { lua_settop(L, top); /* remove function and global table */ return 0; } } static void compat53_pushfuncname(lua_State *L, lua_Debug *ar) { if (*ar->namewhat != '\0') /* is there a name? */ lua_pushfstring(L, "function " LUA_QS, ar->name); else if (*ar->what == 'm') /* main? */ lua_pushliteral(L, "main chunk"); else if (*ar->what == 'C') { if (compat53_pushglobalfuncname(L, ar)) { lua_pushfstring(L, "function " LUA_QS, lua_tostring(L, -1)); lua_remove(L, -2); /* remove name */ } else lua_pushliteral(L, "?"); } else lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined); } #define COMPAT53_LEVELS1 12 /* size of the first part of the stack */ #define COMPAT53_LEVELS2 10 /* size of the second part of the stack */ COMPAT53_API void luaL_traceback(lua_State *L, lua_State *L1, const char *msg, int level) { lua_Debug ar; int top = lua_gettop(L); int numlevels = compat53_countlevels(L1); int mark = (numlevels > COMPAT53_LEVELS1 + COMPAT53_LEVELS2) ? COMPAT53_LEVELS1 : 0; if (msg) lua_pushfstring(L, "%s\n", msg); lua_pushliteral(L, "stack traceback:"); while (lua_getstack(L1, level++, &ar)) { if (level == mark) { /* too many levels? */ lua_pushliteral(L, "\n\t..."); /* add a '...' */ level = numlevels - COMPAT53_LEVELS2; /* and skip to last ones */ } else { lua_getinfo(L1, "Slnt", &ar); lua_pushfstring(L, "\n\t%s:", ar.short_src); if (ar.currentline > 0) lua_pushfstring(L, "%d:", ar.currentline); lua_pushliteral(L, " in "); compat53_pushfuncname(L, &ar); lua_concat(L, lua_gettop(L) - top); } } lua_concat(L, lua_gettop(L) - top); } COMPAT53_API int luaL_fileresult(lua_State *L, int stat, const char *fname) { const char *serr = NULL; int en = errno; /* calls to Lua API may change this value */ char buf[512] = { 0 }; if (stat) { lua_pushboolean(L, 1); return 1; } else { lua_pushnil(L); serr = compat53_strerror(en, buf, sizeof(buf)); if (fname) lua_pushfstring(L, "%s: %s", fname, serr); else lua_pushstring(L, serr); lua_pushnumber(L, (lua_Number)en); return 3; } } static int compat53_checkmode(lua_State *L, const char *mode, const char *modename, int err) { if (mode && strchr(mode, modename[0]) == NULL) { lua_pushfstring(L, "attempt to load a %s chunk (mode is '%s')", modename, mode); return err; } return LUA_OK; } typedef struct { lua_Reader reader; void *ud; int has_peeked_data; const char *peeked_data; size_t peeked_data_size; } compat53_reader_data; static const char *compat53_reader(lua_State *L, void *ud, size_t *size) { compat53_reader_data *data = (compat53_reader_data *)ud; if (data->has_peeked_data) { data->has_peeked_data = 0; *size = data->peeked_data_size; return data->peeked_data; } else return data->reader(L, data->ud, size); } COMPAT53_API int lua_load(lua_State *L, lua_Reader reader, void *data, const char *source, const char *mode) { int status = LUA_OK; compat53_reader_data compat53_data = { reader, data, 1, 0, 0 }; compat53_data.peeked_data = reader(L, data, &(compat53_data.peeked_data_size)); if (compat53_data.peeked_data && compat53_data.peeked_data_size && compat53_data.peeked_data[0] == LUA_SIGNATURE[0]) /* binary file? */ status = compat53_checkmode(L, mode, "binary", LUA_ERRSYNTAX); else status = compat53_checkmode(L, mode, "text", LUA_ERRSYNTAX); if (status != LUA_OK) return status; /* we need to call the original 5.1 version of lua_load! */ #undef lua_load return lua_load(L, compat53_reader, &compat53_data, source); #define lua_load COMPAT53_CONCAT(COMPAT53_PREFIX, _load_53) } typedef struct { int n; /* number of pre-read characters */ FILE *f; /* file being read */ char buff[COMPAT53_LUA_FILE_BUFFER_SIZE]; /* area for reading file */ } compat53_LoadF; static const char *compat53_getF(lua_State *L, void *ud, size_t *size) { compat53_LoadF *lf = (compat53_LoadF *)ud; (void)L; /* not used */ if (lf->n > 0) { /* are there pre-read characters to be read? */ *size = lf->n; /* return them (chars already in buffer) */ lf->n = 0; /* no more pre-read characters */ } else { /* read a block from file */ /* 'fread' can return > 0 *and* set the EOF flag. If next call to 'compat53_getF' called 'fread', it might still wait for user input. The next check avoids this problem. */ if (feof(lf->f)) return NULL; *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); /* read block */ } return lf->buff; } static int compat53_errfile(lua_State *L, const char *what, int fnameindex) { char buf[512] = { 0 }; const char *serr = compat53_strerror(errno, buf, sizeof(buf)); const char *filename = lua_tostring(L, fnameindex) + 1; lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr); lua_remove(L, fnameindex); return LUA_ERRFILE; } static int compat53_skipBOM(compat53_LoadF *lf) { const char *p = "\xEF\xBB\xBF"; /* UTF-8 BOM mark */ int c; lf->n = 0; do { c = getc(lf->f); if (c == EOF || c != *(const unsigned char *)p++) return c; lf->buff[lf->n++] = (char)c; /* to be read by the parser */ } while (*p != '\0'); lf->n = 0; /* prefix matched; discard it */ return getc(lf->f); /* return next character */ } /* ** reads the first character of file 'f' and skips an optional BOM mark ** in its beginning plus its first line if it starts with '#'. Returns ** true if it skipped the first line. In any case, '*cp' has the ** first "valid" character of the file (after the optional BOM and ** a first-line comment). */ static int compat53_skipcomment(compat53_LoadF *lf, int *cp) { int c = *cp = compat53_skipBOM(lf); if (c == '#') { /* first line is a comment (Unix exec. file)? */ do { /* skip first line */ c = getc(lf->f); } while (c != EOF && c != '\n'); *cp = getc(lf->f); /* skip end-of-line, if present */ return 1; /* there was a comment */ } else return 0; /* no comment */ } COMPAT53_API int luaL_loadfilex(lua_State *L, const char *filename, const char *mode) { compat53_LoadF lf; int status, readstatus; int c; int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ if (filename == NULL) { lua_pushliteral(L, "=stdin"); lf.f = stdin; } else { lua_pushfstring(L, "@%s", filename); #if defined(_MSC_VER) /* This code is here to stop a deprecation error that stops builds * if a certain macro is defined. While normally not caring would * be best, some header-only libraries and builds can't afford to * dictate this to the user. A quick check shows that fopen_s this * goes back to VS 2005, and _fsopen goes back to VS 2003 .NET, * possibly even before that so we don't need to do any version * number checks, since this has been there since forever. */ /* TO USER: if you want the behavior of typical fopen_s/fopen, * which does lock the file on VC++, define the macro used below to 0 */ #if COMPAT53_FOPEN_NO_LOCK lf.f = _fsopen(filename, "r", _SH_DENYNO); /* do not lock the file in any way */ if (lf.f == NULL) return compat53_errfile(L, "open", fnameindex); #else /* use default locking version */ if (fopen_s(&lf.f, filename, "r") != 0) return compat53_errfile(L, "open", fnameindex); #endif /* Locking vs. No-locking fopen variants */ #else lf.f = fopen(filename, "r"); /* default stdlib doesn't forcefully lock files here */ if (lf.f == NULL) return compat53_errfile(L, "open", fnameindex); #endif } if (compat53_skipcomment(&lf, &c)) /* read initial portion */ lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */ if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ #if defined(_MSC_VER) if (freopen_s(&lf.f, filename, "rb", lf.f) != 0) return compat53_errfile(L, "reopen", fnameindex); #else lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ if (lf.f == NULL) return compat53_errfile(L, "reopen", fnameindex); #endif compat53_skipcomment(&lf, &c); /* re-read initial portion */ } if (c != EOF) lf.buff[lf.n++] = (char)c; /* 'c' is the first character of the stream */ status = lua_load(L, &compat53_getF, &lf, lua_tostring(L, -1), mode); readstatus = ferror(lf.f); if (filename) fclose(lf.f); /* close file (even in case of errors) */ if (readstatus) { lua_settop(L, fnameindex); /* ignore results from 'lua_load' */ return compat53_errfile(L, "read", fnameindex); } lua_remove(L, fnameindex); return status; } COMPAT53_API int luaL_loadbufferx(lua_State *L, const char *buff, size_t sz, const char *name, const char *mode) { int status = LUA_OK; if (sz > 0 && buff[0] == LUA_SIGNATURE[0]) { status = compat53_checkmode(L, mode, "binary", LUA_ERRSYNTAX); } else { status = compat53_checkmode(L, mode, "text", LUA_ERRSYNTAX); } if (status != LUA_OK) return status; return luaL_loadbuffer(L, buff, sz, name); } #if !defined(l_inspectstat) && \ (defined(unix) || defined(__unix) || defined(__unix__) || \ defined(__TOS_AIX__) || defined(_SYSTYPE_BSD) || \ (defined(__APPLE__) && defined(__MACH__))) /* some form of unix; check feature macros in unistd.h for details */ # include /* check posix version; the relevant include files and macros probably * were available before 2001, but I'm not sure */ # if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L # include # define l_inspectstat(stat,what) \ if (WIFEXITED(stat)) { stat = WEXITSTATUS(stat); } \ else if (WIFSIGNALED(stat)) { stat = WTERMSIG(stat); what = "signal"; } # endif #endif /* provide default (no-op) version */ #if !defined(l_inspectstat) # define l_inspectstat(stat,what) ((void)0) #endif COMPAT53_API int luaL_execresult(lua_State *L, int stat) { const char *what = "exit"; if (stat == -1) return luaL_fileresult(L, 0, NULL); else { l_inspectstat(stat, what); if (*what == 'e' && stat == 0) lua_pushboolean(L, 1); else lua_pushnil(L); lua_pushstring(L, what); lua_pushinteger(L, stat); return 3; } } COMPAT53_API void luaL_buffinit(lua_State *L, luaL_Buffer_53 *B) { /* make it crash if used via pointer to a 5.1-style luaL_Buffer */ B->b.p = NULL; B->b.L = NULL; B->b.lvl = 0; /* reuse the buffer from the 5.1-style luaL_Buffer though! */ B->ptr = B->b.buffer; B->capacity = LUAL_BUFFERSIZE; B->nelems = 0; B->L2 = L; } COMPAT53_API char *luaL_prepbuffsize(luaL_Buffer_53 *B, size_t s) { if (B->capacity - B->nelems < s) { /* needs to grow */ char* newptr = NULL; size_t newcap = B->capacity * 2; if (newcap - B->nelems < s) newcap = B->nelems + s; if (newcap < B->capacity) /* overflow */ luaL_error(B->L2, "buffer too large"); newptr = (char*)lua_newuserdata(B->L2, newcap); memcpy(newptr, B->ptr, B->nelems); if (B->ptr != B->b.buffer) lua_replace(B->L2, -2); /* remove old buffer */ B->ptr = newptr; B->capacity = newcap; } return B->ptr + B->nelems; } COMPAT53_API void luaL_addlstring(luaL_Buffer_53 *B, const char *s, size_t l) { memcpy(luaL_prepbuffsize(B, l), s, l); luaL_addsize(B, l); } COMPAT53_API void luaL_addvalue(luaL_Buffer_53 *B) { size_t len = 0; const char *s = lua_tolstring(B->L2, -1, &len); if (!s) luaL_error(B->L2, "cannot convert value to string"); if (B->ptr != B->b.buffer) lua_insert(B->L2, -2); /* userdata buffer must be at stack top */ luaL_addlstring(B, s, len); lua_remove(B->L2, B->ptr != B->b.buffer ? -2 : -1); } void luaL_pushresult(luaL_Buffer_53 *B) { lua_pushlstring(B->L2, B->ptr, B->nelems); if (B->ptr != B->b.buffer) lua_replace(B->L2, -2); /* remove userdata buffer */ } #endif /* Lua 5.1 */ /* definitions for Lua 5.1 and Lua 5.2 */ #if defined( LUA_VERSION_NUM ) && LUA_VERSION_NUM <= 502 COMPAT53_API int lua_geti(lua_State *L, int index, lua_Integer i) { index = lua_absindex(L, index); lua_pushinteger(L, i); lua_gettable(L, index); return lua_type(L, -1); } COMPAT53_API int lua_isinteger(lua_State *L, int index) { if (lua_type(L, index) == LUA_TNUMBER) { lua_Number n = lua_tonumber(L, index); lua_Integer i = lua_tointeger(L, index); if (i == n) return 1; } return 0; } COMPAT53_API lua_Integer lua_tointegerx(lua_State *L, int i, int *isnum) { int ok = 0; lua_Number n = lua_tonumberx(L, i, &ok); if (ok) { if (n == (lua_Integer)n) { if (isnum) *isnum = 1; return (lua_Integer)n; } } if (isnum) *isnum = 0; return 0; } static void compat53_reverse(lua_State *L, int a, int b) { for (; a < b; ++a, --b) { lua_pushvalue(L, a); lua_pushvalue(L, b); lua_replace(L, a); lua_replace(L, b); } } COMPAT53_API void lua_rotate(lua_State *L, int idx, int n) { int n_elems = 0; idx = lua_absindex(L, idx); n_elems = lua_gettop(L) - idx + 1; if (n < 0) n += n_elems; if (n > 0 && n < n_elems) { luaL_checkstack(L, 2, "not enough stack slots available"); n = n_elems - n; compat53_reverse(L, idx, idx + n - 1); compat53_reverse(L, idx + n, idx + n_elems - 1); compat53_reverse(L, idx, idx + n_elems - 1); } } COMPAT53_API void lua_seti(lua_State *L, int index, lua_Integer i) { luaL_checkstack(L, 1, "not enough stack slots available"); index = lua_absindex(L, index); lua_pushinteger(L, i); lua_insert(L, -2); lua_settable(L, index); } #if !defined(lua_str2number) # define lua_str2number(s, p) strtod((s), (p)) #endif COMPAT53_API size_t lua_stringtonumber(lua_State *L, const char *s) { char* endptr; lua_Number n = lua_str2number(s, &endptr); if (endptr != s) { while (*endptr != '\0' && isspace((unsigned char)*endptr)) ++endptr; if (*endptr == '\0') { lua_pushnumber(L, n); return endptr - s + 1; } } return 0; } COMPAT53_API const char *luaL_tolstring(lua_State *L, int idx, size_t *len) { if (!luaL_callmeta(L, idx, "__tostring")) { int t = lua_type(L, idx), tt = 0; char const* name = NULL; switch (t) { case LUA_TNIL: lua_pushliteral(L, "nil"); break; case LUA_TSTRING: case LUA_TNUMBER: lua_pushvalue(L, idx); break; case LUA_TBOOLEAN: if (lua_toboolean(L, idx)) lua_pushliteral(L, "true"); else lua_pushliteral(L, "false"); break; default: tt = luaL_getmetafield(L, idx, "__name"); name = (tt == LUA_TSTRING) ? lua_tostring(L, -1) : lua_typename(L, t); lua_pushfstring(L, "%s: %p", name, lua_topointer(L, idx)); if (tt != LUA_TNIL) lua_replace(L, -2); break; } } else { if (!lua_isstring(L, -1)) luaL_error(L, "'__tostring' must return a string"); } return lua_tolstring(L, -1, len); } COMPAT53_API void luaL_requiref(lua_State *L, const char *modname, lua_CFunction openf, int glb) { luaL_checkstack(L, 3, "not enough stack slots available"); luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED"); if (lua_getfield(L, -1, modname) == LUA_TNIL) { lua_pop(L, 1); lua_pushcfunction(L, openf); lua_pushstring(L, modname); lua_call(L, 1, 1); lua_pushvalue(L, -1); lua_setfield(L, -3, modname); } if (glb) { lua_pushvalue(L, -1); lua_setglobal(L, modname); } lua_replace(L, -2); } #endif /* Lua 5.1 and 5.2 */ #endif /* KEPLER_PROJECT_COMPAT53_C_ */ /********************************************************************* * This file contains parts of Lua 5.2's and Lua 5.3's source code: * * Copyright (C) 1994-2014 Lua.org, PUC-Rio. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *********************************************************************/ // end of sol/compatibility/compat-5.3.c #endif #endif /* KEPLER_PROJECT_COMPAT53_H_ */ // end of sol/compatibility/compat-5.3.h #endif // SOL_NO_COMPAT // end of sol/compatibility.hpp #include #include #include namespace sol { namespace detail { struct direct_error_tag {}; const auto direct_error = direct_error_tag {}; struct error_result { int results; const char* format_string; std::array args_strings; error_result() : results(0), format_string(nullptr) { } error_result(int results) : results(results), format_string(nullptr) { } error_result(const char* fmt, const char* msg) : results(0), format_string(fmt) { args_strings[0] = msg; } }; inline int handle_errors(lua_State* L, const error_result& er) { if (er.format_string == nullptr) { return er.results; } return luaL_error(L, er.format_string, er.args_strings[0], er.args_strings[1], er.args_strings[2], er.args_strings[3]); } } // namespace detail class error : public std::runtime_error { private: // Because VC++ is upsetting, most of the time! std::string w; public: error(const std::string& str) : error(detail::direct_error, "lua: error: " + str) { } error(std::string&& str) : error(detail::direct_error, "lua: error: " + std::move(str)) { } error(detail::direct_error_tag, const std::string& str) : std::runtime_error(""), w(str) { } error(detail::direct_error_tag, std::string&& str) : std::runtime_error(""), w(std::move(str)) { } error(const error& e) = default; error(error&& e) = default; error& operator=(const error& e) = default; error& operator=(error&& e) = default; virtual const char* what() const noexcept override { return w.c_str(); } }; } // namespace sol // end of sol/error.hpp // beginning of sol/optional.hpp // beginning of sol/in_place.hpp #include namespace sol { #if defined(SOL_CXX17_FEATURES) && 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 {}; template struct in_place_of_i {}; template struct in_place_of_t {}; } // namespace 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(); } template constexpr inline in_place_tag in_place(detail::in_place_of_t) { return in_place_tag(); } template constexpr inline in_place_tag in_place(detail::in_place_of_i) { return in_place_tag(); } 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); 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 } // namespace sol // end of sol/in_place.hpp #if defined(SOL_USE_BOOST) && SOL_USE_BOOST #include #else // beginning of sol/optional_implementation.hpp #include #include #include #if defined(SOL_NO_EXCEPTIONS) && SOL_NO_EXCEPTIONS #include #endif // Exceptions #define TR2_OPTIONAL_REQUIRES(...) typename ::std::enable_if<__VA_ARGS__::value, bool>::type = false #if defined __GNUC__ // NOTE: GNUC is also defined for Clang #if (__GNUC__ >= 5) #define TR2_OPTIONAL_GCC_5_0_AND_HIGHER___ #define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ #elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8) #define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ #elif (__GNUC__ > 4) #define TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ #endif # #if (__GNUC__ == 4) && (__GNUC_MINOR__ >= 7) #define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___ #elif (__GNUC__ > 4) #define TR2_OPTIONAL_GCC_4_7_AND_HIGHER___ #endif # #if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && (__GNUC_PATCHLEVEL__ >= 1) #define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ #elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9) #define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ #elif (__GNUC__ > 4) #define TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ #endif #endif # #if defined __clang_major__ #if (__clang_major__ == 3 && __clang_minor__ >= 5) #define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ #elif (__clang_major__ > 3) #define TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ #endif #if defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ #define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ #elif (__clang_major__ == 3 && __clang_minor__ == 4 && __clang_patchlevel__ >= 2) #define TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ #endif #endif # #if defined _MSC_VER #if (_MSC_VER >= 1900) #define TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ #endif #endif #if defined __clang__ #if (__clang_major__ > 2) || (__clang_major__ == 2) && (__clang_minor__ >= 9) #define OPTIONAL_HAS_THIS_RVALUE_REFS 1 #else #define OPTIONAL_HAS_THIS_RVALUE_REFS 0 #endif #elif defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ #define OPTIONAL_HAS_THIS_RVALUE_REFS 1 #elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ #define OPTIONAL_HAS_THIS_RVALUE_REFS 1 #else #define OPTIONAL_HAS_THIS_RVALUE_REFS 0 #endif #if defined TR2_OPTIONAL_GCC_4_8_1_AND_HIGHER___ #define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 1 #define OPTIONAL_CONSTEXPR_INIT_LIST constexpr #else #define OPTIONAL_HAS_CONSTEXPR_INIT_LIST 0 #define OPTIONAL_CONSTEXPR_INIT_LIST #endif #if defined(TR2_OPTIONAL_MSVC_2015_AND_HIGHER___) || (defined TR2_OPTIONAL_CLANG_3_5_AND_HIGHTER_ && (defined __cplusplus) && (__cplusplus != 201103L)) #define OPTIONAL_HAS_MOVE_ACCESSORS 1 #else #define OPTIONAL_HAS_MOVE_ACCESSORS 0 #endif #// In C++11 constexpr implies const, so we need to make non-const members also non-constexpr #if defined(TR2_OPTIONAL_MSVC_2015_AND_HIGHER___) || ((defined __cplusplus) && (__cplusplus == 201103L)) #define OPTIONAL_MUTABLE_CONSTEXPR #else #define OPTIONAL_MUTABLE_CONSTEXPR constexpr #endif #if defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ #pragma warning(push) #pragma warning(disable : 4814) #endif namespace sol { // BEGIN workaround for missing is_trivially_destructible #if defined TR2_OPTIONAL_GCC_4_8_AND_HIGHER___ // leave it: it is already there #elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ // leave it: it is already there #elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ // leave it: it is already there #elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS // leave it: the user doesn't want it #else template using is_trivially_destructible = ::std::has_trivial_destructor; #endif // END workaround for missing is_trivially_destructible #if (defined TR2_OPTIONAL_GCC_4_7_AND_HIGHER___) // leave it; our metafunctions are already defined. #elif defined TR2_OPTIONAL_CLANG_3_4_2_AND_HIGHER_ // leave it; our metafunctions are already defined. #elif defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ // leave it: it is already there #elif defined TR2_OPTIONAL_DISABLE_EMULATION_OF_TYPE_TRAITS // leave it: the user doesn't want it #else // workaround for missing traits in GCC and CLANG template struct is_nothrow_move_constructible { static constexprbool value = ::std::is_nothrow_constructible::value; }; template struct is_assignable { template static constexprbool has_assign(...) { return false; } template () = ::std::declval(), true))> // the comma operator is necessary for the cases where operator= returns void static constexprbool has_assign(bool) { return true; } static constexprbool value = has_assign(true); }; template struct is_nothrow_move_assignable { template struct has_nothrow_move_assign { static constexprbool value = false; }; template struct has_nothrow_move_assign { static constexprbool value = noexcept(::std::declval() = ::std::declval()); }; static constexprbool value = has_nothrow_move_assign::value>::value; }; // end workaround #endif // 20.5.4, optional for object types template class optional; // 20.5.5, optional for lvalue reference types template class optional; // workaround: std utility functions aren't constexpr yet template inline constexpr T&& constexpr_forward(typename ::std::remove_reference::type& t) noexcept { return static_cast(t); } template inline constexpr T&& constexpr_forward(typename ::std::remove_reference::type&& t) noexcept { static_assert(!::std::is_lvalue_reference::value, "!!"); return static_cast(t); } template inline constexpr typename ::std::remove_reference::type&& constexpr_move(T&& t) noexcept { return static_cast::type&&>(t); } #if defined NDEBUG #define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) (EXPR) #else #define TR2_OPTIONAL_ASSERTED_EXPRESSION(CHECK, EXPR) ((CHECK) ? (EXPR) : ([] { assert(!#CHECK); }(), (EXPR))) #endif namespace detail_ { // static_addressof: a constexpr version of addressof template struct has_overloaded_addressof { template static constexpr bool has_overload(...) { return false; } template ().operator&())> static constexpr bool has_overload(bool) { return true; } static constexpr bool value = has_overload(true); }; template )> constexpr T* static_addressof(T& ref) { return &ref; } template )> T* static_addressof(T& ref) { return ::std::addressof(ref); } // the call to convert(b) has return type A and converts b to type A iff b decltype(b) is implicitly convertible to A template constexpr U convert(U v) { return v; } } // namespace detail_ constexpr struct trivial_init_t { } trivial_init{}; // 20.5.7, Disengaged state indicator struct nullopt_t { struct init {}; constexpr explicit nullopt_t(init) { } }; constexpr nullopt_t nullopt{nullopt_t::init()}; // 20.5.8, class bad_optional_access class bad_optional_access : public ::std::logic_error { public: explicit bad_optional_access(const ::std::string& what_arg) : ::std::logic_error{what_arg} { } explicit bad_optional_access(const char* what_arg) : ::std::logic_error{what_arg} { } }; template struct alignas(T) optional_base { char storage_[sizeof(T)]; bool init_; constexpr optional_base() noexcept : storage_(), init_(false){}; explicit optional_base(const T& v) : storage_(), init_(true) { new (&storage()) T(v); } explicit optional_base(T&& v) : storage_(), init_(true) { new (&storage()) T(constexpr_move(v)); } template explicit optional_base(in_place_t, Args&&... args) : init_(true), storage_() { new (&storage()) T(constexpr_forward(args)...); } template >)> explicit optional_base(in_place_t, ::std::initializer_list il, Args&&... args) : init_(true), storage_() { new (&storage()) T(il, constexpr_forward(args)...); } #if defined __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif T& storage() { return *reinterpret_cast(&storage_[0]); } constexpr const T& storage() const { return *reinterpret_cast(&storage_[0]); } #if defined __GNUC__ #pragma GCC diagnostic pop #endif ~optional_base() { if (init_) { storage().T::~T(); } } }; #if defined __GNUC__ && !defined TR2_OPTIONAL_GCC_5_0_AND_HIGHER___ // Sorry, GCC 4.x; you're just a piece of shit template using constexpr_optional_base = optional_base; #else template struct alignas(T) constexpr_optional_base { char storage_[sizeof(T)]; bool init_; constexpr constexpr_optional_base() noexcept : storage_(), init_(false) { } explicit constexpr constexpr_optional_base(const T& v) : storage_(), init_(true) { new (&storage()) T(v); } explicit constexpr constexpr_optional_base(T&& v) : storage_(), init_(true) { new (&storage()) T(constexpr_move(v)); } template explicit constexpr constexpr_optional_base(in_place_t, Args&&... args) : init_(true), storage_() { new (&storage()) T(constexpr_forward(args)...); } template >)> OPTIONAL_CONSTEXPR_INIT_LIST explicit constexpr_optional_base(in_place_t, ::std::initializer_list il, Args&&... args) : init_(true), storage_() { new (&storage()) T(il, constexpr_forward(args)...); } #if defined __GNUC__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif T& storage() { return (*reinterpret_cast(&storage_[0])); } constexpr const T& storage() const { return (*reinterpret_cast(&storage_[0])); } #if defined __GNUC__ #pragma GCC diagnostic pop #endif ~constexpr_optional_base() = default; }; #endif template using OptionalBase = typename ::std::conditional< ::std::is_trivially_destructible::value, constexpr_optional_base::type>, optional_base::type>>::type; template class optional : private OptionalBase { static_assert(!::std::is_same::type, nullopt_t>::value, "bad T"); static_assert(!::std::is_same::type, in_place_t>::value, "bad T"); constexpr bool initialized() const noexcept { return OptionalBase::init_; } typename ::std::remove_const::type* dataptr() { return ::std::addressof(OptionalBase::storage()); } constexpr const T* dataptr() const { return detail_::static_addressof(OptionalBase::storage()); } #if OPTIONAL_HAS_THIS_RVALUE_REFS == 1 constexpr const T& contained_val() const& { return OptionalBase::storage(); } #if OPTIONAL_HAS_MOVE_ACCESSORS == 1 OPTIONAL_MUTABLE_CONSTEXPR T&& contained_val() && { return ::std::move(OptionalBase::storage()); } OPTIONAL_MUTABLE_CONSTEXPR T& contained_val() & { return OptionalBase::storage(); } #else T& contained_val() & { return OptionalBase::storage(); } T&& contained_val() && { return ::std::move(OptionalBase::storage()); } #endif #else constexpr const T& contained_val() const { return OptionalBase::storage(); } T& contained_val() { return OptionalBase::storage(); } #endif void clear() noexcept { if (initialized()) dataptr()->T::~T(); OptionalBase::init_ = false; } template void initialize(Args&&... args) noexcept(noexcept(T(::std::forward(args)...))) { assert(!OptionalBase::init_); ::new (static_cast(dataptr())) T(::std::forward(args)...); OptionalBase::init_ = true; } template void initialize(::std::initializer_list il, Args&&... args) noexcept(noexcept(T(il, ::std::forward(args)...))) { assert(!OptionalBase::init_); ::new (static_cast(dataptr())) T(il, ::std::forward(args)...); OptionalBase::init_ = true; } public: typedef T value_type; // 20.5.5.1, constructors constexpr optional() noexcept : OptionalBase(){}; constexpr optional(nullopt_t) noexcept : OptionalBase(){}; optional(const optional& rhs) : OptionalBase() { if (rhs.initialized()) { ::new (static_cast(dataptr())) T(*rhs); OptionalBase::init_ = true; } } optional(const optional& rhs) : optional() { if (rhs) { ::new (static_cast(dataptr())) T(*rhs); OptionalBase::init_ = true; } } optional(optional&& rhs) noexcept(::std::is_nothrow_move_constructible::value) : OptionalBase() { if (rhs.initialized()) { ::new (static_cast(dataptr())) T(::std::move(*rhs)); OptionalBase::init_ = true; } } constexpr optional(const T& v) : OptionalBase(v) { } constexpr optional(T&& v) : OptionalBase(constexpr_move(v)) { } template explicit constexpr optional(in_place_t, Args&&... args) : OptionalBase(in_place, constexpr_forward(args)...) { } template >)> OPTIONAL_CONSTEXPR_INIT_LIST explicit optional(in_place_t, ::std::initializer_list il, Args&&... args) : OptionalBase(in_place, il, constexpr_forward(args)...) { } // 20.5.4.2, Destructor ~optional() = default; // 20.5.4.3, assignment optional& operator=(nullopt_t) noexcept { clear(); return *this; } optional& operator=(const optional& rhs) { if (initialized() == true && rhs.initialized() == false) clear(); else if (initialized() == false && rhs.initialized() == true) initialize(*rhs); else if (initialized() == true && rhs.initialized() == true) contained_val() = *rhs; return *this; } optional& operator=(optional&& rhs) noexcept(::std::is_nothrow_move_assignable::value&& ::std::is_nothrow_move_constructible::value) { if (initialized() == true && rhs.initialized() == false) clear(); else if (initialized() == false && rhs.initialized() == true) initialize(::std::move(*rhs)); else if (initialized() == true && rhs.initialized() == true) contained_val() = ::std::move(*rhs); return *this; } template auto operator=(U&& v) -> typename ::std::enable_if< ::std::is_same::type, T>::value, optional&>::type { if (initialized()) { contained_val() = ::std::forward(v); } else { initialize(::std::forward(v)); } return *this; } template void emplace(Args&&... args) { clear(); initialize(::std::forward(args)...); } template void emplace(::std::initializer_list il, Args&&... args) { clear(); initialize(il, ::std::forward(args)...); } // 20.5.4.4, Swap void swap(optional& rhs) noexcept(::std::is_nothrow_move_constructible::value&& noexcept(swap(::std::declval(), ::std::declval()))) { if (initialized() == true && rhs.initialized() == false) { rhs.initialize(::std::move(**this)); clear(); } else if (initialized() == false && rhs.initialized() == true) { initialize(::std::move(*rhs)); rhs.clear(); } else if (initialized() == true && rhs.initialized() == true) { using ::std::swap; swap(**this, *rhs); } } // 20.5.4.5, Observers explicit constexpr operator bool() const noexcept { return initialized(); } constexpr T const* operator->() const { return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), dataptr()); } #if OPTIONAL_HAS_MOVE_ACCESSORS == 1 OPTIONAL_MUTABLE_CONSTEXPR T* operator->() { assert(initialized()); return dataptr(); } constexpr T const& operator*() const& { return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val()); } OPTIONAL_MUTABLE_CONSTEXPR T& operator*() & { assert(initialized()); return contained_val(); } OPTIONAL_MUTABLE_CONSTEXPR T&& operator*() && { assert(initialized()); return constexpr_move(contained_val()); } constexpr T const& value() const& { return initialized() ? contained_val() #ifdef SOL_NO_EXCEPTIONS // we can't abort here // because there's no constexpr abort : *static_cast(nullptr); #else : (throw bad_optional_access("bad optional access"), contained_val()); #endif } OPTIONAL_MUTABLE_CONSTEXPR T& value() & { return initialized() ? contained_val() #ifdef SOL_NO_EXCEPTIONS : *static_cast(nullptr); #else : (throw bad_optional_access("bad optional access"), contained_val()); #endif } OPTIONAL_MUTABLE_CONSTEXPR T&& value() && { return initialized() ? contained_val() #ifdef SOL_NO_EXCEPTIONS // we can't abort here // because there's no constexpr abort : std::move(*static_cast(nullptr)); #else : (throw bad_optional_access("bad optional access"), contained_val()); #endif } #else T* operator->() { assert(initialized()); return dataptr(); } constexpr T const& operator*() const { return TR2_OPTIONAL_ASSERTED_EXPRESSION(initialized(), contained_val()); } T& operator*() { assert(initialized()); return contained_val(); } constexpr T const& value() const { return initialized() ? contained_val() #ifdef SOL_NO_EXCEPTIONS // we can't abort here // because there's no constexpr abort : *static_cast(nullptr); #else : (throw bad_optional_access("bad optional access"), contained_val()); #endif } T& value() { return initialized() ? contained_val() #ifdef SOL_NO_EXCEPTIONS // we can abort here // but the others are constexpr, so we can't... : (std::abort(), *static_cast(nullptr)); #else : (throw bad_optional_access("bad optional access"), contained_val()); #endif } #endif #if OPTIONAL_HAS_THIS_RVALUE_REFS == 1 template constexpr T value_or(V&& v) const& { return *this ? **this : detail_::convert(constexpr_forward(v)); } #if OPTIONAL_HAS_MOVE_ACCESSORS == 1 template OPTIONAL_MUTABLE_CONSTEXPR T value_or(V&& v) && { return *this ? constexpr_move(const_cast&>(*this).contained_val()) : detail_::convert(constexpr_forward(v)); } #else template T value_or(V&& v) && { return *this ? constexpr_move(const_cast&>(*this).contained_val()) : detail_::convert(constexpr_forward(v)); } #endif #else template constexpr T value_or(V&& v) const { return *this ? **this : detail_::convert(constexpr_forward(v)); } #endif }; template class optional { static_assert(!::std::is_same::value, "bad T"); static_assert(!::std::is_same::value, "bad T"); T* ref; public: // 20.5.5.1, construction/destruction constexpr optional() noexcept : ref(nullptr) { } constexpr optional(nullopt_t) noexcept : ref(nullptr) { } constexpr optional(T& v) noexcept : ref(detail_::static_addressof(v)) { } optional(T&&) = delete; constexpr optional(const optional& rhs) noexcept : ref(rhs.ref) { } explicit constexpr optional(in_place_t, T& v) noexcept : ref(detail_::static_addressof(v)) { } explicit optional(in_place_t, T&&) = delete; ~optional() = default; // 20.5.5.2, mutation optional& operator=(nullopt_t) noexcept { ref = nullptr; return *this; } // optional& operator=(const optional& rhs) noexcept { // ref = rhs.ref; // return *this; // } // optional& operator=(optional&& rhs) noexcept { // ref = rhs.ref; // return *this; // } template auto operator=(U&& rhs) noexcept -> typename ::std::enable_if< ::std::is_same::type, optional>::value, optional&>::type { ref = rhs.ref; return *this; } template auto operator=(U&& rhs) noexcept -> typename ::std::enable_if< !::std::is_same::type, optional>::value, optional&>::type = delete; void emplace(T& v) noexcept { ref = detail_::static_addressof(v); } void emplace(T&&) = delete; void swap(optional& rhs) noexcept { ::std::swap(ref, rhs.ref); } // 20.5.5.3, observers constexpr T* operator->() const { return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, ref); } constexpr T& operator*() const { return TR2_OPTIONAL_ASSERTED_EXPRESSION(ref, *ref); } constexpr T& value() const { #ifdef SOL_NO_EXCEPTIONS return *ref; #else return ref ? *ref : (throw bad_optional_access("bad optional access"), *ref); #endif // Exceptions } explicit constexpr operator bool() const noexcept { return ref != nullptr; } template constexpr T& value_or(V&& v) const { return *this ? **this : detail_::convert(constexpr_forward(v)); } }; template class optional { static_assert(sizeof(T) == 0, "optional rvalue references disallowed"); }; // 20.5.8, Relational operators template constexpr bool operator==(const optional& x, const optional& y) { return bool(x) != bool(y) ? false : bool(x) == false ? true : *x == *y; } template constexpr bool operator!=(const optional& x, const optional& y) { return !(x == y); } template constexpr bool operator<(const optional& x, const optional& y) { return (!y) ? false : (!x) ? true : *x < *y; } template constexpr bool operator>(const optional& x, const optional& y) { return (y < x); } template constexpr bool operator<=(const optional& x, const optional& y) { return !(y < x); } template constexpr bool operator>=(const optional& x, const optional& y) { return !(x < y); } // 20.5.9, Comparison with nullopt template constexpr bool operator==(const optional& x, nullopt_t) noexcept { return (!x); } template constexpr bool operator==(nullopt_t, const optional& x) noexcept { return (!x); } template constexpr bool operator!=(const optional& x, nullopt_t) noexcept { return bool(x); } template constexpr bool operator!=(nullopt_t, const optional& x) noexcept { return bool(x); } template constexpr bool operator<(const optional&, nullopt_t) noexcept { return false; } template constexpr bool operator<(nullopt_t, const optional& x) noexcept { return bool(x); } template constexpr bool operator<=(const optional& x, nullopt_t) noexcept { return (!x); } template constexpr bool operator<=(nullopt_t, const optional&) noexcept { return true; } template constexpr bool operator>(const optional& x, nullopt_t) noexcept { return bool(x); } template constexpr bool operator>(nullopt_t, const optional&) noexcept { return false; } template constexpr bool operator>=(const optional&, nullopt_t) noexcept { return true; } template constexpr bool operator>=(nullopt_t, const optional& x) noexcept { return (!x); } // 20.5.10, Comparison with T template constexpr bool operator==(const optional& x, const T& v) { return bool(x) ? *x == v : false; } template constexpr bool operator==(const T& v, const optional& x) { return bool(x) ? v == *x : false; } template constexpr bool operator!=(const optional& x, const T& v) { return bool(x) ? *x != v : true; } template constexpr bool operator!=(const T& v, const optional& x) { return bool(x) ? v != *x : true; } template constexpr bool operator<(const optional& x, const T& v) { return bool(x) ? *x < v : true; } template constexpr bool operator>(const T& v, const optional& x) { return bool(x) ? v > *x : true; } template constexpr bool operator>(const optional& x, const T& v) { return bool(x) ? *x > v : false; } template constexpr bool operator<(const T& v, const optional& x) { return bool(x) ? v < *x : false; } template constexpr bool operator>=(const optional& x, const T& v) { return bool(x) ? *x >= v : false; } template constexpr bool operator<=(const T& v, const optional& x) { return bool(x) ? v <= *x : false; } template constexpr bool operator<=(const optional& x, const T& v) { return bool(x) ? *x <= v : true; } template constexpr bool operator>=(const T& v, const optional& x) { return bool(x) ? v >= *x : true; } // Comparison of optional with T template constexpr bool operator==(const optional& x, const T& v) { return bool(x) ? *x == v : false; } template constexpr bool operator==(const T& v, const optional& x) { return bool(x) ? v == *x : false; } template constexpr bool operator!=(const optional& x, const T& v) { return bool(x) ? *x != v : true; } template constexpr bool operator!=(const T& v, const optional& x) { return bool(x) ? v != *x : true; } template constexpr bool operator<(const optional& x, const T& v) { return bool(x) ? *x < v : true; } template constexpr bool operator>(const T& v, const optional& x) { return bool(x) ? v > *x : true; } template constexpr bool operator>(const optional& x, const T& v) { return bool(x) ? *x > v : false; } template constexpr bool operator<(const T& v, const optional& x) { return bool(x) ? v < *x : false; } template constexpr bool operator>=(const optional& x, const T& v) { return bool(x) ? *x >= v : false; } template constexpr bool operator<=(const T& v, const optional& x) { return bool(x) ? v <= *x : false; } template constexpr bool operator<=(const optional& x, const T& v) { return bool(x) ? *x <= v : true; } template constexpr bool operator>=(const T& v, const optional& x) { return bool(x) ? v >= *x : true; } // Comparison of optional with T template constexpr bool operator==(const optional& x, const T& v) { return bool(x) ? *x == v : false; } template constexpr bool operator==(const T& v, const optional& x) { return bool(x) ? v == *x : false; } template constexpr bool operator!=(const optional& x, const T& v) { return bool(x) ? *x != v : true; } template constexpr bool operator!=(const T& v, const optional& x) { return bool(x) ? v != *x : true; } template constexpr bool operator<(const optional& x, const T& v) { return bool(x) ? *x < v : true; } template constexpr bool operator>(const T& v, const optional& x) { return bool(x) ? v > *x : true; } template constexpr bool operator>(const optional& x, const T& v) { return bool(x) ? *x > v : false; } template constexpr bool operator<(const T& v, const optional& x) { return bool(x) ? v < *x : false; } template constexpr bool operator>=(const optional& x, const T& v) { return bool(x) ? *x >= v : false; } template constexpr bool operator<=(const T& v, const optional& x) { return bool(x) ? v <= *x : false; } template constexpr bool operator<=(const optional& x, const T& v) { return bool(x) ? *x <= v : true; } template constexpr bool operator>=(const T& v, const optional& x) { return bool(x) ? v >= *x : true; } // 20.5.12, Specialized algorithms template void swap(optional& x, optional& y) noexcept(noexcept(x.swap(y))) { x.swap(y); } template constexpr optional::type> make_optional(T&& v) { return optional::type>(constexpr_forward(v)); } template constexpr optional make_optional(::std::reference_wrapper v) { return optional(v.get()); } } // namespace sol namespace std { template struct hash> { typedef typename hash::result_type result_type; typedef sol::optional argument_type; constexpr result_type operator()(argument_type const& arg) const { return arg ? ::std::hash{}(*arg) : result_type{}; } }; template struct hash> { typedef typename hash::result_type result_type; typedef sol::optional argument_type; constexpr result_type operator()(argument_type const& arg) const { return arg ? ::std::hash{}(*arg) : result_type{}; } }; } // namespace std #if defined TR2_OPTIONAL_MSVC_2015_AND_HIGHER___ #pragma warning(pop) #endif #undef TR2_OPTIONAL_REQUIRES #undef TR2_OPTIONAL_ASSERTED_EXPRESSION // end of sol/optional_implementation.hpp #endif // Boost vs. Better optional namespace sol { #if defined(SOL_USE_BOOST) && SOL_USE_BOOST template using optional = boost::optional; using nullopt_t = boost::none_t; const nullopt_t nullopt = boost::none; #endif // Boost vs. Better optional namespace meta { template struct is_optional : std::false_type {}; template struct is_optional> : std::true_type {}; } // namespace meta } // namespace sol // end of sol/optional.hpp // beginning of sol/forward_detail.hpp #ifndef SOL_FORWARD_DETAIL_HPP #define SOL_FORWARD_DETAIL_HPP // beginning of sol/traits.hpp // beginning of sol/tuple.hpp #include namespace sol { namespace detail { using swallow = std::initializer_list; } // namespace detail namespace meta { namespace detail { template struct tuple_types_ { typedef types type; }; template struct tuple_types_> { typedef types type; }; } // namespace detail template using unqualified = std::remove_cv>; template using unqualified_t = typename unqualified::type; template using tuple_types = typename detail::tuple_types_::type; template struct pop_front_type; template using pop_front_type_t = typename pop_front_type::type; template struct pop_front_type> { typedef void front_type; typedef types type; }; template struct pop_front_type> { typedef Arg front_type; typedef types type; }; template using tuple_element = std::tuple_element>; template using tuple_element_t = std::tuple_element_t>; template using unqualified_tuple_element = unqualified>; template using unqualified_tuple_element_t = unqualified_t>; } // namespace meta } // namespace sol // end of sol/tuple.hpp // beginning of sol/bind_traits.hpp namespace sol { namespace meta { namespace meta_detail { template struct check_deducible_signature { struct nat {}; template static auto test(int) -> decltype(&G::operator(), void()); template static auto test(...) -> nat; using type = std::is_void(0))>; }; } // namespace meta_detail template struct has_deducible_signature : meta_detail::check_deducible_signature::type {}; namespace meta_detail { template struct void_tuple_element : meta::tuple_element {}; template struct void_tuple_element> { typedef void type; }; template using void_tuple_element_t = typename void_tuple_element::type; 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); static const std::size_t free_arity = sizeof...(Args) + static_cast(!std::is_void::value); typedef types args_list; typedef std::tuple args_tuple; typedef T object_type; typedef R return_type; typedef tuple_types returns_list; typedef R(function_type)(Args...); typedef std::conditional_t::value, args_list, types> free_args_list; typedef std::conditional_t::value, R(Args...), R(first_type, Args...)> free_function_type; typedef std::conditional_t::value, R (*)(Args...), R (*)(first_type, Args...)> free_function_pointer_type; typedef std::remove_pointer_t signature_type; template using arg_at = void_tuple_element_t; }; template ::value> struct fx_traits : basic_traits {}; // Free Functions template struct fx_traits : basic_traits { typedef R (*function_pointer_type)(Args...); }; template struct fx_traits : basic_traits { typedef R (*function_pointer_type)(Args...); }; template struct fx_traits : basic_traits { typedef R (*function_pointer_type)(Args..., ...); }; template struct fx_traits : basic_traits { typedef R (*function_pointer_type)(Args..., ...); }; // Member Functions /* C-Style Variadics */ template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args...); }; template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args..., ...); }; /* Const Volatile */ template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args...) const; }; template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const; }; template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args...) const volatile; }; template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const volatile; }; /* Member Function Qualifiers */ template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args...) &; }; template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) &; }; template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args...) const&; }; template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const&; }; template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args...) const volatile&; }; template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const volatile&; }; template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args...) &&; }; template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) &&; }; template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args...) const&&; }; template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const&&; }; template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args...) const volatile&&; }; template struct fx_traits : basic_traits { typedef R (T::*function_pointer_type)(Args..., ...) const volatile&&; }; #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && 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 #if defined(_MSC_VER) && defined(_M_IX86) template struct fx_traits : basic_traits { typedef R(__stdcall* function_pointer_type)(Args...); }; template struct fx_traits : basic_traits { typedef R(__stdcall* function_pointer_type)(Args...); }; template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...); }; /* Const Volatile */ template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const; }; template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile; }; /* Member Function Qualifiers */ template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) &; }; template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const&; }; template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&; }; template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) &&; }; template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const&&; }; template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&&; }; #if defined(SOL_NOEXCEPT_FUNCTION_TYPE) && SOL_NOEXCEPT_FUNCTION_TYPE template struct fx_traits : basic_traits { typedef R(__stdcall* function_pointer_type)(Args...) noexcept; }; template struct fx_traits : basic_traits { typedef R(__stdcall* function_pointer_type)(Args...) noexcept; }; /* __stdcall cannot be applied to functions with varargs*/ /*template struct fx_traits<__stdcall R(Args..., ...) noexcept, false> : basic_traits { typedef R(__stdcall* function_pointer_type)(Args..., ...) noexcept; }; template struct fx_traits : basic_traits { typedef R(__stdcall* function_pointer_type)(Args..., ...) noexcept; };*/ template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) noexcept; };*/ /* Const Volatile */ template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const noexcept; };*/ template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const volatile noexcept; };*/ template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) & noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) & noexcept; };*/ template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const& noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const& noexcept; };*/ template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile& noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const volatile& noexcept; };*/ template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) && noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) && noexcept; };*/ template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const&& noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const&& noexcept; };*/ template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args...) const volatile&& noexcept; }; /* __stdcall does not work with varargs */ /*template struct fx_traits : basic_traits { typedef R (__stdcall T::*function_pointer_type)(Args..., ...) const volatile&& noexcept; };*/ #endif // noexcept is part of a function's type #endif // __stdcall x86 VC++ bug template struct fx_traits : fx_traits::function_type, false> {}; template ::value> struct callable_traits : fx_traits> { }; template struct callable_traits { typedef std::conditional_t::value, std::add_lvalue_reference_t, R> return_type; typedef return_type 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; typedef std::tuple args_tuple; typedef types args_list; typedef types free_args_list; typedef meta::tuple_types returns_list; typedef return_type(function_type)(T&, return_type); typedef return_type(*function_pointer_type)(T&, Arg); typedef return_type(*free_function_pointer_type)(T&, Arg); template using arg_at = void_tuple_element_t; }; } // namespace meta_detail template struct bind_traits : meta_detail::callable_traits {}; template using function_args_t = typename bind_traits::args_list; template using function_signature_t = typename bind_traits::signature_type; template using function_return_t = typename bind_traits::return_type; } } // namespace sol::meta // end of sol/bind_traits.hpp // beginning of sol/string_view.hpp #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES #include #endif // C++17 features #if defined(SOL_USE_BOOST) && SOL_USE_BOOST #include #endif namespace sol { #if defined(SOL_CXX17_FEATURES) && SOL_CXX17_FEATURES template > using basic_string_view = std::basic_string_view; typedef std::string_view string_view; typedef std::wstring_view wstring_view; typedef std::u16string_view u16string_view; typedef std::u32string_view u32string_view; typedef std::hash string_view_hash; #else template > struct basic_string_view { std::size_t s; const Char* p; basic_string_view(const std::string& r) : basic_string_view(r.data(), r.size()) { } basic_string_view(const Char* ptr) : basic_string_view(ptr, Traits::length(ptr)) { } basic_string_view(const Char* ptr, std::size_t sz) : s(sz), p(ptr) { } static int compare(const Char* lhs_p, std::size_t lhs_sz, const Char* rhs_p, std::size_t rhs_sz) { int result = Traits::compare(lhs_p, rhs_p, lhs_sz < rhs_sz ? lhs_sz : rhs_sz); if (result != 0) return result; if (lhs_sz < rhs_sz) return -1; if (lhs_sz > rhs_sz) return 1; return 0; } const Char* begin() const { return p; } const Char* end() const { return p + s; } const Char* cbegin() const { return p; } const Char* cend() const { return p + s; } const Char* data() const { return p; } std::size_t size() const { return s; } std::size_t length() const { return size(); } operator std::basic_string() const { return std::basic_string(data(), size()); } bool operator==(const basic_string_view& r) const { return compare(p, s, r.data(), r.size()) == 0; } bool operator==(const Char* r) const { return compare(r, Traits::length(r), p, s) == 0; } bool operator==(const std::basic_string& r) const { return compare(r.data(), r.size(), p, s) == 0; } bool operator!=(const basic_string_view& r) const { return !(*this == r); } bool operator!=(const char* r) const { return !(*this == r); } bool operator!=(const std::basic_string& r) const { return !(*this == r); } }; template > struct basic_string_view_hash { typedef basic_string_view argument_type; typedef std::size_t result_type; template result_type operator()(const std::basic_string& r) const { return (*this)(argument_type(r.c_str(), r.size())); } result_type operator()(const argument_type& r) const { #if defined(SOL_USE_BOOST) && SOL_USE_BOOST return boost::hash_range(r.begin(), r.end()); #else // Modified, from libstdc++ // An implementation attempt at Fowler No Voll, 1a. // Supposedly, used in MSVC, // GCC (libstdc++) uses MurmurHash of some sort for 64-bit though...? // But, well. Can't win them all, right? // This should normally only apply when NOT using boost, // so this should almost never be tapped into... std::size_t hash = 0; const unsigned char* cptr = reinterpret_cast(r.data()); for (std::size_t sz = r.size(); sz != 0; --sz) { hash ^= static_cast(*cptr++); hash *= static_cast(1099511628211ULL); } return hash; #endif } }; } // namespace sol namespace std { template struct hash< ::sol::basic_string_view > : ::sol::basic_string_view_hash {}; } // namespace std namespace sol { using string_view = basic_string_view; using wstring_view = basic_string_view; using u16string_view = basic_string_view; using u32string_view = basic_string_view; using string_view_hash = std::hash; #endif // C++17 Support } // namespace sol // end of sol/string_view.hpp #include #include #include #include namespace sol { namespace meta { template using index_value = std::integral_constant; template struct conditional { template using type = T; }; template <> struct conditional { template using type = U; }; template using conditional_t = typename conditional::template type; using sfinae_yes_t = std::true_type; using sfinae_no_t = std::false_type; template struct identity { typedef T type; }; template using identity_t = typename identity::type; template struct is_tuple : std::false_type {}; template struct is_tuple> : std::true_type {}; template struct is_builtin_type : std::integral_constant::value || std::is_pointer::value || std::is_array::value> {}; template struct unwrapped { typedef T type; }; template struct unwrapped> { typedef T type; }; template using unwrapped_t = typename unwrapped::type; template struct unwrap_unqualified : unwrapped> {}; template using unwrap_unqualified_t = typename unwrap_unqualified::type; template struct remove_member_pointer; template struct remove_member_pointer { typedef R type; }; template struct remove_member_pointer { typedef R type; }; template using remove_member_pointer_t = remove_member_pointer; namespace meta_detail { template class Templ> struct is_specialization_of : std::false_type {}; template class Templ> struct is_specialization_of, Templ> : std::true_type {}; } // namespace meta_detail template class Templ> using is_specialization_of = meta_detail::is_specialization_of, Templ>; template class Templ> constexpr bool is_specialization_of_v = is_specialization_of, Templ>::value; template struct all_same : std::true_type {}; template struct all_same : std::integral_constant::value && all_same::value> {}; template struct any_same : std::false_type {}; template struct any_same : std::integral_constant::value || any_same::value> {}; template using boolean = std::integral_constant; template using invoke_t = typename T::type; template using invoke_b = boolean; template using neg = boolean; template using condition = conditional_t; template struct all : boolean {}; template struct all : condition, boolean> {}; template struct any : boolean {}; template struct any : condition, any> {}; enum class enable_t { _ }; constexpr const auto enabler = enable_t::_; template using disable_if_t = std::enable_if_t; template using enable = std::enable_if_t::value, enable_t>; template using disable = std::enable_if_t>::value, enable_t>; template using enable_any = std::enable_if_t::value, enable_t>; template using disable_any = std::enable_if_t>::value, enable_t>; template struct find_in_pack_v : boolean {}; template struct find_in_pack_v : any, find_in_pack_v> {}; namespace meta_detail { template struct index_in_pack : std::integral_constant {}; template struct index_in_pack : conditional_t::value, std::integral_constant, index_in_pack> {}; } // namespace meta_detail template struct index_in_pack : meta_detail::index_in_pack<0, T, Args...> {}; template struct index_in : meta_detail::index_in_pack<0, T, List> {}; template struct index_in> : meta_detail::index_in_pack<0, T, Args...> {}; template struct at_in_pack {}; template using at_in_pack_t = typename at_in_pack::type; template struct at_in_pack : std::conditional> {}; template struct at_in_pack<0, Arg, Args...> { typedef Arg type; }; namespace meta_detail { template class Pred, typename... Ts> struct count_for_pack : std::integral_constant {}; template class Pred, typename T, typename... Ts> struct count_for_pack : conditional_t(Limit != 0 && Pred::value)>, count_for_pack(Pred::value), Pred, Ts...>> {}; template class Pred, typename... Ts> struct count_2_for_pack : std::integral_constant {}; template class Pred, typename T, typename U, typename... Ts> struct count_2_for_pack : conditional_t(Pred::value)>, count_2_for_pack(Pred::value), Pred, Ts...>> {}; } // namespace meta_detail template