From ae37273021627d91276d80080775568536031e19 Mon Sep 17 00:00:00 2001
From: Hartmut Seichter <hartmut@technotecture.com>
Date: Fri, 28 Dec 2018 00:34:39 +0100
Subject: [PATCH] ref counting with std::shared_ptr seems to work and also is
 handed through with sol

---
 src/scene/src/node.cpp           |  7 +++++++
 src/scripting/src/script.cpp     | 23 ++++++-----------------
 src/scripts/demos/simple_000.lua | 28 +++++++++++++++++++++-------
 src/ui/src/window.cpp            |  7 +++++++
 4 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/src/scene/src/node.cpp b/src/scene/src/node.cpp
index 7fe54bb..796e84d 100644
--- a/src/scene/src/node.cpp
+++ b/src/scene/src/node.cpp
@@ -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;
diff --git a/src/scripting/src/script.cpp b/src/scripting/src/script.cpp
index 40b1374..797f52b 100644
--- a/src/scripting/src/script.cpp
+++ b/src/scripting/src/script.cpp
@@ -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>();
-};
-
-
 }
 
 
diff --git a/src/scripts/demos/simple_000.lua b/src/scripts/demos/simple_000.lua
index cbce571..c343ea0 100644
--- a/src/scripts/demos/simple_000.lua
+++ b/src/scripts/demos/simple_000.lua
@@ -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()
 
diff --git a/src/ui/src/window.cpp b/src/ui/src/window.cpp
index 587153e..9e4fdd2 100644
--- a/src/ui/src/window.cpp
+++ b/src/ui/src/window.cpp
@@ -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)
 //{
 //