diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 53f19bd4..fb0818be 100644 --- a/single/sol/sol.hpp +++ b/single/sol/sol.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2016-10-21 11:06:29.508272 UTC -// This header was generated with sol v2.14.11 (revision 4d45f0c) +// Generated 2016-10-21 21:30:36.718233 UTC +// This header was generated with sol v2.14.11 (revision 8c3ae42) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -4553,32 +4553,32 @@ namespace sol { template struct usertype_traits { - static const std::string name; - static const std::string qualified_name; - static const std::string metatable; - static const std::string user_metatable; - static const std::string user_gc_metatable; - static const std::string gc_table; + static const std::string& name() { + static const std::string n = detail::short_demangle(); + return n; + } + static const std::string& qualified_name() { + static const std::string q_n = detail::demangle(); + return q_n; + } + static const std::string& metatable() { + static const std::string m = std::string("sol.").append(detail::demangle()); + return m; + } + static const std::string& user_metatable() { + static const std::string u_m = std::string("sol.").append(detail::demangle()).append(".user"); + return u_m; + } + static const std::string& user_gc_metatable() { + static const std::string u_g_m = std::string("sol.").append(detail::demangle()).append(".user\xE2\x99\xBB"); + return u_g_m; + } + static const std::string& gc_table() { + static const std::string g_t = std::string("sol.").append(detail::demangle().append(".\xE2\x99\xBB")); + return g_t; + } }; - template - const std::string usertype_traits::name = detail::short_demangle(); - - template - const std::string usertype_traits::qualified_name = detail::demangle(); - - template - const std::string usertype_traits::metatable = std::string("sol.").append(detail::demangle()); - - template - const std::string usertype_traits::user_metatable = std::string("sol.").append(detail::demangle()).append(".user"); - - template - const std::string usertype_traits::user_gc_metatable = std::string("sol.").append(detail::demangle()).append(".user\xE2\x99\xBB"); - - template - const std::string usertype_traits::gc_table = std::string("sol.").append(detail::demangle().append(".\xE2\x99\xBB")); - } // end of sol/usertype_traits.hpp @@ -4685,7 +4685,7 @@ namespace sol { namespace stack_detail { template inline bool check_metatable(lua_State* L, int index = -2) { - const auto& metakey = usertype_traits::metatable; + const auto& metakey = usertype_traits::metatable(); luaL_getmetatable(L, &metakey[0]); const type expectedmetatabletype = static_cast(lua_type(L, -1)); if (expectedmetatabletype != type::nil) { @@ -5790,7 +5790,7 @@ namespace sol { template static int push(lua_State* L, Args&&... args) { - return push_keyed(L, usertype_traits::metatable, std::forward(args)...); + return push_keyed(L, usertype_traits::metatable(), std::forward(args)...); } }; @@ -5815,7 +5815,7 @@ namespace sol { } static int push(lua_State* L, T* obj) { - return push_keyed(L, usertype_traits*>::metatable, obj); + return push_keyed(L, usertype_traits*>::metatable(), obj); } }; @@ -5868,7 +5868,7 @@ namespace sol { *fx = detail::special_destruct; detail::default_construct::construct(mem, std::forward(args)...); *pref = unique_usertype_traits::get(*mem); - if (luaL_newmetatable(L, &usertype_traits>::metatable[0]) == 1) { + if (luaL_newmetatable(L, &usertype_traits>::metatable()[0]) == 1) { set_field(L, "__gc", detail::unique_destruct

); } lua_setmetatable(L, -2); @@ -6090,13 +6090,13 @@ namespace sol { template , no_metatable_t, metatable_key_t>> = meta::enabler> static int push(lua_State* L, Arg&& arg, Args&&... args) { - const auto name = &usertype_traits>::user_gc_metatable[0]; + const auto name = &usertype_traits>::user_gc_metatable()[0]; return push_with(L, name, std::forward(arg), std::forward(args)...); } template static int push(lua_State* L, no_metatable_t, Args&&... args) { - const auto name = &usertype_traits>::user_gc_metatable[0]; + const auto name = &usertype_traits>::user_gc_metatable()[0]; return push_with(L, name, std::forward(args)...); } @@ -6107,22 +6107,22 @@ namespace sol { } static int push(lua_State* L, const user& u) { - const auto name = &usertype_traits>::user_gc_metatable[0]; + const auto name = &usertype_traits>::user_gc_metatable()[0]; return push_with(L, name, u.value); } static int push(lua_State* L, user&& u) { - const auto name = &usertype_traits>::user_gc_metatable[0]; + const auto name = &usertype_traits>::user_gc_metatable()[0]; return push_with(L, name, std::move(u.value)); } static int push(lua_State* L, no_metatable_t, const user& u) { - const auto name = &usertype_traits>::user_gc_metatable[0]; + const auto name = &usertype_traits>::user_gc_metatable()[0]; return push_with(L, name, u.value); } static int push(lua_State* L, no_metatable_t, user&& u) { - const auto name = &usertype_traits>::user_gc_metatable[0]; + const auto name = &usertype_traits>::user_gc_metatable()[0]; return push_with(L, name, std::move(u.value)); } }; @@ -7448,9 +7448,9 @@ namespace sol { template inline int construct(lua_State* L) { - static const auto& meta = usertype_traits::metatable; + static const auto& meta = usertype_traits::metatable(); int argcount = lua_gettop(L); - call_syntax syntax = argcount > 0 ? stack::get_call_syntax(L, &usertype_traits::user_metatable[0], 1) : call_syntax::dot; + call_syntax syntax = argcount > 0 ? stack::get_call_syntax(L, &usertype_traits::user_metatable()[0], 1) : call_syntax::dot; argcount -= static_cast(syntax); T** pointerpointer = reinterpret_cast(lua_newuserdata(L, sizeof(T*) + sizeof(T))); @@ -7686,9 +7686,9 @@ namespace sol { typedef constructor_list F; static int call(lua_State* L, F&) { - const auto& metakey = usertype_traits::metatable; + const auto& metakey = usertype_traits::metatable(); int argcount = lua_gettop(L); - call_syntax syntax = argcount > 0 ? stack::get_call_syntax(L, &usertype_traits::user_metatable[0], 1) : call_syntax::dot; + call_syntax syntax = argcount > 0 ? stack::get_call_syntax(L, &usertype_traits::user_metatable()[0], 1) : call_syntax::dot; argcount -= static_cast(syntax); T** pointerpointer = reinterpret_cast(lua_newuserdata(L, sizeof(T*) + sizeof(T))); @@ -7718,7 +7718,7 @@ namespace sol { struct onmatch { template int operator()(types, index_value, types r, types a, lua_State* L, int, int start, F& f) { - const auto& metakey = usertype_traits::metatable; + const auto& metakey = usertype_traits::metatable(); T** pointerpointer = reinterpret_cast(lua_newuserdata(L, sizeof(T*) + sizeof(T))); reference userdataref(L, -1); T*& referencepointer = *pointerpointer; @@ -7733,7 +7733,7 @@ namespace sol { if (type_of(L, -1) == type::nil) { lua_pop(L, 1); std::string err = "sol: unable to get usertype metatable for "; - err += usertype_traits::name; + err += usertype_traits::name(); return luaL_error(L, err.c_str()); } lua_setmetatable(L, -2); @@ -7743,7 +7743,7 @@ namespace sol { }; static int call(lua_State* L, F& f) { - call_syntax syntax = stack::get_call_syntax(L, &usertype_traits::user_metatable[0]); + call_syntax syntax = stack::get_call_syntax(L, &usertype_traits::user_metatable()[0]); int syntaxval = static_cast(syntax); int argcount = lua_gettop(L) - syntaxval; return construct_match>...>(onmatch(), L, argcount, 1 + syntaxval, f); @@ -9734,8 +9734,8 @@ namespace sol { static void walk_single_base(lua_State* L, bool& found, int& ret, string_detail::string_shim&) { if (found) return; - const char* metakey = &usertype_traits::metatable[0]; - const char* gcmetakey = &usertype_traits::gc_table[0]; + const char* metakey = &usertype_traits::metatable()[0]; + const char* gcmetakey = &usertype_traits::gc_table()[0]; const char* basewalkkey = is_index ? detail::base_class_index_propogation_key() : detail::base_class_new_index_propogation_key(); luaL_getmetatable(L, metakey); @@ -10084,7 +10084,7 @@ namespace sol { static umt_t& make_cleanup(lua_State* L, umt_t&& umx) { // ensure some sort of uniqueness static int uniqueness = 0; - std::string uniquegcmetakey = usertype_traits::user_gc_metatable; + std::string uniquegcmetakey = usertype_traits::user_gc_metatable(); // std::to_string doesn't exist in android still, with NDK, so this bullshit // is necessary // thanks, Android :v @@ -10095,7 +10095,7 @@ namespace sol { snprintf(uniquetarget, uniquegcmetakey.length(), "%d", uniqueness); ++uniqueness; - const char* gcmetakey = &usertype_traits::gc_table[0]; + const char* gcmetakey = &usertype_traits::gc_table()[0]; // Make sure userdata's memory is properly in lua first, // otherwise all the light userdata we make later will become invalid stack::push>(L, metatable_key, uniquegcmetakey, std::move(umx)); @@ -10132,16 +10132,16 @@ namespace sol { luaL_Reg* metaregs = nullptr; switch (i) { case 0: - metakey = &usertype_traits::metatable[0]; + metakey = &usertype_traits::metatable()[0]; metaregs = ref_table.data(); break; case 1: - metakey = &usertype_traits>::metatable[0]; + metakey = &usertype_traits>::metatable()[0]; metaregs = unique_table.data(); break; case 2: default: - metakey = &usertype_traits::metatable[0]; + metakey = &usertype_traits::metatable()[0]; metaregs = value_table.data(); break; } @@ -10189,7 +10189,7 @@ namespace sol { } // Now for the shim-table that actually gets assigned to the name - luaL_newmetatable(L, &usertype_traits::user_metatable[0]); + luaL_newmetatable(L, &usertype_traits::user_metatable()[0]); stack_reference t(L, -1); stack::push(L, make_light(um)); luaL_setfuncs(L, value_table.data(), 1); @@ -10269,14 +10269,14 @@ namespace sol { const char* metakey = nullptr; switch (i) { case 0: - metakey = &usertype_traits::metatable[0]; + metakey = &usertype_traits::metatable()[0]; break; case 1: - metakey = &usertype_traits>::metatable[0]; + metakey = &usertype_traits>::metatable()[0]; break; case 2: default: - metakey = &usertype_traits::metatable[0]; + metakey = &usertype_traits::metatable()[0]; break; } luaL_getmetatable(L, metakey); @@ -10545,7 +10545,7 @@ namespace sol { static usertype_detail::simple_map& make_cleanup(lua_State* L, umt_t& umx) { static int uniqueness = 0; - std::string uniquegcmetakey = usertype_traits::user_gc_metatable; + std::string uniquegcmetakey = usertype_traits::user_gc_metatable(); // std::to_string doesn't exist in android still, with NDK, so this bullshit // is necessary // thanks, Android :v @@ -10556,8 +10556,11 @@ namespace sol { snprintf(uniquetarget, uniquegcmetakey.length(), "%d", uniqueness); ++uniqueness; - const char* gcmetakey = &usertype_traits::gc_table[0]; - stack::push>(L, metatable_key, uniquegcmetakey, &usertype_traits::metatable[0], umx.indexbaseclasspropogation, umx.newindexbaseclasspropogation, std::move(umx.varmap), std::move(umx.registrations)); + const char* gcmetakey = &usertype_traits::gc_table()[0]; + stack::push>(L, metatable_key, uniquegcmetakey, &usertype_traits::metatable()[0], + umx.indexbaseclasspropogation, umx.newindexbaseclasspropogation, + std::move(umx.varmap), std::move(umx.registrations) + ); stack_reference stackvarmap(L, -1); stack::set_field(L, gcmetakey, stackvarmap); stackvarmap.pop(); @@ -10611,14 +10614,14 @@ namespace sol { const char* metakey = nullptr; switch (i) { case 0: - metakey = &usertype_traits::metatable[0]; + metakey = &usertype_traits::metatable()[0]; break; case 1: - metakey = &usertype_traits>::metatable[0]; + metakey = &usertype_traits>::metatable()[0]; break; case 2: default: - metakey = &usertype_traits::metatable[0]; + metakey = &usertype_traits::metatable()[0]; break; } luaL_newmetatable(L, metakey); @@ -10704,7 +10707,7 @@ namespace sol { } // Now for the shim-table that actually gets pushed - luaL_newmetatable(L, &usertype_traits::user_metatable[0]); + luaL_newmetatable(L, &usertype_traits::user_metatable()[0]); stack_reference t(L, -1); for (auto& kvp : varmap.functions) { auto& first = std::get<0>(kvp); @@ -11088,7 +11091,7 @@ namespace sol { typedef container_usertype_metatable cumt; static int push(lua_State* L, const T& cont) { auto fx = [&L]() { - const char* metakey = &usertype_traits::metatable[0]; + const char* metakey = &usertype_traits::metatable()[0]; if (luaL_newmetatable(L, metakey) == 1) { const auto& reg = stack_detail::container_metatable(); luaL_setfuncs(L, reg, 0); @@ -11100,7 +11103,7 @@ namespace sol { static int push(lua_State* L, T&& cont) { auto fx = [&L]() { - const char* metakey = &usertype_traits::metatable[0]; + const char* metakey = &usertype_traits::metatable()[0]; if (luaL_newmetatable(L, metakey) == 1) { const auto& reg = stack_detail::container_metatable(); luaL_setfuncs(L, reg, 0); @@ -11116,7 +11119,7 @@ namespace sol { typedef container_usertype_metatable cumt; static int push(lua_State* L, T* cont) { auto fx = [&L]() { - const char* metakey = &usertype_traits*>::metatable[0]; + const char* metakey = &usertype_traits*>::metatable()[0]; if (luaL_newmetatable(L, metakey) == 1) { const auto& reg = stack_detail::container_metatable(); luaL_setfuncs(L, reg, 0); @@ -11512,7 +11515,7 @@ namespace sol { template basic_table_core& set_usertype(usertype& user) { - return set_usertype(usertype_traits::name, user); + return set_usertype(usertype_traits::name(), user); } template @@ -12138,7 +12141,7 @@ namespace sol { template state_view& set_usertype(usertype& user) { - return set_usertype(usertype_traits::name, user); + return set_usertype(usertype_traits::name(), user); } template diff --git a/sol/call.hpp b/sol/call.hpp index ff757c9e..7e46a459 100644 --- a/sol/call.hpp +++ b/sol/call.hpp @@ -106,9 +106,9 @@ namespace sol { template inline int construct(lua_State* L) { - static const auto& meta = usertype_traits::metatable; + static const auto& meta = usertype_traits::metatable(); int argcount = lua_gettop(L); - call_syntax syntax = argcount > 0 ? stack::get_call_syntax(L, &usertype_traits::user_metatable[0], 1) : call_syntax::dot; + call_syntax syntax = argcount > 0 ? stack::get_call_syntax(L, &usertype_traits::user_metatable()[0], 1) : call_syntax::dot; argcount -= static_cast(syntax); T** pointerpointer = reinterpret_cast(lua_newuserdata(L, sizeof(T*) + sizeof(T))); @@ -344,9 +344,9 @@ namespace sol { typedef constructor_list F; static int call(lua_State* L, F&) { - const auto& metakey = usertype_traits::metatable; + const auto& metakey = usertype_traits::metatable(); int argcount = lua_gettop(L); - call_syntax syntax = argcount > 0 ? stack::get_call_syntax(L, &usertype_traits::user_metatable[0], 1) : call_syntax::dot; + call_syntax syntax = argcount > 0 ? stack::get_call_syntax(L, &usertype_traits::user_metatable()[0], 1) : call_syntax::dot; argcount -= static_cast(syntax); T** pointerpointer = reinterpret_cast(lua_newuserdata(L, sizeof(T*) + sizeof(T))); @@ -376,7 +376,7 @@ namespace sol { struct onmatch { template int operator()(types, index_value, types r, types a, lua_State* L, int, int start, F& f) { - const auto& metakey = usertype_traits::metatable; + const auto& metakey = usertype_traits::metatable(); T** pointerpointer = reinterpret_cast(lua_newuserdata(L, sizeof(T*) + sizeof(T))); reference userdataref(L, -1); T*& referencepointer = *pointerpointer; @@ -391,7 +391,7 @@ namespace sol { if (type_of(L, -1) == type::nil) { lua_pop(L, 1); std::string err = "sol: unable to get usertype metatable for "; - err += usertype_traits::name; + err += usertype_traits::name(); return luaL_error(L, err.c_str()); } lua_setmetatable(L, -2); @@ -401,7 +401,7 @@ namespace sol { }; static int call(lua_State* L, F& f) { - call_syntax syntax = stack::get_call_syntax(L, &usertype_traits::user_metatable[0]); + call_syntax syntax = stack::get_call_syntax(L, &usertype_traits::user_metatable()[0]); int syntaxval = static_cast(syntax); int argcount = lua_gettop(L) - syntaxval; return construct_match>...>(onmatch(), L, argcount, 1 + syntaxval, f); diff --git a/sol/container_usertype_metatable.hpp b/sol/container_usertype_metatable.hpp index 3f9e98da..d8f78be6 100644 --- a/sol/container_usertype_metatable.hpp +++ b/sol/container_usertype_metatable.hpp @@ -364,7 +364,7 @@ namespace sol { typedef container_usertype_metatable cumt; static int push(lua_State* L, const T& cont) { auto fx = [&L]() { - const char* metakey = &usertype_traits::metatable[0]; + const char* metakey = &usertype_traits::metatable()[0]; if (luaL_newmetatable(L, metakey) == 1) { const auto& reg = stack_detail::container_metatable(); luaL_setfuncs(L, reg, 0); @@ -376,7 +376,7 @@ namespace sol { static int push(lua_State* L, T&& cont) { auto fx = [&L]() { - const char* metakey = &usertype_traits::metatable[0]; + const char* metakey = &usertype_traits::metatable()[0]; if (luaL_newmetatable(L, metakey) == 1) { const auto& reg = stack_detail::container_metatable(); luaL_setfuncs(L, reg, 0); @@ -392,7 +392,7 @@ namespace sol { typedef container_usertype_metatable cumt; static int push(lua_State* L, T* cont) { auto fx = [&L]() { - const char* metakey = &usertype_traits*>::metatable[0]; + const char* metakey = &usertype_traits*>::metatable()[0]; if (luaL_newmetatable(L, metakey) == 1) { const auto& reg = stack_detail::container_metatable(); luaL_setfuncs(L, reg, 0); diff --git a/sol/simple_usertype_metatable.hpp b/sol/simple_usertype_metatable.hpp index 9ba31ff4..482ad803 100644 --- a/sol/simple_usertype_metatable.hpp +++ b/sol/simple_usertype_metatable.hpp @@ -78,14 +78,14 @@ namespace sol { const char* metakey = nullptr; switch (i) { case 0: - metakey = &usertype_traits::metatable[0]; + metakey = &usertype_traits::metatable()[0]; break; case 1: - metakey = &usertype_traits>::metatable[0]; + metakey = &usertype_traits>::metatable()[0]; break; case 2: default: - metakey = &usertype_traits::metatable[0]; + metakey = &usertype_traits::metatable()[0]; break; } luaL_getmetatable(L, metakey); @@ -354,7 +354,7 @@ namespace sol { static usertype_detail::simple_map& make_cleanup(lua_State* L, umt_t& umx) { static int uniqueness = 0; - std::string uniquegcmetakey = usertype_traits::user_gc_metatable; + std::string uniquegcmetakey = usertype_traits::user_gc_metatable(); // std::to_string doesn't exist in android still, with NDK, so this bullshit // is necessary // thanks, Android :v @@ -365,8 +365,11 @@ namespace sol { snprintf(uniquetarget, uniquegcmetakey.length(), "%d", uniqueness); ++uniqueness; - const char* gcmetakey = &usertype_traits::gc_table[0]; - stack::push>(L, metatable_key, uniquegcmetakey, &usertype_traits::metatable[0], umx.indexbaseclasspropogation, umx.newindexbaseclasspropogation, std::move(umx.varmap), std::move(umx.registrations)); + const char* gcmetakey = &usertype_traits::gc_table()[0]; + stack::push>(L, metatable_key, uniquegcmetakey, &usertype_traits::metatable()[0], + umx.indexbaseclasspropogation, umx.newindexbaseclasspropogation, + std::move(umx.varmap), std::move(umx.registrations) + ); stack_reference stackvarmap(L, -1); stack::set_field(L, gcmetakey, stackvarmap); stackvarmap.pop(); @@ -420,14 +423,14 @@ namespace sol { const char* metakey = nullptr; switch (i) { case 0: - metakey = &usertype_traits::metatable[0]; + metakey = &usertype_traits::metatable()[0]; break; case 1: - metakey = &usertype_traits>::metatable[0]; + metakey = &usertype_traits>::metatable()[0]; break; case 2: default: - metakey = &usertype_traits::metatable[0]; + metakey = &usertype_traits::metatable()[0]; break; } luaL_newmetatable(L, metakey); @@ -513,7 +516,7 @@ namespace sol { } // Now for the shim-table that actually gets pushed - luaL_newmetatable(L, &usertype_traits::user_metatable[0]); + luaL_newmetatable(L, &usertype_traits::user_metatable()[0]); stack_reference t(L, -1); for (auto& kvp : varmap.functions) { auto& first = std::get<0>(kvp); diff --git a/sol/stack_check.hpp b/sol/stack_check.hpp index 9ac0db75..314fc909 100644 --- a/sol/stack_check.hpp +++ b/sol/stack_check.hpp @@ -34,7 +34,7 @@ namespace sol { namespace stack_detail { template inline bool check_metatable(lua_State* L, int index = -2) { - const auto& metakey = usertype_traits::metatable; + const auto& metakey = usertype_traits::metatable(); luaL_getmetatable(L, &metakey[0]); const type expectedmetatabletype = static_cast(lua_type(L, -1)); if (expectedmetatabletype != type::nil) { diff --git a/sol/stack_push.hpp b/sol/stack_push.hpp index 27d28fc0..cf39d1e4 100644 --- a/sol/stack_push.hpp +++ b/sol/stack_push.hpp @@ -62,7 +62,7 @@ namespace sol { template static int push(lua_State* L, Args&&... args) { - return push_keyed(L, usertype_traits::metatable, std::forward(args)...); + return push_keyed(L, usertype_traits::metatable(), std::forward(args)...); } }; @@ -87,7 +87,7 @@ namespace sol { } static int push(lua_State* L, T* obj) { - return push_keyed(L, usertype_traits*>::metatable, obj); + return push_keyed(L, usertype_traits*>::metatable(), obj); } }; @@ -140,7 +140,7 @@ namespace sol { *fx = detail::special_destruct; detail::default_construct::construct(mem, std::forward(args)...); *pref = unique_usertype_traits::get(*mem); - if (luaL_newmetatable(L, &usertype_traits>::metatable[0]) == 1) { + if (luaL_newmetatable(L, &usertype_traits>::metatable()[0]) == 1) { set_field(L, "__gc", detail::unique_destruct

); } lua_setmetatable(L, -2); @@ -362,13 +362,13 @@ namespace sol { template , no_metatable_t, metatable_key_t>> = meta::enabler> static int push(lua_State* L, Arg&& arg, Args&&... args) { - const auto name = &usertype_traits>::user_gc_metatable[0]; + const auto name = &usertype_traits>::user_gc_metatable()[0]; return push_with(L, name, std::forward(arg), std::forward(args)...); } template static int push(lua_State* L, no_metatable_t, Args&&... args) { - const auto name = &usertype_traits>::user_gc_metatable[0]; + const auto name = &usertype_traits>::user_gc_metatable()[0]; return push_with(L, name, std::forward(args)...); } @@ -379,22 +379,22 @@ namespace sol { } static int push(lua_State* L, const user& u) { - const auto name = &usertype_traits>::user_gc_metatable[0]; + const auto name = &usertype_traits>::user_gc_metatable()[0]; return push_with(L, name, u.value); } static int push(lua_State* L, user&& u) { - const auto name = &usertype_traits>::user_gc_metatable[0]; + const auto name = &usertype_traits>::user_gc_metatable()[0]; return push_with(L, name, std::move(u.value)); } static int push(lua_State* L, no_metatable_t, const user& u) { - const auto name = &usertype_traits>::user_gc_metatable[0]; + const auto name = &usertype_traits>::user_gc_metatable()[0]; return push_with(L, name, u.value); } static int push(lua_State* L, no_metatable_t, user&& u) { - const auto name = &usertype_traits>::user_gc_metatable[0]; + const auto name = &usertype_traits>::user_gc_metatable()[0]; return push_with(L, name, std::move(u.value)); } }; diff --git a/sol/state_view.hpp b/sol/state_view.hpp index 3efb3674..a6ec3290 100644 --- a/sol/state_view.hpp +++ b/sol/state_view.hpp @@ -317,7 +317,7 @@ namespace sol { template state_view& set_usertype(usertype& user) { - return set_usertype(usertype_traits::name, user); + return set_usertype(usertype_traits::name(), user); } template diff --git a/sol/table_core.hpp b/sol/table_core.hpp index 918f3d4a..006f6dd7 100644 --- a/sol/table_core.hpp +++ b/sol/table_core.hpp @@ -244,7 +244,7 @@ namespace sol { template basic_table_core& set_usertype(usertype& user) { - return set_usertype(usertype_traits::name, user); + return set_usertype(usertype_traits::name(), user); } template diff --git a/sol/usertype_metatable.hpp b/sol/usertype_metatable.hpp index 4e55018c..fff5f60d 100644 --- a/sol/usertype_metatable.hpp +++ b/sol/usertype_metatable.hpp @@ -116,8 +116,8 @@ namespace sol { static void walk_single_base(lua_State* L, bool& found, int& ret, string_detail::string_shim&) { if (found) return; - const char* metakey = &usertype_traits::metatable[0]; - const char* gcmetakey = &usertype_traits::gc_table[0]; + const char* metakey = &usertype_traits::metatable()[0]; + const char* gcmetakey = &usertype_traits::gc_table()[0]; const char* basewalkkey = is_index ? detail::base_class_index_propogation_key() : detail::base_class_new_index_propogation_key(); luaL_getmetatable(L, metakey); @@ -466,7 +466,7 @@ namespace sol { static umt_t& make_cleanup(lua_State* L, umt_t&& umx) { // ensure some sort of uniqueness static int uniqueness = 0; - std::string uniquegcmetakey = usertype_traits::user_gc_metatable; + std::string uniquegcmetakey = usertype_traits::user_gc_metatable(); // std::to_string doesn't exist in android still, with NDK, so this bullshit // is necessary // thanks, Android :v @@ -477,7 +477,7 @@ namespace sol { snprintf(uniquetarget, uniquegcmetakey.length(), "%d", uniqueness); ++uniqueness; - const char* gcmetakey = &usertype_traits::gc_table[0]; + const char* gcmetakey = &usertype_traits::gc_table()[0]; // Make sure userdata's memory is properly in lua first, // otherwise all the light userdata we make later will become invalid stack::push>(L, metatable_key, uniquegcmetakey, std::move(umx)); @@ -514,16 +514,16 @@ namespace sol { luaL_Reg* metaregs = nullptr; switch (i) { case 0: - metakey = &usertype_traits::metatable[0]; + metakey = &usertype_traits::metatable()[0]; metaregs = ref_table.data(); break; case 1: - metakey = &usertype_traits>::metatable[0]; + metakey = &usertype_traits>::metatable()[0]; metaregs = unique_table.data(); break; case 2: default: - metakey = &usertype_traits::metatable[0]; + metakey = &usertype_traits::metatable()[0]; metaregs = value_table.data(); break; } @@ -571,7 +571,7 @@ namespace sol { } // Now for the shim-table that actually gets assigned to the name - luaL_newmetatable(L, &usertype_traits::user_metatable[0]); + luaL_newmetatable(L, &usertype_traits::user_metatable()[0]); stack_reference t(L, -1); stack::push(L, make_light(um)); luaL_setfuncs(L, value_table.data(), 1); diff --git a/sol/usertype_traits.hpp b/sol/usertype_traits.hpp index 38438c6d..d1439ed0 100644 --- a/sol/usertype_traits.hpp +++ b/sol/usertype_traits.hpp @@ -28,32 +28,32 @@ namespace sol { template struct usertype_traits { - static const std::string name; - static const std::string qualified_name; - static const std::string metatable; - static const std::string user_metatable; - static const std::string user_gc_metatable; - static const std::string gc_table; + static const std::string& name() { + static const std::string n = detail::short_demangle(); + return n; + } + static const std::string& qualified_name() { + static const std::string q_n = detail::demangle(); + return q_n; + } + static const std::string& metatable() { + static const std::string m = std::string("sol.").append(detail::demangle()); + return m; + } + static const std::string& user_metatable() { + static const std::string u_m = std::string("sol.").append(detail::demangle()).append(".user"); + return u_m; + } + static const std::string& user_gc_metatable() { + static const std::string u_g_m = std::string("sol.").append(detail::demangle()).append(".user\xE2\x99\xBB"); + return u_g_m; + } + static const std::string& gc_table() { + static const std::string g_t = std::string("sol.").append(detail::demangle().append(".\xE2\x99\xBB")); + return g_t; + } }; - template - const std::string usertype_traits::name = detail::short_demangle(); - - template - const std::string usertype_traits::qualified_name = detail::demangle(); - - template - const std::string usertype_traits::metatable = std::string("sol.").append(detail::demangle()); - - template - const std::string usertype_traits::user_metatable = std::string("sol.").append(detail::demangle()).append(".user"); - - template - const std::string usertype_traits::user_gc_metatable = std::string("sol.").append(detail::demangle()).append(".user\xE2\x99\xBB"); - - template - const std::string usertype_traits::gc_table = std::string("sol.").append(detail::demangle().append(".\xE2\x99\xBB")); - } #endif // SOL_USERTYPE_TRAITS_HPP