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>
|
||||
//#include <lualib.h>
|
||||
template <typename T> struct module {
|
||||
|
||||
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"
|
||||
//#include "pw/core/matrix.hpp"
|
||||
struct stuff {
|
||||
|
||||
};
|
||||
|
||||
|
||||
void test_matrixbase() {
|
||||
using namespace pw;
|
||||
module<stuff> mod;
|
||||
|
||||
// matrix4x4f m;
|
||||
|
||||
// m.set_identity();
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
|
||||
int main(int argc,const char** argv) {
|
||||
|
||||
// pw_runtime_lua_core();
|
||||
|
||||
argagg::parser argparser {{
|
||||
{ "help", {"-h", "--help"},
|
||||
"shows this help message", 0},
|
||||
|
@ -58,6 +56,8 @@ int main(int argc,const char** argv) {
|
|||
|
||||
input.close();
|
||||
|
||||
pw::script::initialize();
|
||||
|
||||
pw::script s;
|
||||
|
||||
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 {
|
||||
public:
|
||||
|
||||
|
||||
script();
|
||||
~script();
|
||||
|
||||
int eval(const std::string& s);
|
||||
|
||||
static void initialize();
|
||||
|
||||
protected:
|
||||
|
||||
struct state;
|
||||
|
|
|
@ -17,4 +17,5 @@ runtime_lua::runtime_lua()
|
|||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -29,22 +29,9 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
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;
|
||||
void register_core_lua();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,7 +15,7 @@ struct script::state {
|
|||
|
||||
state();
|
||||
|
||||
void load_modules();
|
||||
void load_all();
|
||||
void load(const std::string& name);
|
||||
|
||||
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)
|
||||
{
|
||||
runtime_lua::get().register_functions()[name](_state,_namespace);
|
||||
auto f = runtime_lua::get().register_functions()[name];
|
||||
f(_state,_namespace);
|
||||
}
|
||||
|
||||
script::state::state()
|
||||
|
@ -40,21 +41,24 @@ script::state::state()
|
|||
|
||||
// add the script as a user type
|
||||
_namespace.new_usertype<state>("script",
|
||||
"initialize",&state::load_modules,
|
||||
"initialize",&state::load_all,
|
||||
"load",&state::load
|
||||
);
|
||||
|
||||
// add this instance as "script"
|
||||
_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
|
||||
_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);
|
||||
}
|
||||
|
||||
void script::initialize()
|
||||
{
|
||||
register_core_lua();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -11,45 +11,44 @@
|
|||
|
||||
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)
|
||||
{
|
||||
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<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",
|
||||
|
@ -98,13 +97,12 @@ struct lua_core {
|
|||
// "mesh",
|
||||
// sol::constructors<mesh()>()
|
||||
// );
|
||||
}
|
||||
};
|
||||
|
||||
struct lua_core_register : runtime_lua_register<lua_core>
|
||||
{
|
||||
};
|
||||
|
||||
//PW_RUNTIME_LUA_REGISTER(core)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void register_core_lua()
|
||||
{
|
||||
runtime_lua::get().add("core",register_core_function);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
-- loading our libraries
|
||||
pw.script:initialize()
|
||||
|
||||
os.exit()
|
||||
pw.script:load("core")
|
||||
|
||||
|
||||
local v1 = pw.vector3.new(3,2,1)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue