ref counting with std::shared_ptr seems to work and also is handed through with sol

This commit is contained in:
Hartmut Seichter 2018-12-28 00:34:39 +01:00
parent dd23fa811a
commit ae37273021
4 changed files with 41 additions and 24 deletions

View file

@ -92,7 +92,7 @@ void lua_state::load_modules() {
_namespace.new_usertype<window>("window",
"update",&window::update,
"set_title",&window::set_title,
"title",sol::writeonly_property(&window::set_title),
"set_size",&window::set_size
);
@ -100,26 +100,15 @@ void lua_state::load_modules() {
_namespace.new_usertype<node>("node",
sol::constructors<node(), node(std::string)>(),
"add_child",&node::add_child,
"shared",&node::shared,
"children",&node::children,
"child_count",&node::child_count,
"create", []() -> std::shared_ptr<node> {
auto ptr = std::make_shared<node>();
return ptr;
},
"children",sol::readonly_property(&node::children),
"child_count",sol::readonly_property(&node::child_count),
"create", []() -> std::shared_ptr<node> { return std::make_shared<node>(); },
"is_leaf", sol::readonly_property(&node::is_leaf),
"is_root", sol::readonly_property(&node::is_root),
// "share",scripting::property(scripting::resolve<std::shared_ptr<node>(std::make_shared<node>))
"name",scripting::property(&node::name,&node::set_name)
);
// _namespace.set("something", std::shared_ptr<node>(new node()));
_namespace["my_func"] = []() -> std::shared_ptr<node> {
return std::make_shared<node>();
};
}