From 045d96e11a10cfbee07e54fc0b7e53d2d538c51b Mon Sep 17 00:00:00 2001 From: ThePhD Date: Mon, 11 Jul 2016 13:03:38 -0400 Subject: [PATCH] Update single sol.hpp --- single/sol/sol.hpp | 71 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index fcc60624..458a57f8 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-07-09 19:20:29.179096 UTC -// This header was generated with sol v2.9.0 (revision 4634ec4) +// Generated 2016-07-11 17:03:17.659207 UTC +// This header was generated with sol v2.9.0 (revision 6b85ed2) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -5175,7 +5175,7 @@ namespace sol { } template - struct constructors_for { + struct tagged { List l; }; } // detail @@ -7787,15 +7787,15 @@ namespace sol { }; template - struct pusher>> { - static int push(lua_State* L, detail::constructors_for>) { + struct pusher>> { + static int push(lua_State* L, detail::tagged>) { lua_CFunction cf = call_detail::construct; return stack::push(L, cf); } }; template - struct pusher>> { + struct pusher>> { static int push(lua_State* L, constructor_wrapper c) { lua_CFunction cf = call_detail::call_user>; int closures = stack::push>(L, std::move(c)); @@ -7803,6 +7803,23 @@ namespace sol { } }; + template + struct pusher>> { + static int push(lua_State* L, detail::tagged>) { + lua_CFunction cf = call_detail::destruct; + return stack::push(L, cf); + } + }; + + template + struct pusher>> { + static int push(lua_State* L, destructor_wrapper c) { + lua_CFunction cf = call_detail::call_user>; + int closures = stack::push>(L, std::move(c)); + return stack::push(L, c_closure(cf, closures)); + } + }; + } // stack } // sol @@ -9033,10 +9050,12 @@ namespace sol { (void)detail::swallow{ 0, (um.template make_regs<(I * 2)>(value_table, lastreg, std::get<(I * 2)>(um.functions), std::get<(I * 2 + 1)>(um.functions)), 0)... }; um.finish_regs(value_table, lastreg); value_table[lastreg] = { nullptr, nullptr }; + bool hasdestructor = !value_table.empty() && name_of(meta_function::garbage_collect) == value_table[lastreg - 1].name; regs_t ref_table = value_table; - bool hasdestructor = lastreg > 0 && name_of(meta_function::garbage_collect) == ref_table[lastreg - 1].name; + regs_t unique_table = value_table; if (hasdestructor) { ref_table[lastreg - 1] = { nullptr, nullptr }; + unique_table[lastreg - 1] = { value_table[lastreg - 1].name, detail::unique_destruct }; } // Now use um @@ -9044,27 +9063,26 @@ namespace sol { for (std::size_t i = 0; i < 3; ++i) { // Pointer types, AKA "references" from C++ const char* metakey = nullptr; + luaL_Reg* metaregs = nullptr; switch (i) { case 0: metakey = &usertype_traits::metatable[0]; + metaregs = ref_table.data(); break; case 1: metakey = &usertype_traits>::metatable[0]; + metaregs = unique_table.data(); break; case 2: default: metakey = &usertype_traits::metatable[0]; + metaregs = value_table.data(); break; } luaL_newmetatable(L, metakey); stack_reference t(L, -1); stack::push(L, make_light(um)); - if (i < 2) { - luaL_setfuncs(L, ref_table.data(), 1); - } - else { - luaL_setfuncs(L, value_table.data(), 1); - } + luaL_setfuncs(L, metaregs, 1); if (um.baseclasscheck != nullptr) { stack::set_field(L, detail::base_class_check_key(), um.baseclasscheck, t.stack_index()); @@ -9122,19 +9140,24 @@ namespace sol { std::vector> registrations; object callconstructfunc; - template + template >> = meta::enabler> + void add(lua_State* L, N&& n, F&& f) { + registrations.emplace_back(make_object(L, std::forward(n)), make_object(L, function_args(std::forward(f)))); + } + + template >> = meta::enabler> void add(lua_State* L, N&& n, F&& f) { registrations.emplace_back(make_object(L, std::forward(n)), make_object(L, std::forward(f))); } template void add(lua_State* L, N&& n, constructor_wrapper c) { - registrations.emplace_back(make_object(L, std::forward(n)), make_object(L, detail::constructors_for>{std::move(c)})); + registrations.emplace_back(make_object(L, std::forward(n)), make_object(L, detail::tagged>{std::move(c)})); } template void add(lua_State* L, N&& n, constructor_list c) { - registrations.emplace_back(make_object(L, std::forward(n)), make_object(L, detail::constructors_for>{std::move(c)})); + registrations.emplace_back(make_object(L, std::forward(n)), make_object(L, detail::tagged>{std::move(c)})); } template @@ -9209,6 +9232,22 @@ namespace sol { luaL_newmetatable(L, metakey); stack_reference t(L, -1); for (auto& kvp : umx.registrations) { + switch (i) { + case 0: + if (kvp.first.template is() && kvp.first.template as() == "__gc") { + continue; + } + break; + case 1: + if (kvp.first.template is() && kvp.first.template as() == "__gc") { + stack::set_field(L, kvp.first, detail::unique_destruct, t.stack_index()); + continue; + } + break; + case 2: + default: + break; + } stack::set_field(L, kvp.first, kvp.second, t.stack_index()); }