From 132ff87fbcd5baa5229f285e4eabcc1b133d0609 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Sat, 17 Sep 2016 22:17:03 -0400 Subject: [PATCH] update single --- single/sol/sol.hpp | 248 +++++++++++++++++++++++++++++++-------------- 1 file changed, 174 insertions(+), 74 deletions(-) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index ebbe1717..eefd1d73 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-09-14 04:10:09.319129 UTC -// This header was generated with sol v2.14.0 (revision 0e56783) +// Generated 2016-09-18 02:16:45.191230 UTC +// This header was generated with sol v2.14.0 (revision 330df79) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -4480,12 +4480,12 @@ namespace sol { const std::size_t id_for::value = unique_id(); inline decltype(auto) base_class_check_key() { - static const auto& key = u8"♡o。.(✿ฺ。 ✿ฺ)"; + static const auto& key = "class_check"; return key; } inline decltype(auto) base_class_cast_key() { - static const auto& key = u8"(◕‿◕✿)"; + static const auto& key = "class_cast"; return key; } @@ -4507,11 +4507,11 @@ namespace sol { template static bool type_check_bases(types, std::size_t ti) { - return ti != id_for::value || type_check_bases(types(), ti); + return ti == id_for::value || type_check_bases(types(), ti); } static bool type_check(std::size_t ti) { - return ti != id_for::value || type_check_bases(types(), ti); + return ti == id_for::value || type_check_bases(types(), ti); } static void* type_cast_bases(types<>, T*, std::size_t) { @@ -4773,16 +4773,18 @@ namespace sol { if (lua_getmetatable(L, index) == 0) { return true; } - if (stack_detail::check_metatable(L)) + int metatableindex = lua_gettop(L); + if (stack_detail::check_metatable(L, metatableindex)) return true; - if (stack_detail::check_metatable(L)) + if (stack_detail::check_metatable(L, metatableindex)) return true; - if (stack_detail::check_metatable>(L)) + if (stack_detail::check_metatable>(L, metatableindex)) return true; bool success = false; if (detail::has_derived::value) { auto pn = stack::pop_n(L, 1); - lua_getfield(L, -1, &detail::base_class_check_key()[0]); + lua_pushstring(L, &detail::base_class_check_key()[0]); + lua_rawget(L, metatableindex); if (type_of(L, -1) != type::nil) { void* basecastdata = lua_touserdata(L, -1); detail::inheritance_check_function ic = (detail::inheritance_check_function)basecastdata; @@ -9419,6 +9421,7 @@ namespace sol { // end of sol/deprecate.hpp +#include #include namespace sol { @@ -9431,6 +9434,14 @@ namespace sol { }; typedef void(*base_walk)(lua_State*, bool&, int&, string_detail::string_shim&); + typedef int(*member_search)(lua_State*, void*); + + struct find_call_pair { + member_search first; + member_search second; + + find_call_pair(member_search first, member_search second) : first(first), second(second) {} + }; inline bool is_indexer(string_detail::string_shim s) { return s == name_of(meta_function::index) || s == name_of(meta_function::new_index); @@ -9486,13 +9497,13 @@ namespace sol { auto maybeaccessor = stack::get>(L, is_index ? -1 : -2); string_detail::string_shim accessor = maybeaccessor.value_or(string_detail::string_shim("(unknown)")); if (is_index) - return luaL_error(L, "sol: attempt to index (get) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.data()); + return luaL_error(L, "sol: attempt to index (get) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.c_str()); else - return luaL_error(L, "sol: attempt to index (set) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.data()); + return luaL_error(L, "sol: attempt to index (set) nil value \"%s\" on userdata (bad (misspelled?) key name or does not exist)", accessor.c_str()); } template - static void walk_single_base(lua_State* L, bool& found, int& ret, string_detail::string_shim& accessor) { + 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]; @@ -9504,19 +9515,7 @@ namespace sol { lua_pop(L, 1); return; } - stack::get_field(L, accessor.c_str(), lua_gettop(L)); - if (type_of(L, -1) == type::nil) { - lua_pop(L, 1); - } - else { - // Probably a function. Probably. - // Kick off metatable - lua_remove(L, -2); - // Return the field (which is probably a function) itself - found = true; - ret = 1; - return; - } + stack::get_field(L, basewalkkey); if (type_of(L, -1) == type::nil) { lua_pop(L, 2); @@ -9627,6 +9626,7 @@ namespace sol { template struct check_binding : is_variable_binding> {}; Tuple functions; + std::unordered_map mapping; lua_CFunction indexfunc; lua_CFunction newindexfunc; lua_CFunction destructfunc; @@ -9744,6 +9744,7 @@ namespace sol { template > usertype_metatable(Args&&... args) : functions(std::forward(args)...), + mapping(), indexfunc(usertype_detail::indexing_fail), newindexfunc(usertype_detail::indexing_fail), destructfunc(nullptr), callconstructfunc(nullptr), indexbase(&core_indexing_call), newindexbase(&core_indexing_call), @@ -9751,32 +9752,24 @@ namespace sol { baseclasscheck(nullptr), baseclasscast(nullptr), mustindex(contains_variable() || contains_index()), secondarymeta(contains_variable()), hasequals(false), hasless(false), haslessequals(false) { + mapping.insert( + { { + std::pair( + usertype_detail::make_string(std::get(functions)), + { &usertype_metatable::real_find_call, + &usertype_metatable::real_find_call } + ) + }... } + ); } template - int real_find_call(std::integral_constant, lua_State* L) { - if (is_variable_binding(functions))>::value) { - return real_call_with(L, *this); + static int real_find_call(lua_State* L, void* um) { + auto& f = *static_cast(um); + if (is_variable_binding(f.functions))>::value) { + return real_call_with(L, f); } - return stack::push(L, c_closure(call, stack::push(L, light(*this)))); - } - - template - void find_call(std::integral_constant idx, lua_State* L, bool& found, int& ret, const sol::string_detail::string_shim& accessor) { - if (found) { - return; - } - string_detail::string_shim name = usertype_detail::make_shim(std::get(functions)); - if (accessor != name) { - return; - } - found = true; - ret = real_find_call(idx, L); - } - - template - void propogating_call(lua_State* L, bool& found, int& ret, string_detail::string_shim& accessor) { - (void)detail::swallow{ 0, (find_call(std::integral_constant(), L, found, ret, accessor), 0)... }; + return stack::push(L, c_closure(call, stack::push(L, light(f)))); } template @@ -9786,13 +9779,15 @@ namespace sol { if (toplevel && stack::get(L, keyidx) != type::string) { return is_index ? f.indexfunc(L) : f.newindexfunc(L); } - string_detail::string_shim accessor = stack::get(L, keyidx); + std::string name = stack::get(L, keyidx); + auto memberit = f.mapping.find(name); + if (memberit != f.mapping.cend()) { + auto& member = is_index ? memberit->second.second : memberit->second.first; + return (member)(L, static_cast(&f)); + } + string_detail::string_shim accessor = name; int ret = 0; bool found = false; - f.propogating_call(L, found, ret, accessor); - if (found) { - return ret; - } // Otherwise, we need to do propagating calls through the bases if (is_index) f.indexbaseclasspropogation(L, found, ret, accessor); @@ -9979,8 +9974,6 @@ namespace sol { // beginning of sol/simple_usertype_metatable.hpp -#include - namespace sol { namespace usertype_detail { @@ -10010,12 +10003,13 @@ namespace sol { typedef std::unordered_map function_map; struct simple_map { + const char* metakey; variable_map variables; function_map functions; base_walk indexbaseclasspropogation; base_walk newindexbaseclasspropogation; - simple_map(base_walk index, base_walk newindex, variable_map&& vars, function_map&& funcs) : variables(std::move(vars)), functions(std::move(funcs)), indexbaseclasspropogation(index), newindexbaseclasspropogation(newindex) {} + simple_map(const char* mkey, base_walk index, base_walk newindex, variable_map&& vars, function_map&& funcs) : metakey(mkey), variables(std::move(vars)), functions(std::move(funcs)), indexbaseclasspropogation(index), newindexbaseclasspropogation(newindex) {} }; template @@ -10045,6 +10039,19 @@ namespace sol { auto& func = (fit->second); return stack::push(L, func); } + // Check table storage first for a method that works + luaL_getmetatable(L, sm.metakey); + if (type_of(L, -1) != type::nil) { + stack::get_field(L, accessor.c_str(), lua_gettop(L)); + if (type_of(L, -1) != type::nil) { + // Woo, we found it? + lua_remove(L, -2); + return 1; + } + lua_pop(L, 1); + } + lua_pop(L, 1); + int ret = 0; bool found = false; // Otherwise, we need to do propagating calls through the bases @@ -10100,18 +10107,30 @@ namespace sol { bool mustindex; bool secondarymeta; + template + void insert(N&& n, object&& o) { + std::string key = usertype_detail::make_string(std::forward(n)); + auto hint = registrations.find(key); + if (hint == registrations.cend()) { + registrations.emplace_hint(hint, std::move(key), std::move(o)); + return; + } + hint->second = std::move(o); + } + template >> = meta::enabler> void add_function(lua_State* L, N&& n, F&& f) { - registrations.emplace(usertype_detail::make_string(std::forward(n)), make_object(L, as_function_reference(std::forward(f)))); + insert(std::forward(n), make_object(L, as_function_reference(std::forward(f)))); } template >> = meta::enabler> void add_function(lua_State* L, N&& n, F&& f) { + object o = make_object(L, std::forward(f)); if (std::is_same, call_construction>::value) { - callconstructfunc = make_object(L, std::forward(f)); + callconstructfunc = std::move(o); return; } - registrations.emplace(usertype_detail::make_string(std::forward(n)), make_object(L, std::forward(f))); + insert(std::forward(n), std::move(o)); } template >> = meta::enabler> @@ -10121,9 +10140,16 @@ namespace sol { template >> = meta::enabler> void add(lua_State*, N&& n, F&& f) { - varmap.emplace(usertype_detail::make_string(std::forward(n)), std::make_unique>>(std::forward(f))); mustindex = true; secondarymeta = true; + std::string key = usertype_detail::make_string(std::forward(n)); + auto o = std::make_unique>>(std::forward(f)); + auto hint = varmap.find(key); + if (hint == varmap.cend()) { + varmap.emplace_hint(hint, std::move(key), std::move(o)); + return; + } + hint->second = std::move(o); } template @@ -10133,7 +10159,7 @@ namespace sol { callconstructfunc = std::move(o); return; } - registrations.emplace(usertype_detail::make_string(std::forward(n)), std::move(o)); + insert(std::forward(n), std::move(o)); } template @@ -10143,7 +10169,27 @@ namespace sol { callconstructfunc = std::move(o); return; } - registrations.emplace(usertype_detail::make_string(std::forward(n)), std::move(o)); + insert(std::forward(n), std::move(o)); + } + + template + void add(lua_State* L, N&& n, destructor_wrapper c) { + object o(L, in_place>>, std::move(c)); + if (std::is_same, call_construction>::value) { + callconstructfunc = std::move(o); + return; + } + insert(std::forward(n), std::move(o)); + } + + template + void add(lua_State* L, N&& n, destructor_wrapper c) { + object o(L, in_place>>, std::move(c)); + if (std::is_same, call_construction>::value) { + callconstructfunc = std::move(o); + return; + } + insert(std::forward(n), std::move(o)); } template @@ -10163,20 +10209,20 @@ namespace sol { newindexbaseclasspropogation = usertype_detail::walk_all_bases; } + private: template simple_usertype_metatable(usertype_detail::verified_tag, std::index_sequence, lua_State* L, Tuple&& args) - : callconstructfunc(nil), - indexfunc(&usertype_detail::indexing_fail), newindexfunc(&usertype_detail::indexing_fail), - indexbase(&usertype_detail::simple_core_indexing_call), newindexbase(&usertype_detail::simple_core_indexing_call), - indexbaseclasspropogation(usertype_detail::walk_all_bases), newindexbaseclasspropogation(&usertype_detail::walk_all_bases), - baseclasscheck(nullptr), baseclasscast(nullptr), - mustindex(false), secondarymeta(false) { + : callconstructfunc(nil), + indexfunc(&usertype_detail::indexing_fail), newindexfunc(&usertype_detail::indexing_fail), + indexbase(&usertype_detail::simple_core_indexing_call), newindexbase(&usertype_detail::simple_core_indexing_call), + indexbaseclasspropogation(usertype_detail::walk_all_bases), newindexbaseclasspropogation(&usertype_detail::walk_all_bases), + baseclasscheck(nullptr), baseclasscast(nullptr), + mustindex(false), secondarymeta(false) { (void)detail::swallow{ 0, (add(L, detail::forward_get(args), detail::forward_get(args)),0)... }; } - private: template simple_usertype_metatable(lua_State* L, usertype_detail::verified_tag v, Args&&... args) : simple_usertype_metatable(v, std::make_index_sequence(), L, std::forward_as_tuple(std::forward(args)...)) {} @@ -10187,7 +10233,7 @@ namespace sol { simple_usertype_metatable(lua_State* L, usertype_detail::check_destructor_tag, Args&&... args) : simple_usertype_metatable(L, meta::condition, meta::neg>>, usertype_detail::add_destructor_tag, usertype_detail::verified_tag>(), std::forward(args)...) {} public: - simple_usertype_metatable(lua_State* L) : simple_usertype_metatable(meta::condition>, decltype(default_constructor), usertype_detail::check_destructor_tag>(), L) {} + simple_usertype_metatable(lua_State* L) : simple_usertype_metatable(L, meta::condition>, decltype(default_constructor), usertype_detail::check_destructor_tag>()) {} template, @@ -10230,7 +10276,7 @@ namespace sol { ++uniqueness; const char* gcmetakey = &usertype_traits::gc_table[0]; - stack::push>(L, metatable_key, uniquegcmetakey, umx.indexbaseclasspropogation, umx.newindexbaseclasspropogation, std::move(umx.varmap), std::move(umx.registrations)); + 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(); @@ -10802,11 +10848,32 @@ namespace sol { template usertype(simple_tag, lua_State* L, Args&&... args) : metatableregister(detail::make_unique_deleter, detail::deleter>(L, std::forward(args)...)) {} + usertype_detail::registrar* registrar_data() { + return metatableregister.get(); + } + int push(lua_State* L) { return metatableregister->push_um(L); } }; + template + class simple_usertype : public usertype { + private: + typedef usertype base_t; + lua_State* state; + + public: + template + simple_usertype(lua_State* L, Args&&... args) : base_t(simple, L, std::forward(args)...), state(L) {} + + template + void set(N&& n, F&& f) { + auto meta = static_cast*>(base_t::registrar_data()); + meta->add(state, n, f); + } + }; + namespace stack { template struct pusher> { @@ -11161,7 +11228,7 @@ namespace sol { template basic_table_core& new_simple_usertype(const std::string& name, Args&&... args) { - usertype utype(simple, base_t::lua_state(), std::forward(args)...); + simple_usertype utype(base_t::lua_state(), std::forward(args)...); set_usertype(name, utype); return *this; } @@ -11174,11 +11241,29 @@ namespace sol { template basic_table_core& new_simple_usertype(const std::string& name, constructors ctor, Args&&... args) { - usertype utype(simple, base_t::lua_state(), ctor, std::forward(args)...); + simple_usertype utype(base_t::lua_state(), ctor, std::forward(args)...); set_usertype(name, utype); return *this; } + template + simple_usertype create_simple_usertype(Args&&... args) { + simple_usertype utype(base_t::lua_state(), std::forward(args)...); + return utype; + } + + template + simple_usertype create_simple_usertype(Args&&... args) { + constructors> ctor{}; + return create_simple_usertype(ctor, std::forward(args)...); + } + + template + simple_usertype create_simple_usertype(constructors ctor, Args&&... args) { + simple_usertype utype(base_t::lua_state(), ctor, std::forward(args)...); + return utype; + } + template basic_table_core& new_enum(const std::string& name, Args&&... args) { if (read_only) { @@ -11777,13 +11862,28 @@ namespace sol { global.new_simple_usertype(name, std::forward(args)...); return *this; } - + template state_view& new_simple_usertype(const std::string& name, constructors ctor, Args&&... args) { global.new_simple_usertype(name, ctor, std::forward(args)...); return *this; } + template + simple_usertype create_simple_usertype(Args&&... args) { + return global.create_simple_usertype(std::forward(args)...); + } + + template + simple_usertype create_simple_usertype(Args&&... args) { + return global.create_simple_usertype(std::forward(args)...); + } + + template + simple_usertype create_simple_usertype(constructors ctor, Args&&... args) { + return global.create_simple_usertype(ctor, std::forward(args)...); + } + template state_view& new_enum(const std::string& name, Args&&... args) { global.new_enum(name, std::forward(args)...);