From 0809d9c54b192be7dd23405550983d1f9446a7e1 Mon Sep 17 00:00:00 2001
From: Hartmut Seichter <hartmut@technotecture.com>
Date: Wed, 23 Jan 2019 19:33:33 +0100
Subject: [PATCH] poking around to make a somewhat workable factory pattern

---
 src/core/include/pw/core/vector.hpp           |  1 +
 src/engine/CMakeLists.txt                     |  6 +-
 src/engine/pixwerx.cpp                        |  7 +++
 src/scripting/include/pw/scripting/script.hpp |  1 +
 src/scripting/src/runtime_lua.cpp             |  2 -
 src/scripting/src/runtime_lua.hpp             | 32 +++-------
 src/scripting/src/script.cpp                  |  2 +
 src/scripting/src/script_core.cpp             | 63 +++++++++----------
 8 files changed, 56 insertions(+), 58 deletions(-)

diff --git a/src/core/include/pw/core/vector.hpp b/src/core/include/pw/core/vector.hpp
index 01960dd..a3c42c7 100644
--- a/src/core/include/pw/core/vector.hpp
+++ b/src/core/include/pw/core/vector.hpp
@@ -60,6 +60,7 @@ struct vector3_ : matrix_<3,1,T>  {
     using base_type::base_type;
     using base_type::operator = ;
 
+    vector3_() : base_type() {}
     vector3_(const base_type& m) : base_type(m) {}
     vector3_(T x_,T y_,T z_) : base_type({x_,y_,z_}) {}
 
diff --git a/src/engine/CMakeLists.txt b/src/engine/CMakeLists.txt
index 962b622..5326811 100644
--- a/src/engine/CMakeLists.txt
+++ b/src/engine/CMakeLists.txt
@@ -21,4 +21,8 @@ target_include_directories(pixwerx
 	${CMAKE_SOURCE_DIR}/src/scripting/include
 	)
 
-target_link_libraries(pixwerx pwcore pwsystem pwscripting)
+    target_link_libraries(pixwerx
+        pwscripting
+        #   -Wl,--whole-archive -lpwscripting -Wl,--no-whole-archive
+        pwcore
+        pwsystem)
diff --git a/src/engine/pixwerx.cpp b/src/engine/pixwerx.cpp
index 7ed8e41..0ca884b 100644
--- a/src/engine/pixwerx.cpp
+++ b/src/engine/pixwerx.cpp
@@ -7,6 +7,7 @@
 #include <pw/core/core.hpp>
 #include <pw/scripting/script.hpp>
 
+
 #include <string>
 
 #include <argagg/include/argagg/argagg.hpp>
@@ -14,8 +15,14 @@
 #include <iostream>
 #include <fstream>
 
+
+//PW_RUNTIME_LUA_USE(core)
+
+
 int main(int argc,const char** argv) {
 
+//    pw_runtime_lua_core();
+
     argagg::parser argparser {{
             { "help", {"-h", "--help"},
                  "shows this help message", 0},
diff --git a/src/scripting/include/pw/scripting/script.hpp b/src/scripting/include/pw/scripting/script.hpp
index 3834a0c..ac6645a 100644
--- a/src/scripting/include/pw/scripting/script.hpp
+++ b/src/scripting/include/pw/scripting/script.hpp
@@ -42,6 +42,7 @@ protected:
 
 };
 
+
 }
 
 #endif
diff --git a/src/scripting/src/runtime_lua.cpp b/src/scripting/src/runtime_lua.cpp
index ef0bcdb..f06b86f 100644
--- a/src/scripting/src/runtime_lua.cpp
+++ b/src/scripting/src/runtime_lua.cpp
@@ -2,8 +2,6 @@
 
 namespace pw {
 
-PW_RUNTIME_LUA_USE(core)
-
 runtime_lua &runtime_lua::get()
 {
 	static runtime_lua instance;
diff --git a/src/scripting/src/runtime_lua.hpp b/src/scripting/src/runtime_lua.hpp
index 93a925c..6bc02b9 100644
--- a/src/scripting/src/runtime_lua.hpp
+++ b/src/scripting/src/runtime_lua.hpp
@@ -5,6 +5,8 @@
 #include <lua.hpp>
 #include <map>
 
+#include <pw/core/debug.hpp>
+
 namespace pw {
 
 class runtime_lua {
@@ -26,39 +28,23 @@ protected:
 
 };
 
-template<typename Derived>
+
+template<typename T>
 struct runtime_lua_register
 {
-	Derived& derived() { return static_cast<Derived&>(*this); }
-	const Derived& derived() const { return static_cast<const Derived&>(*this); }
-
 	runtime_lua_register()
-	{
-		printf("Test\n");
-		runtime_lua::get().add(derived().module_name(),&Derived::register_function);
+    {
+        debug::d() << __PRETTY_FUNCTION__;
+        runtime_lua::get().add("test",&T::register_function);
 	}
 
-	static runtime_lua_register<Derived> _instance;
+    static runtime_lua_register<T> _instance;
 };
 
-
-extern "C" {
-	typedef void (* CModuleFunction) (void);
-}
-
-struct ModuleFunctionProxy
-{
-	ModuleFunctionProxy(CModuleFunction function) { (function)(); }
-};
+template <typename T> runtime_lua_register<T> runtime_lua_register<T>::_instance;
 
 }
 
-#define PW_RUNTIME_LUA_USE(name) \
-	extern "C" void pw_runtime_lua_##name(void) { printf("Meh!\n"); };
 
 
-#define PW_RUNTIME_LUA_REGISTER(name) \
-	extern "C" void pw_runtime_lua_##name(void); \
-	static pw::ModuleFunctionProxy proxy_##name(pw_runtime_lua_##name);
-
 #endif
diff --git a/src/scripting/src/script.cpp b/src/scripting/src/script.cpp
index 837cde1..ac90cd3 100644
--- a/src/scripting/src/script.cpp
+++ b/src/scripting/src/script.cpp
@@ -4,6 +4,8 @@
 
 #include "pw/core/debug.hpp"
 
+
+
 namespace pw {
 
 struct script::state {
diff --git a/src/scripting/src/script_core.cpp b/src/scripting/src/script_core.cpp
index d2c3051..00400bc 100644
--- a/src/scripting/src/script_core.cpp
+++ b/src/scripting/src/script_core.cpp
@@ -11,7 +11,7 @@
 
 namespace pw {
 
-struct lua_core : runtime_lua_register<lua_core> {
+struct lua_core {
 
 	std::string module_name() const { return "core"; }
 
@@ -22,35 +22,34 @@ struct lua_core : runtime_lua_register<lua_core> {
 
 		ns.set("pi",pw::pi<Scalar>());
 
-
-		ns.new_usertype<vector3>
-				(
-					"vector3",
-					sol::constructors<vector3(),vector3(vector3::value_type,vector3::value_type,vector3::value_type)>(),
-					"x", sol::property(sol::resolve<const vector3::value_type&() const>(&vector3::x), [](vector3& v,vector3::value_type val){ v.x() = val;}),
-				"y", sol::property(sol::resolve<const vector3::value_type&() const>(&vector3::y), [](vector3& v,vector3::value_type val){ v.y() = val;}),
-		"z", sol::property(sol::resolve<const vector3::value_type&() const>(&vector3::z), [](vector3& v,vector3::value_type val){ v.z() = val;}),
-		"cross",&vector3::cross,
-				"lerp",&vector3::lerp
-				);
+//        ns.new_usertype<vector3>
+//                (
+//                    "vector3",
+//                    sol::constructors<vector3(),vector3(vector3::value_type,vector3::value_type,vector3::value_type)>(),
+//                    "x", sol::property(sol::resolve<const vector3::value_type&() const>(&vector3::x), [](vector3& v,vector3::value_type val){ v.x() = val;}),
+//                "y", sol::property(sol::resolve<const vector3::value_type&() const>(&vector3::y), [](vector3& v,vector3::value_type val){ v.y() = val;}),
+//        "z", sol::property(sol::resolve<const vector3::value_type&() const>(&vector3::z), [](vector3& v,vector3::value_type val){ v.z() = val;}),
+//        "cross",&vector3::cross,
+//                "lerp",&vector3::lerp
+//                );
 
 
 
-		ns.new_usertype<quaternion>
-				(
-					"quaternion",
-					sol::constructors<quaternion(), quaternion(quaternion::value_type,quaternion::value_type,quaternion::value_type,quaternion::value_type)>(),
-					"x", sol::property(sol::resolve<const quaternion::value_type&() const>(&quaternion::x), [](quaternion& v,quaternion::value_type val){ v.x() = val;}),
-				"y", sol::property(sol::resolve<const quaternion::value_type&() const>(&quaternion::y), [](quaternion& v,quaternion::value_type val){ v.y() = val;}),
-		"z", sol::property(sol::resolve<const quaternion::value_type&() const>(&quaternion::z), [](quaternion& v,quaternion::value_type val){ v.z() = val;}),
-		"w", sol::property(sol::resolve<const quaternion::value_type&() const>(&quaternion::w), [](quaternion& v,quaternion::value_type val){ v.w() = val;}),
-		"identity",sol::readonly_property(&quaternion::identity),
-				"dot",&quaternion::dot,
-				"inverse",sol::readonly_property(&quaternion::inverse),
-				"normalized",&quaternion::normalized,
-				"lerp",&quaternion::lerp,
-				"slerp",&quaternion::slerp
-				);
+//        ns.new_usertype<quaternion>
+//                (
+//                    "quaternion",
+//                    sol::constructors<quaternion(), quaternion(quaternion::value_type,quaternion::value_type,quaternion::value_type,quaternion::value_type)>(),
+//                    "x", sol::property(sol::resolve<const quaternion::value_type&() const>(&quaternion::x), [](quaternion& v,quaternion::value_type val){ v.x() = val;}),
+//                "y", sol::property(sol::resolve<const quaternion::value_type&() const>(&quaternion::y), [](quaternion& v,quaternion::value_type val){ v.y() = val;}),
+//        "z", sol::property(sol::resolve<const quaternion::value_type&() const>(&quaternion::z), [](quaternion& v,quaternion::value_type val){ v.z() = val;}),
+//        "w", sol::property(sol::resolve<const quaternion::value_type&() const>(&quaternion::w), [](quaternion& v,quaternion::value_type val){ v.w() = val;}),
+//        "identity",sol::readonly_property(&quaternion::identity),
+//                "dot",&quaternion::dot,
+//                "inverse",sol::readonly_property(&quaternion::inverse),
+//                "normalized",&quaternion::normalized,
+//                "lerp",&quaternion::lerp,
+//                "slerp",&quaternion::slerp
+//                );
 
 		ns.new_usertype<axisangle>
 				("axisangle",
@@ -99,13 +98,13 @@ struct lua_core : runtime_lua_register<lua_core> {
 		//				"mesh",
 		//				sol::constructors<mesh()>()
 		//				);
-	}
-
-
+    }
 };
 
+struct lua_core_register : runtime_lua_register<lua_core>
+{
 };
 
-PW_RUNTIME_LUA_REGISTER(core)
-
+//PW_RUNTIME_LUA_REGISTER(core)
 
+}