From 5093f61615dbc3233fcff99a5d7ac5f1b13a66e0 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Tue, 30 Aug 2016 18:09:07 -0400 Subject: [PATCH] Attempt to fix #119 by using less-powerful C++11 features and praying for the best Fix #205 Partially address #204 (will need to do more -- perhaps add an automatic-conversion shim?) --- single/sol/sol.hpp | 59 ++++++++++++++++++++-------- sol/container_usertype_metatable.hpp | 29 +++++++++++--- sol/traits.hpp | 12 +++--- sol/usertype_metatable.hpp | 13 +++++- 4 files changed, 83 insertions(+), 30 deletions(-) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 2cb58149..ce929a37 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-08-27 12:45:21.542724 UTC -// This header was generated with sol v2.12.1 (revision 580ebc7) +// Generated 2016-08-30 17:35:03.221817 UTC +// This header was generated with sol v2.12.1 (revision 5b5d1e9) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -704,32 +704,32 @@ namespace sol { } template - decltype(auto) deref(T&& item) { + auto deref(T&& item) -> decltype(std::forward(item)) { return std::forward(item); } template - T& deref(T* item) { + inline T& deref(T* item) { return *item; } template - decltype(auto) deref(std::unique_ptr& item) { + inline std::add_lvalue_reference_t deref(std::unique_ptr& item) { return *item; } template - T& deref(std::shared_ptr& item) { + inline std::add_lvalue_reference_t deref(std::shared_ptr& item) { return *item; } template - decltype(auto) deref(const std::unique_ptr& item) { + inline std::add_lvalue_reference_t deref(const std::unique_ptr& item) { return *item; } template - T& deref(const std::shared_ptr& item) { + inline std::add_lvalue_reference_t deref(const std::shared_ptr& item) { return *item; } @@ -9369,6 +9369,8 @@ namespace sol { // end of sol/deprecate.hpp +#include + namespace sol { namespace usertype_detail { struct no_comp { @@ -9790,9 +9792,17 @@ namespace sol { // ensure some sort of uniqueness static int uniqueness = 0; std::string uniquegcmetakey = usertype_traits::user_gc_metatable; - uniquegcmetakey.append(std::to_string(uniqueness++)); + // std::to_string doesn't exist in android still, with NDK, so this bullshit + // is necessary + // thanks, Android :v + int appended = std::snprintf(nullptr, 0, "%d", uniqueness); + std::size_t insertionpoint = uniquegcmetakey.length() - 1; + uniquegcmetakey.append(appended, '\0'); + char* uniquetarget = &uniquegcmetakey[insertionpoint]; + std::snprintf(uniquetarget, uniquegcmetakey.length(), "%d", uniqueness); + ++uniqueness; + 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)); @@ -10404,8 +10414,7 @@ namespace sol { template struct pusher, meta::neg, std::is_base_of>>>::value>> { typedef container_usertype_metatable cumt; - template - static int push(lua_State* L, C&& cont) { + static int push(lua_State* L, const T& cont) { auto fx = [&L]() { const char* metakey = &usertype_traits::metatable[0]; if (luaL_newmetatable(L, metakey) == 1) { @@ -10421,15 +10430,33 @@ namespace sol { } lua_setmetatable(L, -2); }; - return pusher>{}.push_fx(L, fx, std::forward(cont)); + return pusher>{}.push_fx(L, fx, cont); + } + + static int push(lua_State* L, T&& cont) { + auto fx = [&L]() { + const char* metakey = &usertype_traits::metatable[0]; + if (luaL_newmetatable(L, metakey) == 1) { + luaL_Reg reg[] = { + { "__index", &cumt::index_call }, + { "__newindex", &cumt::new_index_call }, + { "__pairs", &cumt::pairs_call }, + { "__len", &cumt::length_call }, + { "__gc", &detail::usertype_alloc_destroy }, + { nullptr, nullptr } + }; + luaL_setfuncs(L, reg, 0); + } + lua_setmetatable(L, -2); + }; + return pusher>{}.push_fx(L, fx, std::move(cont)); } }; template struct pusher>, meta::neg>, std::is_base_of>>>>::value>> { typedef container_usertype_metatable cumt; - template - static int push(lua_State* L, C&& cont) { + static int push(lua_State* L, T* cont) { auto fx = [&L]() { const char* metakey = &usertype_traits*>::metatable[0]; if (luaL_newmetatable(L, metakey) == 1) { @@ -10444,7 +10471,7 @@ namespace sol { } lua_setmetatable(L, -2); }; - return pusher>>{}.push_fx(L, fx, std::forward(cont)); + return pusher>{}.push_fx(L, fx, cont); } }; } // stack diff --git a/sol/container_usertype_metatable.hpp b/sol/container_usertype_metatable.hpp index ae506805..0d876b60 100644 --- a/sol/container_usertype_metatable.hpp +++ b/sol/container_usertype_metatable.hpp @@ -346,8 +346,7 @@ namespace sol { template struct pusher, meta::neg, std::is_base_of>>>::value>> { typedef container_usertype_metatable cumt; - template - static int push(lua_State* L, C&& cont) { + static int push(lua_State* L, const T& cont) { auto fx = [&L]() { const char* metakey = &usertype_traits::metatable[0]; if (luaL_newmetatable(L, metakey) == 1) { @@ -363,15 +362,33 @@ namespace sol { } lua_setmetatable(L, -2); }; - return pusher>{}.push_fx(L, fx, std::forward(cont)); + return pusher>{}.push_fx(L, fx, cont); + } + + static int push(lua_State* L, T&& cont) { + auto fx = [&L]() { + const char* metakey = &usertype_traits::metatable[0]; + if (luaL_newmetatable(L, metakey) == 1) { + luaL_Reg reg[] = { + { "__index", &cumt::index_call }, + { "__newindex", &cumt::new_index_call }, + { "__pairs", &cumt::pairs_call }, + { "__len", &cumt::length_call }, + { "__gc", &detail::usertype_alloc_destroy }, + { nullptr, nullptr } + }; + luaL_setfuncs(L, reg, 0); + } + lua_setmetatable(L, -2); + }; + return pusher>{}.push_fx(L, fx, std::move(cont)); } }; template struct pusher>, meta::neg>, std::is_base_of>>>>::value>> { typedef container_usertype_metatable cumt; - template - static int push(lua_State* L, C&& cont) { + static int push(lua_State* L, T* cont) { auto fx = [&L]() { const char* metakey = &usertype_traits*>::metatable[0]; if (luaL_newmetatable(L, metakey) == 1) { @@ -386,7 +403,7 @@ namespace sol { } lua_setmetatable(L, -2); }; - return pusher>>{}.push_fx(L, fx, std::forward(cont)); + return pusher>{}.push_fx(L, fx, cont); } }; } // stack diff --git a/sol/traits.hpp b/sol/traits.hpp index 8d7195fd..3e0fd9fe 100644 --- a/sol/traits.hpp +++ b/sol/traits.hpp @@ -376,32 +376,32 @@ namespace sol { } template - decltype(auto) deref(T&& item) { + auto deref(T&& item) -> decltype(std::forward(item)) { return std::forward(item); } template - T& deref(T* item) { + inline T& deref(T* item) { return *item; } template - decltype(auto) deref(std::unique_ptr& item) { + inline std::add_lvalue_reference_t deref(std::unique_ptr& item) { return *item; } template - T& deref(std::shared_ptr& item) { + inline std::add_lvalue_reference_t deref(std::shared_ptr& item) { return *item; } template - decltype(auto) deref(const std::unique_ptr& item) { + inline std::add_lvalue_reference_t deref(const std::unique_ptr& item) { return *item; } template - T& deref(const std::shared_ptr& item) { + inline std::add_lvalue_reference_t deref(const std::shared_ptr& item) { return *item; } diff --git a/sol/usertype_metatable.hpp b/sol/usertype_metatable.hpp index dbfea5d3..8669b8f9 100644 --- a/sol/usertype_metatable.hpp +++ b/sol/usertype_metatable.hpp @@ -31,6 +31,7 @@ #include "inheritance.hpp" #include "raii.hpp" #include "deprecate.hpp" +#include namespace sol { namespace usertype_detail { @@ -453,9 +454,17 @@ namespace sol { // ensure some sort of uniqueness static int uniqueness = 0; std::string uniquegcmetakey = usertype_traits::user_gc_metatable; - uniquegcmetakey.append(std::to_string(uniqueness++)); + // std::to_string doesn't exist in android still, with NDK, so this bullshit + // is necessary + // thanks, Android :v + int appended = std::snprintf(nullptr, 0, "%d", uniqueness); + std::size_t insertionpoint = uniquegcmetakey.length() - 1; + uniquegcmetakey.append(appended, '\0'); + char* uniquetarget = &uniquegcmetakey[insertionpoint]; + std::snprintf(uniquetarget, uniquegcmetakey.length(), "%d", uniqueness); + ++uniqueness; + 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));