revert back to sol2
This commit is contained in:
parent
ce8e89af51
commit
f3c17f6d03
16 changed files with 184 additions and 118 deletions
|
@ -25,7 +25,7 @@ target_include_directories(
|
|||
pwbinding
|
||||
PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/src/deps/lua-5.3.5/src
|
||||
${CMAKE_SOURCE_DIR}/src/deps/sol2-3.2.2/include
|
||||
${CMAKE_SOURCE_DIR}/src/deps/sol2-2.20.6
|
||||
PUBLIC
|
||||
include
|
||||
)
|
||||
|
@ -36,4 +36,5 @@ target_link_libraries(pwbinding
|
|||
pwsystem
|
||||
pwio
|
||||
pwscene
|
||||
pwvisual)
|
||||
pwvisual
|
||||
)
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
script();
|
||||
~script();
|
||||
|
||||
int eval(const std::string& s);
|
||||
int eval(const std::string_view &s);
|
||||
|
||||
static void initialize();
|
||||
|
||||
|
|
|
@ -8,7 +8,9 @@ runtime_lua &runtime_lua::get()
|
|||
return instance;
|
||||
}
|
||||
|
||||
void runtime_lua::add(const std::string &name, runtime_lua::register_function_t f) {
|
||||
void runtime_lua::add(const std::string &name
|
||||
,runtime_lua::register_function_t f)
|
||||
{
|
||||
_register_function_list[name] = f;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,24 @@ PW_REGISTER_DECL_LUA(io)
|
|||
PW_REGISTER_DECL_LUA(scene)
|
||||
PW_REGISTER_DECL_LUA(visual)
|
||||
|
||||
|
||||
void static_example()
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
// in SOL 2.20.6
|
||||
|
||||
|
||||
|
||||
// in SOL 3.2.2
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
struct script::state {
|
||||
|
||||
sol::state _state;
|
||||
|
@ -24,13 +42,19 @@ struct script::state {
|
|||
void load_all();
|
||||
void load(const std::string& name);
|
||||
|
||||
int run(const std::string &s);
|
||||
int eval(const std::string_view &code);
|
||||
|
||||
};
|
||||
|
||||
int script::state::run(const std::string &s)
|
||||
int script::state::eval(const std::string_view &code)
|
||||
{
|
||||
return _state.script(s.c_str()).get<int>();
|
||||
auto results = _state.safe_script(code);
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
// sol2
|
||||
// return _state.script(s.c_str()).get<int>();
|
||||
}
|
||||
|
||||
void script::state::load(const std::string& name)
|
||||
|
@ -80,20 +104,18 @@ script::~script()
|
|||
{
|
||||
}
|
||||
|
||||
int script::eval(const std::string &s)
|
||||
int script::eval(const std::string_view &s)
|
||||
{
|
||||
return _state->run(s);
|
||||
return _state->eval(s);
|
||||
}
|
||||
|
||||
void script::initialize()
|
||||
{
|
||||
|
||||
PW_REGISTER_USE_LUA(core)
|
||||
PW_REGISTER_USE_LUA(system)
|
||||
PW_REGISTER_USE_LUA(io)
|
||||
PW_REGISTER_USE_LUA(scene)
|
||||
PW_REGISTER_USE_LUA(visual)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
|
||||
// seems CRTP magic doesnt work with SOL
|
||||
namespace sol {
|
||||
template <> struct is_automagical<pw::matrix4x4> : std::false_type {};
|
||||
template <> struct is_automagical<pw::vector3> : std::false_type {};
|
||||
template <> struct is_automagical<pw::quaternion> : std::false_type {};
|
||||
template <> struct is_automagical<pw::matrix4x4> : std::false_type {};
|
||||
template <> struct is_automagical<pw::vector3> : std::false_type {};
|
||||
template <> struct is_automagical<pw::quaternion> : std::false_type {};
|
||||
}
|
||||
|
||||
namespace pw {
|
||||
|
@ -47,7 +47,7 @@ void register_core_function(sol::state& lua,sol::table& ns)
|
|||
);
|
||||
|
||||
ns.new_usertype<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;})
|
||||
,"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;})
|
||||
|
@ -103,29 +103,33 @@ void register_core_function(sol::state& lua,sol::table& ns)
|
|||
"elapsed",sol::readonly_property(&time::elapsed),
|
||||
"reset",&time::reset
|
||||
);
|
||||
|
||||
auto geoom_type = ns.new_usertype<geometry>("geometry"
|
||||
ns.new_usertype<geometry>("geometry"
|
||||
, sol::constructors<geometry()>()
|
||||
, "topology", sol::property(&geometry::topology,&geometry::set_topology)
|
||||
, "vertices", sol::property(&geometry::vertices,&geometry::set_vertices)
|
||||
, "indices", sol::property(&geometry::indices,&geometry::set_indices)
|
||||
);
|
||||
geoom_type["type"] = lua.create_table_with(
|
||||
"points", geometry::topology_type::points
|
||||
).new_enum<false>("topology_type"
|
||||
,"points", geometry::topology_type::points
|
||||
, "lines", geometry::topology_type::lines
|
||||
, "line_strip", geometry::topology_type::line_strip
|
||||
);
|
||||
, "line_strip", geometry::topology_type::line_strip);
|
||||
|
||||
auto image_type = ns.new_usertype<image>("image"
|
||||
|
||||
// SOL3
|
||||
// geoom_type["type"] = lua.create_table_with(
|
||||
// "points", geometry::topology_type::points
|
||||
// , "lines", geometry::topology_type::lines
|
||||
// , "line_strip", geometry::topology_type::line_strip
|
||||
// );
|
||||
|
||||
ns.new_usertype<image>("image"
|
||||
, sol::constructors<image()>()
|
||||
,"create",&image::create
|
||||
,"size",sol::readonly_property(&image::size)
|
||||
,"change_count",sol::property(&image::change_count,&image::set_change_count)
|
||||
);
|
||||
|
||||
// image_type.new_enum("layout"
|
||||
// ,"rgb8", image::RGB8
|
||||
// ,"rgb32", image::RGBA8
|
||||
// ,"gray", image::LUM);
|
||||
).new_enum<false>("layout"
|
||||
,"rgb8", image::RGB8
|
||||
,"rgb32", image::RGBA8
|
||||
,"gray", image::LUM);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ void register_io_function(sol::state&,sol::table& ns)
|
|||
,"new", sol::no_constructor
|
||||
,"get",&image_io::get
|
||||
,"read",&image_io::read
|
||||
, "write",&image_io::write
|
||||
,"write",&image_io::write
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,19 +6,27 @@
|
|||
|
||||
#include "runtime_lua.hpp"
|
||||
|
||||
namespace sol {
|
||||
template <> struct is_automagical<pw::entity> : std::false_type {};
|
||||
}
|
||||
|
||||
namespace pw {
|
||||
|
||||
|
||||
void register_scene_function(sol::state&,sol::table &ns)
|
||||
{
|
||||
|
||||
ns.new_usertype<scene>("scene",
|
||||
sol::constructors<scene()>());
|
||||
sol::constructors<scene()>()
|
||||
,"count_all_entities",sol::readonly_property(&scene::count_all_enties)
|
||||
,"count_alive_entities",sol::readonly_property(&scene::count_alive_enties)
|
||||
);
|
||||
|
||||
|
||||
ns.new_usertype<entity>("entity",
|
||||
sol::constructors</*entity(),*/entity(scene&)>(),
|
||||
"add_child",&entity::add_child,
|
||||
"child_count",sol::readonly_property(&entity::child_count)
|
||||
ns.new_usertype<entity>("entity"
|
||||
,sol::constructors<entity(),entity(const entity&),entity(scene&)>()
|
||||
,"add_child",&entity::add_child
|
||||
,"child_count",sol::readonly_property(&entity::child_count)
|
||||
);
|
||||
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ public:
|
|||
stream& operator << (const bool &value);
|
||||
stream& operator << (const char *value);
|
||||
stream& operator << (const std::string& value); ///! log a string
|
||||
stream& operator << (const std::string_view& value); ///! log a string_view
|
||||
|
||||
stream& operator << (const float &value); ///! log a float value
|
||||
stream& operator << (const double &value); ///! log a double value
|
||||
|
|
|
@ -22,13 +22,6 @@ template <typename T> struct module {
|
|||
template <typename T> typename module<T>::proxy module<T>::_proxy;
|
||||
|
||||
|
||||
struct stuff {
|
||||
|
||||
};
|
||||
|
||||
|
||||
module<stuff> mod;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -140,6 +140,12 @@ debug::stream &debug::stream::operator <<(const std::string &value)
|
|||
return *this;
|
||||
}
|
||||
|
||||
debug::stream &debug::stream::operator <<(const std::string_view &value)
|
||||
{
|
||||
_line.append(value.data());
|
||||
return *this;
|
||||
}
|
||||
|
||||
debug::stream &debug::stream::operator <<(const float &value)
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
|
|
@ -64,7 +64,7 @@ public:
|
|||
}
|
||||
|
||||
template<typename T>
|
||||
bool has_component() const { return _registry->valid(_entity);}
|
||||
bool has_component() const { return _registry->has<T>(_entity);}
|
||||
|
||||
void destroy();
|
||||
|
||||
|
|
|
@ -38,6 +38,9 @@ public:
|
|||
scene();
|
||||
~scene() = default;
|
||||
|
||||
size_t count_all_enties() const;
|
||||
size_t count_alive_enties() const;
|
||||
|
||||
protected:
|
||||
|
||||
std::shared_ptr<entt::registry> _registry;
|
||||
|
|
|
@ -8,5 +8,17 @@ scene::scene()
|
|||
{
|
||||
}
|
||||
|
||||
size_t scene::count_all_enties() const
|
||||
{
|
||||
return _registry->size();
|
||||
}
|
||||
|
||||
size_t scene::count_alive_enties() const
|
||||
{
|
||||
return _registry->alive();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ void test_stack()
|
|||
e.add_child(e2);
|
||||
e.add_child(e3);
|
||||
|
||||
|
||||
std::cout << e.child_count() << std::endl;
|
||||
|
||||
}
|
||||
|
@ -55,6 +56,13 @@ void test_heap()
|
|||
|
||||
auto e = std::make_unique<entity>(*s);
|
||||
|
||||
auto e2 = std::make_unique<entity>(*s);
|
||||
|
||||
e->add_child(*e2);
|
||||
|
||||
pw::debug::d() << e->child_count();
|
||||
|
||||
|
||||
auto t = e->add_component<test>(112);
|
||||
|
||||
std::cout << t.val << std::endl;
|
||||
|
|
|
@ -2,20 +2,26 @@
|
|||
-- small demonstrator for Lua binding on pixwerx
|
||||
--
|
||||
|
||||
-- loading our libraries
|
||||
pw.script:load_all()
|
||||
|
||||
print("hello pixwerx!")
|
||||
|
||||
local s = pw.scene.new()
|
||||
|
||||
e = pw.entity.new(s)
|
||||
e2 = pw.entity.new(s)
|
||||
print(s)
|
||||
|
||||
local e = pw.entity.new(s)
|
||||
c = pw.entity.new(s)
|
||||
|
||||
print(e)
|
||||
e2.add_child(e)
|
||||
print(e.child_count)
|
||||
|
||||
-- print(s)
|
||||
-- print(e2.child_count)
|
||||
-- add child
|
||||
e.add_child(c)
|
||||
|
||||
|
||||
print(e.child_count)
|
||||
|
||||
print("bye, bye pixwerx!")
|
||||
|
||||
return 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue