From fc91147edcf21f849a7cbb2df28338ef3bf4855f Mon Sep 17 00:00:00 2001 From: ThePhD Date: Tue, 5 Sep 2017 21:07:33 -0400 Subject: [PATCH] fix errors --- single/sol/sol.hpp | 698 +++++++++++++++++++++++------------------- sol/error_handler.hpp | 2 +- sol/stack_push.hpp | 16 + 3 files changed, 408 insertions(+), 308 deletions(-) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index c1a9d41d..09307856 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 2017-09-03 13:52:23.734893 UTC -// This header was generated with sol v2.18.2 (revision 1f64a7f) +// Generated 2017-09-06 01:05:13.658647 UTC +// This header was generated with sol v2.18.2 (revision eb313eb) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -3681,90 +3681,99 @@ namespace sol { // end of sol/forward_detail.hpp -// beginning of sol/string_shim.hpp +// beginning of sol/string_view.hpp #ifdef SOL_CXX17_FEATURES #endif // C++17 features namespace sol { - namespace string_detail { #ifdef SOL_CXX17_FEATURES - typedef std::string_view string_shim; + typedef std::string_view string_view; + typedef std::wstring_view wstring_view; + typedef std::u16string_view u16string_view; + typedef std::u32string_view u32string_view; #else - struct string_shim { - std::size_t s; - const char* p; + template > + struct basic_string_view { + std::size_t s; + const Char* p; - string_shim(const std::string& r) : string_shim(r.data(), r.size()) {} - string_shim(const char* ptr) : string_shim(ptr, std::char_traits::length(ptr)) {} - string_shim(const char* ptr, std::size_t sz) : s(sz), p(ptr) {} + 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 = std::char_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; - } + 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* begin() const { + return p; + } - const char* end() const { - return p + s; - } + const Char* end() const { + return p + s; + } - const char* cbegin() const { - return p; - } + const Char* cbegin() const { + return p; + } - const char* cend() const { - return p + s; - } + const Char* cend() const { + return p + s; + } - const char* data() const { - return p; - } + const Char* data() const { + return p; + } - std::size_t size() const { - return s; - } + std::size_t size() const { + return s; + } - bool operator==(const string_shim& r) const { - return compare(p, s, r.data(), r.size()) == 0; - } + std::size_t length() const { + return size(); + } - bool operator==(const char* r) const { - return compare(r, std::char_traits::length(r), p, s) == 0; - } + bool operator==(const basic_string_view& r) const { + return compare(p, s, r.data(), r.size()) == 0; + } - bool operator==(const std::string& r) const { - return compare(r.data(), r.size(), p, s) == 0; - } + bool operator==(const Char* r) const { + return compare(r, std::char_traits::length(r), p, s) == 0; + } - bool operator!=(const string_shim& r) const { - return !(*this == r); - } + bool operator==(const std::basic_string& r) const { + return compare(r.data(), r.size(), p, s) == 0; + } - bool operator!=(const char* r) const { - return !(*this == r); - } + bool operator!=(const basic_string_view& r) const { + return !(*this == r); + } - bool operator!=(const std::string& r) const { - return !(*this == r); - } - }; -#endif // C++17 - } + bool operator!=(const char* r) const { + return !(*this == r); + } - typedef string_detail::string_shim string_view; + bool operator!=(const std::basic_string& r) const { + return !(*this == r); + } + }; + + using string_view = basic_string_view; + using wstring_view = basic_string_view; + using u16string_view = basic_string_view; + using u32string_view = basic_string_view; +#endif // C++17 Support } -// end of sol/string_shim.hpp +// end of sol/string_view.hpp // beginning of sol/raii.hpp @@ -4087,7 +4096,7 @@ namespace sol { struct no_metatable_t {}; const no_metatable_t no_metatable = {}; - typedef std::remove_pointer_t lua_r_CFunction; + typedef std::remove_pointer_t lua_CFunction_ref; template struct unique_usertype_traits { @@ -4518,13 +4527,15 @@ namespace sol { bitwise_or, bitwise_xor, pairs, - next + next, + type, + type_info, }; typedef meta_function meta_method; - inline const std::array& meta_function_names() { - static const std::array names = { { + inline const std::array& meta_function_names() { + static const std::array names = { { "new", "__index", "__newindex", @@ -4555,7 +4566,9 @@ namespace sol { "__bxor", "__pairs", - "__next" + "__next", + "__type", + "__typeinfo" } }; return names; } @@ -4787,24 +4800,21 @@ namespace sol { template <> struct lua_type_of : std::integral_constant {}; + template <> + struct lua_type_of : std::integral_constant {}; + + template <> + struct lua_type_of : std::integral_constant {}; + + template <> + struct lua_type_of : std::integral_constant {}; + + template <> + struct lua_type_of : std::integral_constant {}; + #ifdef SOL_CXX17_FEATURES - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - - template <> - struct lua_type_of : std::integral_constant {}; - template struct lua_type_of> : std::integral_constant {}; -#else - template <> - struct lua_type_of : std::integral_constant {}; #endif // C++ 17 (or not) features template @@ -5016,6 +5026,149 @@ namespace sol { // beginning of sol/error_handler.hpp +// beginning of sol/demangle.hpp + +#include +#if defined(__GNUC__) && defined(__MINGW32__) && (__GNUC__ < 6) +extern "C" { +#include +} +#endif // MinGW is on some stuff +#include + +namespace sol { + namespace detail { +#if defined(__GNUC__) || defined(__clang__) + template + inline std::string ctti_get_type_name() { + // cardinal sins from MINGW + using namespace std; + const static std::array removals = { { "{anonymous}", "(anonymous namespace)" } }; + std::string name = __PRETTY_FUNCTION__; + std::size_t start = name.find_first_of('['); + start = name.find_first_of('=', start); + std::size_t end = name.find_last_of(']'); + if (end == std::string::npos) + end = name.size(); + if (start == std::string::npos) + start = 0; + if (start < name.size() - 1) + start += 1; + name = name.substr(start, end - start); + start = name.rfind("seperator_mark"); + if (start != std::string::npos) { + name.erase(start - 2, name.length()); + } + while (!name.empty() && isblank(name.front())) name.erase(name.begin()); + while (!name.empty() && isblank(name.back())) name.pop_back(); + + for (std::size_t r = 0; r < removals.size(); ++r) { + auto found = name.find(removals[r]); + while (found != std::string::npos) { + name.erase(found, removals[r].size()); + found = name.find(removals[r]); + } + } + + return name; + } +#elif defined(_MSC_VER) + template + inline std::string ctti_get_type_name() { + const static std::array removals = { { "public:", "private:", "protected:", "struct ", "class ", "`anonymous-namespace'", "`anonymous namespace'" } }; + std::string name = __FUNCSIG__; + std::size_t start = name.find("get_type_name"); + if (start == std::string::npos) + start = 0; + else + start += 13; + if (start < name.size() - 1) + start += 1; + std::size_t end = name.find_last_of('>'); + if (end == std::string::npos) + end = name.size(); + name = name.substr(start, end - start); + if (name.find("struct", 0) == 0) + name.replace(0, 6, "", 0); + if (name.find("class", 0) == 0) + name.replace(0, 5, "", 0); + while (!name.empty() && isblank(name.front())) name.erase(name.begin()); + while (!name.empty() && isblank(name.back())) name.pop_back(); + + for (std::size_t r = 0; r < removals.size(); ++r) { + auto found = name.find(removals[r]); + while (found != std::string::npos) { + name.erase(found, removals[r].size()); + found = name.find(removals[r]); + } + } + + return name; + } +#else +#error Compiler not supported for demangling +#endif // compilers + + template + inline std::string demangle_once() { + std::string realname = ctti_get_type_name(); + return realname; + } + + template + inline std::string short_demangle_once() { + std::string realname = ctti_get_type_name(); + // This isn't the most complete but it'll do for now...? + static const std::array ops = { { "operator<", "operator<<", "operator<<=", "operator<=", "operator>", "operator>>", "operator>>=", "operator>=", "operator->", "operator->*" } }; + int level = 0; + std::ptrdiff_t idx = 0; + for (idx = static_cast(realname.empty() ? 0 : realname.size() - 1); idx > 0; --idx) { + if (level == 0 && realname[idx] == ':') { + break; + } + bool isleft = realname[idx] == '<'; + bool isright = realname[idx] == '>'; + if (!isleft && !isright) + continue; + bool earlybreak = false; + for (const auto& op : ops) { + std::size_t nisop = realname.rfind(op, idx); + if (nisop == std::string::npos) + continue; + std::size_t nisopidx = idx - op.size() + 1; + if (nisop == nisopidx) { + idx = static_cast(nisopidx); + earlybreak = true; + } + break; + } + if (earlybreak) { + continue; + } + level += isleft ? -1 : 1; + } + if (idx > 0) { + realname.erase(0, realname.length() < static_cast(idx) ? realname.length() : idx + 1); + } + return realname; + } + + template + inline const std::string& demangle() { + static const std::string d = demangle_once(); + return d; + } + + template + inline const std::string& short_demangle() { + static const std::string d = short_demangle_once(); + return d; + } + } // detail +} // sol + +// end of sol/demangle.hpp + namespace sol { inline int type_panic_string(lua_State* L, int index, type expected, type actual, const std::string& message = "") noexcept(false) { @@ -5056,12 +5209,33 @@ namespace sol { } }; + template struct argument_handler { int operator()(lua_State* L, int index, type expected, type actual, const std::string& message) const noexcept(false) { return type_panic_string(L, index, expected, actual, message + " (bad argument to variable or function call)"); } }; + template + struct argument_handler> { + int operator()(lua_State* L, int index, type expected, type actual, const std::string& message) const noexcept(false) { + std::string addendum = " (bad argument to type expecting '"; + addendum += detail::demangle(); + addendum += "("; + int marker = 0; + auto action = [&addendum, &marker](const std::string& n) { + if (marker > 0) { + addendum += ", "; + } + addendum += n; + ++marker; + }; + (void)detail::swallow{ int(), (action(detail::demangle()), int())... }; + addendum += ")')"; + return type_panic_string(L, index, expected, actual, message + addendum); + } + }; + // Specify this function as the handler for lua::check if you know there's nothing wrong inline int no_panic(lua_State*, int, type, type, const char* = nullptr) noexcept { return 0; @@ -5529,149 +5703,6 @@ namespace sol { // end of sol/stack_guard.hpp -// beginning of sol/demangle.hpp - -#include -#if defined(__GNUC__) && defined(__MINGW32__) && (__GNUC__ < 6) -extern "C" { -#include -} -#endif // MinGW is on some stuff -#include - -namespace sol { - namespace detail { -#if defined(__GNUC__) || defined(__clang__) - template - inline std::string ctti_get_type_name() { - // cardinal sins from MINGW - using namespace std; - const static std::array removals = { { "{anonymous}", "(anonymous namespace)" } }; - std::string name = __PRETTY_FUNCTION__; - std::size_t start = name.find_first_of('['); - start = name.find_first_of('=', start); - std::size_t end = name.find_last_of(']'); - if (end == std::string::npos) - end = name.size(); - if (start == std::string::npos) - start = 0; - if (start < name.size() - 1) - start += 1; - name = name.substr(start, end - start); - start = name.rfind("seperator_mark"); - if (start != std::string::npos) { - name.erase(start - 2, name.length()); - } - while (!name.empty() && isblank(name.front())) name.erase(name.begin()); - while (!name.empty() && isblank(name.back())) name.pop_back(); - - for (std::size_t r = 0; r < removals.size(); ++r) { - auto found = name.find(removals[r]); - while (found != std::string::npos) { - name.erase(found, removals[r].size()); - found = name.find(removals[r]); - } - } - - return name; - } -#elif defined(_MSC_VER) - template - inline std::string ctti_get_type_name() { - const static std::array removals = { { "public:", "private:", "protected:", "struct ", "class ", "`anonymous-namespace'", "`anonymous namespace'" } }; - std::string name = __FUNCSIG__; - std::size_t start = name.find("get_type_name"); - if (start == std::string::npos) - start = 0; - else - start += 13; - if (start < name.size() - 1) - start += 1; - std::size_t end = name.find_last_of('>'); - if (end == std::string::npos) - end = name.size(); - name = name.substr(start, end - start); - if (name.find("struct", 0) == 0) - name.replace(0, 6, "", 0); - if (name.find("class", 0) == 0) - name.replace(0, 5, "", 0); - while (!name.empty() && isblank(name.front())) name.erase(name.begin()); - while (!name.empty() && isblank(name.back())) name.pop_back(); - - for (std::size_t r = 0; r < removals.size(); ++r) { - auto found = name.find(removals[r]); - while (found != std::string::npos) { - name.erase(found, removals[r].size()); - found = name.find(removals[r]); - } - } - - return name; - } -#else -#error Compiler not supported for demangling -#endif // compilers - - template - inline std::string demangle_once() { - std::string realname = ctti_get_type_name(); - return realname; - } - - template - inline std::string short_demangle_once() { - std::string realname = ctti_get_type_name(); - // This isn't the most complete but it'll do for now...? - static const std::array ops = { { "operator<", "operator<<", "operator<<=", "operator<=", "operator>", "operator>>", "operator>>=", "operator>=", "operator->", "operator->*" } }; - int level = 0; - std::ptrdiff_t idx = 0; - for (idx = static_cast(realname.empty() ? 0 : realname.size() - 1); idx > 0; --idx) { - if (level == 0 && realname[idx] == ':') { - break; - } - bool isleft = realname[idx] == '<'; - bool isright = realname[idx] == '>'; - if (!isleft && !isright) - continue; - bool earlybreak = false; - for (const auto& op : ops) { - std::size_t nisop = realname.rfind(op, idx); - if (nisop == std::string::npos) - continue; - std::size_t nisopidx = idx - op.size() + 1; - if (nisop == nisopidx) { - idx = static_cast(nisopidx); - earlybreak = true; - } - break; - } - if (earlybreak) { - continue; - } - level += isleft ? -1 : 1; - } - if (idx > 0) { - realname.erase(0, realname.length() < static_cast(idx) ? realname.length() : idx + 1); - } - return realname; - } - - template - inline const std::string& demangle() { - static const std::string d = demangle_once(); - return d; - } - - template - inline const std::string& short_demangle() { - static const std::string d = short_demangle_once(); - return d; - } - } // detail -} // sol - -// end of sol/demangle.hpp - #include #include #include @@ -7171,6 +7202,16 @@ namespace sol { } }; + template<> + struct getter { + static string_view get(lua_State* L, int index, record& tracking) { + tracking.use(1); + size_t sz; + const char* str = lua_tolstring(L, index, &sz); + return string_view(str, sz); + } + }; + #ifdef SOL_CODECVT_SUPPORT template<> struct getter { @@ -7474,16 +7515,6 @@ namespace sol { }; #ifdef SOL_CXX17_FEATURES - template<> - struct getter { - static std::string_view get(lua_State* L, int index, record& tracking) { - tracking.use(1); - size_t sz; - const char* str = lua_tolstring(L, index, &sz); - return std::string_view(str, sz); - } - }; - template struct getter> { typedef std::variant V; @@ -7519,16 +7550,6 @@ namespace sol { return get_one(std::integral_constant(), L, index, tracking); } }; -#else - template <> - struct getter { - string_detail::string_shim get(lua_State* L, int index, record& tracking) { - tracking.use(1); - size_t len; - const char* p = lua_tolstring(L, index, &len); - return string_detail::string_shim(p, len); - } - }; #endif // C++17-wave } // stack @@ -8215,6 +8236,17 @@ namespace sol { } }; + template <> + struct pusher { + static int push(lua_State* L, const string_view& sv) { + return stack::push(L, sv.data(), sv.length()); + } + + static int push(lua_State* L, const string_view& sv, std::size_t n) { + return stack::push(L, sv.data(), n); + } + }; + template<> struct pusher { static int push(lua_State* L, meta_function m) { @@ -8404,6 +8436,39 @@ namespace sol { return stack::push(L, u32str.data(), u32str.data() + sz); } }; + + template <> + struct pusher { + static int push(lua_State* L, const wstring_view& sv) { + return stack::push(L, sv.data(), sv.length()); + } + + static int push(lua_State* L, const wstring_view& sv, std::size_t n) { + return stack::push(L, sv.data(), n); + } + }; + + template <> + struct pusher { + static int push(lua_State* L, const u16string_view& sv) { + return stack::push(L, sv.data(), sv.length()); + } + + static int push(lua_State* L, const u16string_view& sv, std::size_t n) { + return stack::push(L, sv.data(), n); + } + }; + + template <> + struct pusher { + static int push(lua_State* L, const u32string_view& sv) { + return stack::push(L, sv.data(), sv.length()); + } + + static int push(lua_State* L, const u32string_view& sv, std::size_t n) { + return stack::push(L, sv.data(), n); + } + }; #endif // codecvt Header Support template @@ -8474,35 +8539,6 @@ namespace sol { }; #ifdef SOL_CXX17_FEATURES - template <> - struct pusher { - static int push(lua_State* L, const std::string_view& sv) { - return stack::push(L, sv.data(), sv.length()); - } - }; -#ifdef SOL_CODECVT_SUPPORT - template <> - struct pusher { - static int push(lua_State* L, const std::wstring_view& sv) { - return stack::push(L, sv.data(), sv.length()); - } - }; - - template <> - struct pusher { - static int push(lua_State* L, const std::u16string_view& sv) { - return stack::push(L, sv.data(), sv.length()); - } - }; - - template <> - struct pusher { - static int push(lua_State* L, const std::u32string_view& sv) { - return stack::push(L, sv.data(), sv.length()); - } - }; -#endif // codecvt header support - namespace stack_detail { struct push_function { @@ -8528,7 +8564,8 @@ namespace sol { return std::visit(stack_detail::push_function(L), std::move(v)); } }; -#endif +#endif // C++17 Support + } // stack } // sol @@ -8949,8 +8986,8 @@ namespace sol { inline decltype(auto) call(types, types ta, std::index_sequence tai, lua_State* L, int start, Fx&& fx, FxArgs&&... args) { #ifndef _MSC_VER static_assert(meta::all...>::value, "One of the arguments being bound is a move-only type, and it is not being taken by reference: this will break your code. Please take a reference and std::move it manually if this was your intention."); -#endif // This compiler make me so fucking sad - argument_handler handler{}; +#endif // This compiler make me so sad + argument_handler> handler{}; multi_check(L, start, handler); record tracking{}; return evaluator{}.eval(ta, tai, L, start, tracking, std::forward(fx), std::forward(args)...); @@ -8961,7 +8998,7 @@ namespace sol { #ifndef _MSC_VER static_assert(meta::all...>::value, "One of the arguments being bound is a move-only type, and it is not being taken by reference: this will break your code. Please take a reference and std::move it manually if this was your intention."); #endif // This compiler make me so fucking sad - argument_handler handler{}; + argument_handler> handler{}; multi_check(L, start, handler); record tracking{}; evaluator{}.eval(ta, tai, L, start, tracking, std::forward(fx), std::forward(args)...); @@ -9047,7 +9084,7 @@ namespace sol { return call_syntax::colon; } - inline void script(lua_State* L, const string_detail::string_shim& code, const std::string& chunkname = detail::default_chunk_name(), load_mode mode = load_mode::any) { + inline void script(lua_State* L, const string_view& code, const std::string& chunkname = detail::default_chunk_name(), load_mode mode = load_mode::any) { char basechunkname[17] = {}; const char* chunknametarget = detail::make_chunk_name(code, chunkname, basechunkname); if (luaL_loadbufferx(L, code.data(), code.size(), chunknametarget, to_string(mode).c_str()) || lua_pcall(L, 0, LUA_MULTRET, 0)) { @@ -9927,8 +9964,8 @@ namespace sol { }; template - struct agnostic_lua_call_wrapper { - static int call(lua_State* L, lua_r_CFunction f) { + struct agnostic_lua_call_wrapper { + static int call(lua_State* L, lua_CFunction_ref f) { return f(L); } }; @@ -14344,6 +14381,11 @@ namespace sol { } }; + template + int is_check(lua_State* L) { + return stack::push(L, stack::check(L, 1, &no_panic)); + } + template inline int member_default_to_string(std::true_type, lua_State* L) { decltype(auto) ts = stack::get(L, 1).to_string(); @@ -14547,7 +14589,7 @@ namespace sol { const int index_function_index = 3; const int newindex_function_index = 4; - typedef void(*base_walk)(lua_State*, bool&, int&, string_detail::string_shim&); + typedef void(*base_walk)(lua_State*, bool&, int&, string_view&); typedef int(*member_search)(lua_State*, void*, int); struct call_information { @@ -14625,7 +14667,7 @@ namespace sol { namespace usertype_detail { const lua_Integer toplevel_magic = static_cast(0xCCC2CCC1); - inline int is_indexer(string_detail::string_shim s) { + inline int is_indexer(string_view s) { if (s == to_string(meta_function::index)) { return 1; } @@ -14653,31 +14695,31 @@ namespace sol { return 0; } - inline auto make_shim(string_detail::string_shim s) { + inline auto make_string_view(string_view s) { return s; } - inline auto make_shim(call_construction) { - return string_detail::string_shim(to_string(meta_function::call_function)); + inline auto make_string_view(call_construction) { + return string_view(to_string(meta_function::call_function)); } - inline auto make_shim(meta_function mf) { - return string_detail::string_shim(to_string(mf)); + inline auto make_string_view(meta_function mf) { + return string_view(to_string(mf)); } - inline auto make_shim(base_classes_tag) { - return string_detail::string_shim(detail::base_class_cast_key()); + inline auto make_string_view(base_classes_tag) { + return string_view(detail::base_class_cast_key()); } template inline std::string make_string(Arg&& arg) { - string_detail::string_shim s = make_shim(arg); + string_view s = make_string_view(arg); return std::string(s.data(), s.size()); } template inline luaL_Reg make_reg(N&& n, lua_CFunction f) { - luaL_Reg l{ make_shim(std::forward(n)).data(), f }; + luaL_Reg l{ make_string_view(std::forward(n)).data(), f }; return l; } @@ -14724,8 +14766,8 @@ namespace sol { #endif } else { - auto maybeaccessor = stack::get>(L, is_index ? -1 : -2); - string_detail::string_shim accessor = maybeaccessor.value_or(string_detail::string_shim("(unknown)")); + auto maybeaccessor = stack::get>(L, is_index ? -1 : -2); + string_view accessor = maybeaccessor.value_or(string_view("(unknown)")); return luaL_error(L, "sol: attempt to index (set) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.data()); } } @@ -14822,7 +14864,7 @@ namespace sol { } template - static void walk_single_base(lua_State* L, bool& found, int& ret, string_detail::string_shim&) { + static void walk_single_base(lua_State* L, bool& found, int& ret, string_view&) { if (found) return; const char* metakey = &usertype_traits::metatable()[0]; @@ -14852,7 +14894,7 @@ namespace sol { } template - static void walk_all_bases(lua_State* L, bool& found, int& ret, string_detail::string_shim& accessor) { + static void walk_all_bases(lua_State* L, bool& found, int& ret, string_view& accessor) { (void)L; (void)found; (void)ret; @@ -14876,7 +14918,7 @@ namespace sol { struct usertype_metatable, Tn...> : usertype_metatable_core, usertype_detail::registrar { typedef std::make_index_sequence indices; typedef std::index_sequence half_indices; - typedef std::array regs_t; + typedef std::array regs_t; typedef std::tuple RawTuple; typedef std::tuple ...> Tuple; template @@ -14891,7 +14933,7 @@ namespace sol { void* baseclasscheck; void* baseclasscast; bool secondarymeta; - std::array properties; + std::array properties; template >> = meta::enabler> lua_CFunction make_func() const { @@ -14901,7 +14943,7 @@ namespace sol { template >> = meta::enabler> lua_CFunction make_func() const { const auto& name = std::get(functions); - return (usertype_detail::make_shim(name) == "__newindex") ? &call : &call; + return (usertype_detail::make_string_view(name) == "__newindex") ? &call : &call; } static bool contains_variable() { @@ -15055,7 +15097,7 @@ namespace sol { const usertype_detail::member_search& member = is_index ? ci.index: ci.new_index; return (member)(L, static_cast(&f), ci.runtime_target); } - string_detail::string_shim accessor = name; + string_view accessor = name; int ret = 0; bool found = false; // Otherwise, we need to do propagating calls through the bases @@ -15173,6 +15215,12 @@ namespace sol { } unique_table[lastreg - 1] = { value_table[lastreg - 1].name, detail::unique_destruct }; + lua_createtable(L, 0, 2); + stack_reference type_table(L, -1); + + stack::set_field(L, "name", detail::demangle(), type_table.stack_index()); + stack::set_field(L, "is", &usertype_detail::is_check, type_table.stack_index()); + // Now use um const bool& mustindex = umc.mustindex; for (std::size_t i = 0; i < 3; ++i) { @@ -15196,6 +15244,7 @@ namespace sol { } luaL_newmetatable(L, metakey); stack_reference t(L, -1); + stack::set_field(L, meta_function::type, type_table, t.stack_index()); int upvalues = 0; upvalues += stack::push(L, nullptr); upvalues += stack::push(L, make_light(um)); @@ -15232,6 +15281,9 @@ namespace sol { stack::set_field(L, meta_function::index, make_closure(umt_t::index_call, nullptr, make_light(um), make_light(umc)), metabehind.stack_index()); stack::set_field(L, meta_function::new_index, make_closure(umt_t::new_index_call, nullptr, make_light(um), make_light(umc)), metabehind.stack_index()); } + // type information needs to be present on the behind-tables too + stack::set_field(L, meta_function::type, type_table, metabehind.stack_index()); + stack::set_field(L, metatable_key, metabehind, t.stack_index()); metabehind.pop(); // We want to just leave the table @@ -15242,6 +15294,7 @@ namespace sol { // Now for the shim-table that actually gets assigned to the name luaL_newmetatable(L, &usertype_traits::user_metatable()[0]); stack_reference t(L, -1); + stack::set_field(L, meta_function::type, type_table, t.stack_index()); int upvalues = 0; upvalues += stack::push(L, nullptr); upvalues += stack::push(L, make_light(um)); @@ -15255,11 +15308,14 @@ namespace sol { stack::set_field(L, meta_function::index, make_closure(umt_t::index_call, nullptr, make_light(um), make_light(umc), nullptr, usertype_detail::toplevel_magic), metabehind.stack_index()); stack::set_field(L, meta_function::new_index, make_closure(umt_t::new_index_call, nullptr, make_light(um), make_light(umc), nullptr, usertype_detail::toplevel_magic), metabehind.stack_index()); - stack::set_field(L, metatable_key, metabehind, t.stack_index()); + // type information needs to be present on the behind-tables too + stack::set_field(L, meta_function::type, type_table, metabehind.stack_index()); metabehind.pop(); } + lua_remove(L, type_table.stack_index()); + return 1; } }; @@ -15309,7 +15365,7 @@ namespace sol { } } } - string_detail::string_shim accessor = stack::get(L, keyidx); + string_view accessor = stack::get(L, keyidx); std::string accessorkey = accessor.data(); auto vit = variables.find(accessorkey); if (vit != variables.cend()) { @@ -15428,7 +15484,7 @@ namespace sol { void* baseclasscast; bool mustindex; bool secondarymeta; - std::array properties; + std::array properties; template void insert(N&& n, object&& o) { @@ -15659,6 +15715,13 @@ namespace sol { auto& properties = umx.properties; auto sic = hasindex ? &usertype_detail::simple_index_call : &usertype_detail::simple_index_call; auto snic = hasnewindex ? &usertype_detail::simple_new_index_call : &usertype_detail::simple_new_index_call; + + lua_createtable(L, 0, 2); + stack_reference type_table(L, -1); + + stack::set_field(L, "name", detail::demangle(), type_table.stack_index()); + stack::set_field(L, "is", &usertype_detail::is_check, type_table.stack_index()); + auto register_kvp = [&](std::size_t meta_index, stack_reference& t, const std::string& first, object& second) { meta_function mf = meta_function::construct; for (std::size_t j = 1; j < properties.size(); ++j) { @@ -15713,6 +15776,8 @@ namespace sol { } luaL_newmetatable(L, metakey); stack_reference t(L, -1); + stack::set_field(L, meta_function::type, type_table, t.stack_index()); + for (auto& kvp : varmap.functions) { auto& first = std::get<0>(kvp); auto& second = std::get<1>(kvp); @@ -15758,6 +15823,7 @@ namespace sol { // for call constructor purposes and such lua_createtable(L, 0, 2 * static_cast(umx.secondarymeta) + static_cast(umx.callconstructfunc.valid())); stack_reference metabehind(L, -1); + stack::set_field(L, meta_function::type, type_table, metabehind.stack_index()); if (umx.callconstructfunc.valid()) { stack::set_field(L, sol::meta_function::call_function, umx.callconstructfunc, metabehind.stack_index()); } @@ -15782,6 +15848,7 @@ namespace sol { // Now for the shim-table that actually gets pushed luaL_newmetatable(L, &usertype_traits::user_metatable()[0]); stack_reference t(L, -1); + stack::set_field(L, meta_function::type, type_table, t.stack_index()); for (auto& kvp : varmap.functions) { auto& first = std::get<0>(kvp); auto& second = std::get<1>(kvp); @@ -15790,6 +15857,7 @@ namespace sol { { lua_createtable(L, 0, 2 + static_cast(umx.callconstructfunc.valid())); stack_reference metabehind(L, -1); + stack::set_field(L, meta_function::type, type_table, metabehind.stack_index()); if (umx.callconstructfunc.valid()) { stack::set_field(L, sol::meta_function::call_function, umx.callconstructfunc, metabehind.stack_index()); } @@ -15814,6 +15882,8 @@ namespace sol { metabehind.pop(); } + lua_remove(L, type_table.stack_index()); + // Don't pop the table when we're done; // return it return 1; @@ -16758,19 +16828,33 @@ namespace sol { namespace sol { enum class lib : char { + // print, assert, and other base functions base, + // require and other package functions package, + // coroutine functions and utilities coroutine, + // string library string, + // functionality from the OS os, + // all things math math, + // the table manipulator and observer functions table, + // the debug library debug, + // the bit library: different based on which you're using bit32, + // input/output library io, + // LuaJIT only ffi, + // LuaJIT only jit, + // library for handling utf8: new to Lua utf8, + // do not use count }; @@ -17451,15 +17535,15 @@ namespace sol { inline int default_traceback_error_handler(lua_State*L) { using namespace sol; std::string msg = "An unknown error has triggered the default error handler"; - optional maybetopmsg = stack::check_get(L, 1); + optional maybetopmsg = stack::check_get(L, 1); if (maybetopmsg) { - const string_detail::string_shim& topmsg = maybetopmsg.value(); + const string_view& topmsg = maybetopmsg.value(); msg.assign(topmsg.data(), topmsg.size()); } luaL_traceback(L, L, msg.c_str(), 1); - optional maybetraceback = stack::check_get(L, -1); + optional maybetraceback = stack::check_get(L, -1); if (maybetraceback) { - const string_detail::string_shim& traceback = maybetraceback.value(); + const string_view& traceback = maybetraceback.value(); msg.assign(traceback.data(), traceback.size()); } return stack::push(L, msg); diff --git a/sol/error_handler.hpp b/sol/error_handler.hpp index ad3bd532..d96eae7d 100644 --- a/sol/error_handler.hpp +++ b/sol/error_handler.hpp @@ -85,7 +85,7 @@ namespace sol { } addendum += n; ++marker; - } + }; (void)detail::swallow{ int(), (action(detail::demangle()), int())... }; addendum += ")')"; return type_panic_string(L, index, expected, actual, message + addendum); diff --git a/sol/stack_push.hpp b/sol/stack_push.hpp index 962f72f8..220b4859 100644 --- a/sol/stack_push.hpp +++ b/sol/stack_push.hpp @@ -572,6 +572,10 @@ namespace sol { static int push(lua_State* L, const string_view& sv) { return stack::push(L, sv.data(), sv.length()); } + + static int push(lua_State* L, const string_view& sv, std::size_t n) { + return stack::push(L, sv.data(), n); + } }; template<> @@ -769,6 +773,10 @@ namespace sol { static int push(lua_State* L, const wstring_view& sv) { return stack::push(L, sv.data(), sv.length()); } + + static int push(lua_State* L, const wstring_view& sv, std::size_t n) { + return stack::push(L, sv.data(), n); + } }; template <> @@ -776,6 +784,10 @@ namespace sol { static int push(lua_State* L, const u16string_view& sv) { return stack::push(L, sv.data(), sv.length()); } + + static int push(lua_State* L, const u16string_view& sv, std::size_t n) { + return stack::push(L, sv.data(), n); + } }; template <> @@ -783,6 +795,10 @@ namespace sol { static int push(lua_State* L, const u32string_view& sv) { return stack::push(L, sv.data(), sv.length()); } + + static int push(lua_State* L, const u32string_view& sv, std::size_t n) { + return stack::push(L, sv.data(), n); + } }; #endif // codecvt Header Support