testing other registration methods for the registry
This commit is contained in:
parent
0809d9c54b
commit
6ee3732994
9 changed files with 139 additions and 126 deletions
|
@ -1,20 +1,34 @@
|
||||||
|
#include "pw/core/core.hpp"
|
||||||
|
#include "pw/core/debug.hpp"
|
||||||
|
|
||||||
//#include <GLFW/glfw3.h>
|
namespace pw {
|
||||||
|
|
||||||
//#include <lua.hpp>
|
template <typename T> struct module {
|
||||||
//#include <lualib.h>
|
|
||||||
|
module() {
|
||||||
|
debug::d() << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct proxy {
|
||||||
|
proxy() {
|
||||||
|
debug::d() << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static proxy _proxy;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T> typename module<T>::proxy module<T>::_proxy;
|
||||||
|
|
||||||
|
|
||||||
#include "pw/core/matrixbase.hpp"
|
struct stuff {
|
||||||
//#include "pw/core/matrix.hpp"
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
void test_matrixbase() {
|
module<stuff> mod;
|
||||||
using namespace pw;
|
|
||||||
|
|
||||||
// matrix4x4f m;
|
|
||||||
|
|
||||||
// m.set_identity();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,6 @@
|
||||||
|
|
||||||
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},
|
||||||
|
@ -58,6 +56,8 @@ int main(int argc,const char** argv) {
|
||||||
|
|
||||||
input.close();
|
input.close();
|
||||||
|
|
||||||
|
pw::script::initialize();
|
||||||
|
|
||||||
pw::script s;
|
pw::script s;
|
||||||
|
|
||||||
return s.eval(sout.str().c_str());
|
return s.eval(sout.str().c_str());
|
||||||
|
|
|
@ -80,7 +80,7 @@ mesh primitives::sphere(real_t radius,int divisions_latitude,int divisions_longi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return geom;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,11 +30,14 @@ namespace pw {
|
||||||
class script {
|
class script {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
script();
|
script();
|
||||||
~script();
|
~script();
|
||||||
|
|
||||||
int eval(const std::string& s);
|
int eval(const std::string& s);
|
||||||
|
|
||||||
|
static void initialize();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
struct state;
|
struct state;
|
||||||
|
|
|
@ -17,4 +17,5 @@ runtime_lua::runtime_lua()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,22 +29,9 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
void register_core_lua();
|
||||||
struct runtime_lua_register
|
|
||||||
{
|
|
||||||
runtime_lua_register()
|
|
||||||
{
|
|
||||||
debug::d() << __PRETTY_FUNCTION__;
|
|
||||||
runtime_lua::get().add("test",&T::register_function);
|
|
||||||
}
|
|
||||||
|
|
||||||
static runtime_lua_register<T> _instance;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T> runtime_lua_register<T> runtime_lua_register<T>::_instance;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,7 +15,7 @@ struct script::state {
|
||||||
|
|
||||||
state();
|
state();
|
||||||
|
|
||||||
void load_modules();
|
void load_all();
|
||||||
void load(const std::string& name);
|
void load(const std::string& name);
|
||||||
|
|
||||||
int run(const std::string &s);
|
int run(const std::string &s);
|
||||||
|
@ -29,7 +29,8 @@ int script::state::run(const std::string &s)
|
||||||
|
|
||||||
void script::state::load(const std::string& name)
|
void script::state::load(const std::string& name)
|
||||||
{
|
{
|
||||||
runtime_lua::get().register_functions()[name](_state,_namespace);
|
auto f = runtime_lua::get().register_functions()[name];
|
||||||
|
f(_state,_namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
script::state::state()
|
script::state::state()
|
||||||
|
@ -40,21 +41,24 @@ script::state::state()
|
||||||
|
|
||||||
// add the script as a user type
|
// add the script as a user type
|
||||||
_namespace.new_usertype<state>("script",
|
_namespace.new_usertype<state>("script",
|
||||||
"initialize",&state::load_modules,
|
"initialize",&state::load_all,
|
||||||
"load",&state::load
|
"load",&state::load
|
||||||
);
|
);
|
||||||
|
|
||||||
// add this instance as "script"
|
// add this instance as "script"
|
||||||
_namespace.set("script",this);
|
_namespace.set("script",this);
|
||||||
|
|
||||||
debug::d() << "available " << runtime_lua::get().register_functions().size();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void script::state::load_modules() {
|
void script::state::load_all() {
|
||||||
|
|
||||||
// open all libraries
|
// open all libraries
|
||||||
_state.open_libraries();
|
_state.open_libraries();
|
||||||
|
|
||||||
|
//
|
||||||
|
for (auto m : runtime_lua::get().register_functions()) {
|
||||||
|
m.second(_state,_namespace);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -75,6 +79,11 @@ int script::eval(const std::string &s)
|
||||||
return _state->run(s);
|
return _state->run(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void script::initialize()
|
||||||
|
{
|
||||||
|
register_core_lua();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,100 +11,98 @@
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
struct lua_core {
|
|
||||||
|
|
||||||
std::string module_name() const { return "core"; }
|
void register_core_function(sol::state& lua,sol::table& ns)
|
||||||
|
|
||||||
void register_function(sol::state& lua,sol::table& ns)
|
|
||||||
{
|
|
||||||
|
|
||||||
typedef real_t Scalar;
|
|
||||||
|
|
||||||
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<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",
|
|
||||||
sol::constructors<axisangle(), axisangle(vector3,Scalar)>(),
|
|
||||||
"axis",sol::property(&axisangle::axis,&axisangle::set_axis),
|
|
||||||
"angle",sol::property(&axisangle::angle,&axisangle::set_angle)
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
ns.new_usertype<size>("size",
|
|
||||||
sol::constructors<size(),size(Scalar,Scalar)>(),
|
|
||||||
"width",&size::width,
|
|
||||||
"height",&size::height
|
|
||||||
// "none",sol::debug::level::none
|
|
||||||
);
|
|
||||||
|
|
||||||
ns.new_usertype<point>("point",
|
|
||||||
sol::constructors<point(),point(Scalar,Scalar)>(),
|
|
||||||
"x",&point::x,
|
|
||||||
"y",&point::y
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
ns.new_usertype<debug>("debug",
|
|
||||||
"new",sol::no_constructor,
|
|
||||||
"get",&debug::get,
|
|
||||||
"write",&debug::write
|
|
||||||
// "none",sol::debug::level::none
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
ns.new_usertype<timer>("timer",
|
|
||||||
"now",sol::readonly_property(&timer::now),
|
|
||||||
"elapsed",sol::readonly_property(&timer::elapsed),
|
|
||||||
"reset",&timer::reset
|
|
||||||
);
|
|
||||||
|
|
||||||
ns.new_usertype<mesh>
|
|
||||||
(
|
|
||||||
"mesh",
|
|
||||||
sol::constructors<mesh()>()
|
|
||||||
);
|
|
||||||
|
|
||||||
// lua["mesh"].new_enum()
|
|
||||||
// (
|
|
||||||
// "mesh",
|
|
||||||
// sol::constructors<mesh()>()
|
|
||||||
// );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct lua_core_register : runtime_lua_register<lua_core>
|
|
||||||
{
|
{
|
||||||
};
|
|
||||||
|
|
||||||
//PW_RUNTIME_LUA_REGISTER(core)
|
debug::d() << "registering ";
|
||||||
|
|
||||||
|
typedef real_t Scalar;
|
||||||
|
|
||||||
|
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<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",
|
||||||
|
sol::constructors<axisangle(), axisangle(vector3,Scalar)>(),
|
||||||
|
"axis",sol::property(&axisangle::axis,&axisangle::set_axis),
|
||||||
|
"angle",sol::property(&axisangle::angle,&axisangle::set_angle)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
ns.new_usertype<size>("size",
|
||||||
|
sol::constructors<size(),size(Scalar,Scalar)>(),
|
||||||
|
"width",&size::width,
|
||||||
|
"height",&size::height
|
||||||
|
// "none",sol::debug::level::none
|
||||||
|
);
|
||||||
|
|
||||||
|
ns.new_usertype<point>("point",
|
||||||
|
sol::constructors<point(),point(Scalar,Scalar)>(),
|
||||||
|
"x",&point::x,
|
||||||
|
"y",&point::y
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
ns.new_usertype<debug>("debug",
|
||||||
|
"new",sol::no_constructor,
|
||||||
|
"get",&debug::get,
|
||||||
|
"write",&debug::write
|
||||||
|
// "none",sol::debug::level::none
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
ns.new_usertype<timer>("timer",
|
||||||
|
"now",sol::readonly_property(&timer::now),
|
||||||
|
"elapsed",sol::readonly_property(&timer::elapsed),
|
||||||
|
"reset",&timer::reset
|
||||||
|
);
|
||||||
|
|
||||||
|
ns.new_usertype<mesh>
|
||||||
|
(
|
||||||
|
"mesh",
|
||||||
|
sol::constructors<mesh()>()
|
||||||
|
);
|
||||||
|
|
||||||
|
// lua["mesh"].new_enum()
|
||||||
|
// (
|
||||||
|
// "mesh",
|
||||||
|
// sol::constructors<mesh()>()
|
||||||
|
// );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void register_core_lua()
|
||||||
|
{
|
||||||
|
runtime_lua::get().add("core",register_core_function);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
-- loading our libraries
|
-- loading our libraries
|
||||||
pw.script:initialize()
|
pw.script:initialize()
|
||||||
|
|
||||||
os.exit()
|
pw.script:load("core")
|
||||||
|
|
||||||
|
|
||||||
local v1 = pw.vector3.new(3,2,1)
|
local v1 = pw.vector3.new(3,2,1)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue