From ebbbd896d4788ec316d3620d1b2d1dae4d6473a4 Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sat, 12 Oct 2019 07:38:17 +0700 Subject: [PATCH] collect lua garbage before starter destroy. register sol ptrs. --- headers/enduro2d/high/_high.hpp | 52 +++++++++++++++++++++++++++++++ headers/enduro2d/high/luasol.hpp | 2 ++ sources/enduro2d/high/luasol.cpp | 4 +++ sources/enduro2d/high/starter.cpp | 4 ++- 4 files changed, 61 insertions(+), 1 deletion(-) diff --git a/headers/enduro2d/high/_high.hpp b/headers/enduro2d/high/_high.hpp index 0e497792..37a1d6ae 100644 --- a/headers/enduro2d/high/_high.hpp +++ b/headers/enduro2d/high/_high.hpp @@ -75,6 +75,10 @@ namespace e2d class atlas; class flipbook; class gobject; + template < typename T > + class gcomponent; + template < typename T > + class const_gcomponent; class model; class node; class prefab; @@ -86,3 +90,51 @@ namespace e2d class starter; class world; } + +namespace sol +{ + template < typename T > + struct unique_usertype_traits> { + using type = T; + using actual_type = e2d::intrusive_ptr; + static const bool value = true; + + static bool is_null(const actual_type& ptr) { + return !ptr; + } + + static type* get(actual_type& ptr) { + return ptr.get(); + } + }; + + template < typename T > + struct unique_usertype_traits> { + using type = T; + using actual_type = e2d::gcomponent; + static const bool value = true; + + static bool is_null(const actual_type& ptr) { + return !ptr; + } + + static type* get(actual_type& ptr) { + return ptr.find(); + } + }; + + template < typename T > + struct unique_usertype_traits> { + using type = T; + using actual_type = e2d::const_gcomponent; + static const bool value = true; + + static bool is_null(const actual_type& ptr) { + return !ptr; + } + + static type* get(actual_type& ptr) { + return ptr.find(); + } + }; +} diff --git a/headers/enduro2d/high/luasol.hpp b/headers/enduro2d/high/luasol.hpp index e3e5011f..f06883b7 100644 --- a/headers/enduro2d/high/luasol.hpp +++ b/headers/enduro2d/high/luasol.hpp @@ -17,6 +17,8 @@ namespace e2d luasol(); ~luasol() noexcept final = default; + void collect_garbage(); + template < typename F > decltype(auto) with_state(F&& f); template < typename F > diff --git a/sources/enduro2d/high/luasol.cpp b/sources/enduro2d/high/luasol.cpp index a1fd5d86..7a9f9bdf 100644 --- a/sources/enduro2d/high/luasol.cpp +++ b/sources/enduro2d/high/luasol.cpp @@ -25,6 +25,10 @@ namespace e2d bindings::bind_high(state_); } + void luasol::collect_garbage() { + state_.collect_garbage(); + } + std::optional