From 069a209a4ecc6bacf9a301a30cf6895177e101fa Mon Sep 17 00:00:00 2001 From: ThePhD Date: Thu, 18 Jun 2015 10:53:21 -0400 Subject: [PATCH] Fixes for the g++/clang builds --- sol/compatibility/version.hpp | 2 + sol/stack.hpp | 138 ++++++++++++++++++---------------- sol/state.hpp | 9 ++- 3 files changed, 79 insertions(+), 70 deletions(-) diff --git a/sol/compatibility/version.hpp b/sol/compatibility/version.hpp index 37d5df7b..e003465a 100644 --- a/sol/compatibility/version.hpp +++ b/sol/compatibility/version.hpp @@ -25,7 +25,9 @@ #include #ifdef LUAJIT_VERSION +#ifndef SOL_LUAJIT #define SOL_LUAJIT +#endif // sol luajit #endif // luajit #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 502 diff --git a/sol/stack.hpp b/sol/stack.hpp index 7144100a..99d57563 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -73,56 +73,6 @@ struct return_forward { } // detail namespace stack { -namespace detail { -const bool default_check_arguments = -#ifdef SOL_CHECK_ARGUMENTS -true; -#else -false; -#endif - -template -inline int push_userdata_pointer(lua_State* L, Key&& metatablekey) { - return push_confirmed_userdata(L, std::forward(metatablekey)); -} - -template >> = 0> -inline int push_userdata_pointer(lua_State* L, Key&& metatablekey, Arg&& arg) { - if (arg == nullptr) - return push(L, nil); - return push_confirmed_userdata(L, std::forward(metatablekey), std::forward(arg)); -} - -template >> = 0> -inline int push_userdata_pointer(lua_State* L, Key&& metatablekey, Arg&& arg) { - return push_confirmed_userdata(L, std::forward(metatablekey), std::forward(arg)); -} - -template -inline int push_userdata_pointer(lua_State* L, Key&& metatablekey, Arg0&& arg0, Arg1&& arg1, Args&&... args) { - return push_confirmed_userdata(L, std::forward(metatablekey), std::forward(arg0), std::forward(arg1), std::forward(args)...); -} - -template -inline int push_confirmed_userdata(lua_State* L, Key&& metatablekey, Args&&... args) { - T* pdatum = static_cast(lua_newuserdata(L, sizeof(T))); - std::allocator alloc{}; - alloc.construct(pdatum, std::forward(args)...); - luaL_getmetatable(L, std::addressof(metatablekey[0])); - lua_setmetatable(L, -2); - return 1; -} - -template> = 0> -inline int push_userdata(lua_State* L, Key&& metatablekey, Args&&... args) { - return push_confirmed_userdata(L, std::forward(metatablekey), std::forward(args)...); -} - -template> = 0> -inline int push_userdata(lua_State* L, Key&& metatablekey, Args&&... args) { - return push_userdata_pointer(L, std::forward(metatablekey), std::forward(args)...); -} -} // detail template struct getter; @@ -159,7 +109,7 @@ template inline int push_args(lua_State* L, T&& t, Args&&... args) { int pushcount = push(L, std::forward(t)); using swallow = char[]; - void(swallow{'\0', (pushcount += push(L, std::forward(args)), '\0')... }); + void(swallow{'\0', (pushcount += sol::stack::push(L, std::forward(args)), '\0')... }); return pushcount; } @@ -176,6 +126,70 @@ auto pop(lua_State* L) -> decltype(get(L)) { return r; } +template +bool check(lua_State* L, int index, Handler&& handler) { + typedef Unqualified Tu; + checker c; + return c.check(L, index, std::forward(handler)); +} + +template +bool check(lua_State* L, int index) { + auto handler = type_panic; + return check(L, index, handler); +} + +namespace detail { +const bool default_check_arguments = +#ifdef SOL_CHECK_ARGUMENTS +true; +#else +false; +#endif + +template +inline int push_confirmed_userdata(lua_State* L, Key&& metatablekey, Args&&... args) { + T* pdatum = static_cast(lua_newuserdata(L, sizeof(T))); + std::allocator alloc{}; + alloc.construct(pdatum, std::forward(args)...); + luaL_getmetatable(L, std::addressof(metatablekey[0])); + lua_setmetatable(L, -2); + return 1; +} + +template +inline int push_userdata_pointer(lua_State* L, Key&& metatablekey) { + return push_confirmed_userdata(L, std::forward(metatablekey)); +} + +template >> = 0> +inline int push_userdata_pointer(lua_State* L, Key&& metatablekey, Arg&& arg) { + if (arg == nullptr) + return push(L, nil); + return push_confirmed_userdata(L, std::forward(metatablekey), std::forward(arg)); +} + +template >> = 0> +inline int push_userdata_pointer(lua_State* L, Key&& metatablekey, Arg&& arg) { + return push_confirmed_userdata(L, std::forward(metatablekey), std::forward(arg)); +} + +template +inline int push_userdata_pointer(lua_State* L, Key&& metatablekey, Arg0&& arg0, Arg1&& arg1, Args&&... args) { + return push_confirmed_userdata(L, std::forward(metatablekey), std::forward(arg0), std::forward(arg1), std::forward(args)...); +} + +template> = 0> +inline int push_userdata(lua_State* L, Key&& metatablekey, Args&&... args) { + return push_confirmed_userdata(L, std::forward(metatablekey), std::forward(args)...); +} + +template> = 0> +inline int push_userdata(lua_State* L, Key&& metatablekey, Args&&... args) { + return push_userdata_pointer(L, std::forward(metatablekey), std::forward(args)...); +} +} // detail + template struct get_return { typedef decltype(get(nullptr)) type; @@ -210,19 +224,6 @@ struct checker { } }; -template -bool check(lua_State* L, int index, Handler&& handler) { - typedef Unqualified Tu; - checker c; - return c.check(L, index, std::forward(handler)); -} - -template -bool check(lua_State* L, int index) { - auto handler = type_panic; - return check(L, index, handler); -} - template struct getter { template> = 0> @@ -548,15 +549,20 @@ inline std::pair get_as_upvalues(lua_State* L, int index = 1) { template struct check_arguments { - template - static bool check(lua_State* L, int firstargument, indices, types) { + template + static bool check(lua_State* L, int firstargument, indices, types) { bool checks = true; + stack::check(L, firstargument + I0); using swallow = int[sizeof...(Args)+2]; (void)swallow { 0, (checks &= stack::check(L, firstargument + I))..., 0 }; return checks; } + + static bool check(lua_State*, int, indices<>, types<>) { + return true; + } }; template <> diff --git a/sol/state.hpp b/sol/state.hpp index fcd8a202..bb2d0080 100644 --- a/sol/state.hpp +++ b/sol/state.hpp @@ -95,12 +95,12 @@ public: luaL_requiref(L.get(), "package", luaopen_package, 1); lua_pop(L.get(), 1); break; -#if SOL_LUA_VERSION > 501 case lib::coroutine: +#if SOL_LUA_VERSION > 501 luaL_requiref(L.get(), "coroutine", luaopen_coroutine, 1); lua_pop(L.get(), 1); - break; #endif // Lua 5.2+ only + break; case lib::string: luaL_requiref(L.get(), "string", luaopen_string, 1); lua_pop(L.get(), 1); @@ -113,12 +113,13 @@ public: luaL_requiref(L.get(), "math", luaopen_math, 1); lua_pop(L.get(), 1); break; -#if SOL_LUA_VERSION > 510 case lib::bit32: +#if SOL_LUA_VERSION > 510 luaL_requiref(L.get(), "bit32", luaopen_bit32, 1); lua_pop(L.get(), 1); - break; +#else #endif // Lua 5.2+ only + break; case lib::io: luaL_requiref(L.get(), "io", luaopen_io, 1); lua_pop(L.get(), 1);