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

@ -7,6 +7,13 @@ node::node(const std::string &name)
{
}
node::node(const node &node)
: _children(node.children())
, _parents(node._parents)
, _name(node._name)
{
}
node *node::clone(const unsigned short &copymode) const
{
return nullptr;

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>();
};
}

View file

@ -46,21 +46,35 @@ local n_2 = pw.node.new("node-2")
print("node 1: ", n_1.name)
print("node 2: ", n_2.name)
print(pw.node.create())
--print(pw.node.create())
print("node children ",n_1:children())
n_1:add_child(pw.node.create()).name = "one"
n_1:add_child(pw.node.create()).name = "two"
n_1:add_child(pw.node.create()).name = "three"
n_1:add_child(pw.node.create()).name = "four"
n_1:add_child(pw.node.create()).name = "five"
--n_1:add_child(n_2:shared())
print("node 1 - child count ",n_1.child_count)
for i = 1,n_1.child_count do
print(i,n_1.children[i],n_1.children[i].name)
end
--print(n_1:shared())
--print(pw.my_func())
--n_1:add_child()
--local w = pw.window.new()
local w = pw.window.new()
--while w:update()
--do
-- -- print("update")
--end
w.title = "pixwerx 1.0"
while w:update()
do
-- print("update")
end
--local scene = pw:scene.new()

View file

@ -50,6 +50,13 @@ void pw::window::set_size(int w,int h) {
glfwSetWindowSize(_window,w,h);
}
std::pair<int,int> pw::window::get_size()
{
int x,y;
glfwGetWindowSize(_window,&x,&y);
return std::make_pair(x,y);
}
//void pw::window::load(sol::table &ns)
//{
//