poking around to make a somewhat workable factory pattern
This commit is contained in:
parent
36683d6288
commit
0809d9c54b
8 changed files with 56 additions and 58 deletions
|
@ -60,6 +60,7 @@ struct vector3_ : matrix_<3,1,T> {
|
||||||
using base_type::base_type;
|
using base_type::base_type;
|
||||||
using base_type::operator = ;
|
using base_type::operator = ;
|
||||||
|
|
||||||
|
vector3_() : base_type() {}
|
||||||
vector3_(const base_type& m) : base_type(m) {}
|
vector3_(const base_type& m) : base_type(m) {}
|
||||||
vector3_(T x_,T y_,T z_) : base_type({x_,y_,z_}) {}
|
vector3_(T x_,T y_,T z_) : base_type({x_,y_,z_}) {}
|
||||||
|
|
||||||
|
|
|
@ -21,4 +21,8 @@ target_include_directories(pixwerx
|
||||||
${CMAKE_SOURCE_DIR}/src/scripting/include
|
${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)
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <pw/core/core.hpp>
|
#include <pw/core/core.hpp>
|
||||||
#include <pw/scripting/script.hpp>
|
#include <pw/scripting/script.hpp>
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <argagg/include/argagg/argagg.hpp>
|
#include <argagg/include/argagg/argagg.hpp>
|
||||||
|
@ -14,8 +15,14 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
|
||||||
|
//PW_RUNTIME_LUA_USE(core)
|
||||||
|
|
||||||
|
|
||||||
int main(int argc,const char** argv) {
|
int main(int argc,const char** argv) {
|
||||||
|
|
||||||
|
// pw_runtime_lua_core();
|
||||||
|
|
||||||
argagg::parser argparser {{
|
argagg::parser argparser {{
|
||||||
{ "help", {"-h", "--help"},
|
{ "help", {"-h", "--help"},
|
||||||
"shows this help message", 0},
|
"shows this help message", 0},
|
||||||
|
|
|
@ -42,6 +42,7 @@ protected:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
PW_RUNTIME_LUA_USE(core)
|
|
||||||
|
|
||||||
runtime_lua &runtime_lua::get()
|
runtime_lua &runtime_lua::get()
|
||||||
{
|
{
|
||||||
static runtime_lua instance;
|
static runtime_lua instance;
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include <lua.hpp>
|
#include <lua.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include <pw/core/debug.hpp>
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
class runtime_lua {
|
class runtime_lua {
|
||||||
|
@ -26,39 +28,23 @@ protected:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Derived>
|
|
||||||
|
template<typename T>
|
||||||
struct runtime_lua_register
|
struct runtime_lua_register
|
||||||
{
|
{
|
||||||
Derived& derived() { return static_cast<Derived&>(*this); }
|
|
||||||
const Derived& derived() const { return static_cast<const Derived&>(*this); }
|
|
||||||
|
|
||||||
runtime_lua_register()
|
runtime_lua_register()
|
||||||
{
|
{
|
||||||
printf("Test\n");
|
debug::d() << __PRETTY_FUNCTION__;
|
||||||
runtime_lua::get().add(derived().module_name(),&Derived::register_function);
|
runtime_lua::get().add("test",&T::register_function);
|
||||||
}
|
}
|
||||||
|
|
||||||
static runtime_lua_register<Derived> _instance;
|
static runtime_lua_register<T> _instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T> runtime_lua_register<T> runtime_lua_register<T>::_instance;
|
||||||
extern "C" {
|
|
||||||
typedef void (* CModuleFunction) (void);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ModuleFunctionProxy
|
|
||||||
{
|
|
||||||
ModuleFunctionProxy(CModuleFunction function) { (function)(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#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
|
#endif
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#include "pw/core/debug.hpp"
|
#include "pw/core/debug.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
struct script::state {
|
struct script::state {
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
struct lua_core : runtime_lua_register<lua_core> {
|
struct lua_core {
|
||||||
|
|
||||||
std::string module_name() const { return "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.set("pi",pw::pi<Scalar>());
|
||||||
|
|
||||||
|
// ns.new_usertype<vector3>
|
||||||
ns.new_usertype<vector3>
|
// (
|
||||||
(
|
// "vector3",
|
||||||
"vector3",
|
// sol::constructors<vector3(),vector3(vector3::value_type,vector3::value_type,vector3::value_type)>(),
|
||||||
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;}),
|
||||||
"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;}),
|
||||||
"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;}),
|
||||||
"z", sol::property(sol::resolve<const vector3::value_type&() const>(&vector3::z), [](vector3& v,vector3::value_type val){ v.z() = val;}),
|
// "cross",&vector3::cross,
|
||||||
"cross",&vector3::cross,
|
// "lerp",&vector3::lerp
|
||||||
"lerp",&vector3::lerp
|
// );
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ns.new_usertype<quaternion>
|
// ns.new_usertype<quaternion>
|
||||||
(
|
// (
|
||||||
"quaternion",
|
// "quaternion",
|
||||||
sol::constructors<quaternion(), quaternion(quaternion::value_type,quaternion::value_type,quaternion::value_type,quaternion::value_type)>(),
|
// 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;}),
|
// "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;}),
|
// "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;}),
|
// "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;}),
|
// "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),
|
// "identity",sol::readonly_property(&quaternion::identity),
|
||||||
"dot",&quaternion::dot,
|
// "dot",&quaternion::dot,
|
||||||
"inverse",sol::readonly_property(&quaternion::inverse),
|
// "inverse",sol::readonly_property(&quaternion::inverse),
|
||||||
"normalized",&quaternion::normalized,
|
// "normalized",&quaternion::normalized,
|
||||||
"lerp",&quaternion::lerp,
|
// "lerp",&quaternion::lerp,
|
||||||
"slerp",&quaternion::slerp
|
// "slerp",&quaternion::slerp
|
||||||
);
|
// );
|
||||||
|
|
||||||
ns.new_usertype<axisangle>
|
ns.new_usertype<axisangle>
|
||||||
("axisangle",
|
("axisangle",
|
||||||
|
@ -99,13 +98,13 @@ struct lua_core : runtime_lua_register<lua_core> {
|
||||||
// "mesh",
|
// "mesh",
|
||||||
// sol::constructors<mesh()>()
|
// sol::constructors<mesh()>()
|
||||||
// );
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct lua_core_register : runtime_lua_register<lua_core>
|
||||||
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
PW_RUNTIME_LUA_REGISTER(core)
|
//PW_RUNTIME_LUA_REGISTER(core)
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue