poking around to make a somewhat workable factory pattern

This commit is contained in:
Hartmut Seichter 2019-01-23 19:33:33 +01:00
parent 36683d6288
commit 0809d9c54b
8 changed files with 56 additions and 58 deletions

View file

@ -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_}) {}

View file

@ -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)

View file

@ -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},

View file

@ -42,6 +42,7 @@ protected:
};
}
#endif

View file

@ -2,8 +2,6 @@
namespace pw {
PW_RUNTIME_LUA_USE(core)
runtime_lua &runtime_lua::get()
{
static runtime_lua instance;

View file

@ -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

View file

@ -4,6 +4,8 @@
#include "pw/core/debug.hpp"
namespace pw {
struct script::state {

View file

@ -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)
}