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
|
pwbinding
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_SOURCE_DIR}/src/deps/lua-5.3.5/src
|
${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
|
PUBLIC
|
||||||
include
|
include
|
||||||
)
|
)
|
||||||
|
@ -36,4 +36,5 @@ target_link_libraries(pwbinding
|
||||||
pwsystem
|
pwsystem
|
||||||
pwio
|
pwio
|
||||||
pwscene
|
pwscene
|
||||||
pwvisual)
|
pwvisual
|
||||||
|
)
|
||||||
|
|
|
@ -34,7 +34,7 @@ public:
|
||||||
script();
|
script();
|
||||||
~script();
|
~script();
|
||||||
|
|
||||||
int eval(const std::string& s);
|
int eval(const std::string_view &s);
|
||||||
|
|
||||||
static void initialize();
|
static void initialize();
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,9 @@ runtime_lua &runtime_lua::get()
|
||||||
return instance;
|
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;
|
_register_function_list[name] = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,24 @@ PW_REGISTER_DECL_LUA(io)
|
||||||
PW_REGISTER_DECL_LUA(scene)
|
PW_REGISTER_DECL_LUA(scene)
|
||||||
PW_REGISTER_DECL_LUA(visual)
|
PW_REGISTER_DECL_LUA(visual)
|
||||||
|
|
||||||
|
|
||||||
|
void static_example()
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// in SOL 2.20.6
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// in SOL 3.2.2
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
struct script::state {
|
struct script::state {
|
||||||
|
|
||||||
sol::state _state;
|
sol::state _state;
|
||||||
|
@ -24,13 +42,19 @@ struct script::state {
|
||||||
void load_all();
|
void load_all();
|
||||||
void load(const std::string& name);
|
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)
|
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()
|
void script::initialize()
|
||||||
{
|
{
|
||||||
|
|
||||||
PW_REGISTER_USE_LUA(core)
|
PW_REGISTER_USE_LUA(core)
|
||||||
PW_REGISTER_USE_LUA(system)
|
PW_REGISTER_USE_LUA(system)
|
||||||
PW_REGISTER_USE_LUA(io)
|
PW_REGISTER_USE_LUA(io)
|
||||||
PW_REGISTER_USE_LUA(scene)
|
PW_REGISTER_USE_LUA(scene)
|
||||||
PW_REGISTER_USE_LUA(visual)
|
PW_REGISTER_USE_LUA(visual)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -103,29 +103,33 @@ void register_core_function(sol::state& lua,sol::table& ns)
|
||||||
"elapsed",sol::readonly_property(&time::elapsed),
|
"elapsed",sol::readonly_property(&time::elapsed),
|
||||||
"reset",&time::reset
|
"reset",&time::reset
|
||||||
);
|
);
|
||||||
|
ns.new_usertype<geometry>("geometry"
|
||||||
auto geoom_type = ns.new_usertype<geometry>("geometry"
|
|
||||||
, sol::constructors<geometry()>()
|
, sol::constructors<geometry()>()
|
||||||
, "topology", sol::property(&geometry::topology,&geometry::set_topology)
|
, "topology", sol::property(&geometry::topology,&geometry::set_topology)
|
||||||
, "vertices", sol::property(&geometry::vertices,&geometry::set_vertices)
|
, "vertices", sol::property(&geometry::vertices,&geometry::set_vertices)
|
||||||
, "indices", sol::property(&geometry::indices,&geometry::set_indices)
|
, "indices", sol::property(&geometry::indices,&geometry::set_indices)
|
||||||
);
|
).new_enum<false>("topology_type"
|
||||||
geoom_type["type"] = lua.create_table_with(
|
,"points", geometry::topology_type::points
|
||||||
"points", geometry::topology_type::points
|
|
||||||
, "lines", geometry::topology_type::lines
|
, "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
|
,"create",&image::create
|
||||||
,"size",sol::readonly_property(&image::size)
|
,"size",sol::readonly_property(&image::size)
|
||||||
,"change_count",sol::property(&image::change_count,&image::set_change_count)
|
,"change_count",sol::property(&image::change_count,&image::set_change_count)
|
||||||
);
|
).new_enum<false>("layout"
|
||||||
|
,"rgb8", image::RGB8
|
||||||
// image_type.new_enum("layout"
|
,"rgb32", image::RGBA8
|
||||||
// ,"rgb8", image::RGB8
|
,"gray", image::LUM);
|
||||||
// ,"rgb32", image::RGBA8
|
|
||||||
// ,"gray", image::LUM);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,19 +6,27 @@
|
||||||
|
|
||||||
#include "runtime_lua.hpp"
|
#include "runtime_lua.hpp"
|
||||||
|
|
||||||
|
namespace sol {
|
||||||
|
template <> struct is_automagical<pw::entity> : std::false_type {};
|
||||||
|
}
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
|
|
||||||
void register_scene_function(sol::state&,sol::table &ns)
|
void register_scene_function(sol::state&,sol::table &ns)
|
||||||
{
|
{
|
||||||
|
|
||||||
ns.new_usertype<scene>("scene",
|
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",
|
ns.new_usertype<entity>("entity"
|
||||||
sol::constructors</*entity(),*/entity(scene&)>(),
|
,sol::constructors<entity(),entity(const entity&),entity(scene&)>()
|
||||||
"add_child",&entity::add_child,
|
,"add_child",&entity::add_child
|
||||||
"child_count",sol::readonly_property(&entity::child_count)
|
,"child_count",sol::readonly_property(&entity::child_count)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,7 @@ public:
|
||||||
stream& operator << (const bool &value);
|
stream& operator << (const bool &value);
|
||||||
stream& operator << (const char *value);
|
stream& operator << (const char *value);
|
||||||
stream& operator << (const std::string& value); ///! log a string
|
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 float &value); ///! log a float value
|
||||||
stream& operator << (const double &value); ///! log a double 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;
|
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;
|
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)
|
debug::stream &debug::stream::operator <<(const float &value)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
|
@ -64,7 +64,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
bool has_component() const { return _registry->valid(_entity);}
|
bool has_component() const { return _registry->has<T>(_entity);}
|
||||||
|
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,9 @@ public:
|
||||||
scene();
|
scene();
|
||||||
~scene() = default;
|
~scene() = default;
|
||||||
|
|
||||||
|
size_t count_all_enties() const;
|
||||||
|
size_t count_alive_enties() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
std::shared_ptr<entt::registry> _registry;
|
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(e2);
|
||||||
e.add_child(e3);
|
e.add_child(e3);
|
||||||
|
|
||||||
|
|
||||||
std::cout << e.child_count() << std::endl;
|
std::cout << e.child_count() << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -55,6 +56,13 @@ void test_heap()
|
||||||
|
|
||||||
auto e = std::make_unique<entity>(*s);
|
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);
|
auto t = e->add_component<test>(112);
|
||||||
|
|
||||||
std::cout << t.val << std::endl;
|
std::cout << t.val << std::endl;
|
||||||
|
|
|
@ -2,20 +2,26 @@
|
||||||
-- small demonstrator for Lua binding on pixwerx
|
-- small demonstrator for Lua binding on pixwerx
|
||||||
--
|
--
|
||||||
|
|
||||||
-- loading our libraries
|
|
||||||
pw.script:load_all()
|
pw.script:load_all()
|
||||||
|
|
||||||
print("hello pixwerx!")
|
print("hello pixwerx!")
|
||||||
|
|
||||||
local s = pw.scene.new()
|
local s = pw.scene.new()
|
||||||
|
|
||||||
e = pw.entity.new(s)
|
print(s)
|
||||||
e2 = pw.entity.new(s)
|
|
||||||
|
local e = pw.entity.new(s)
|
||||||
|
c = pw.entity.new(s)
|
||||||
|
|
||||||
print(e)
|
print(e)
|
||||||
e2.add_child(e)
|
print(e.child_count)
|
||||||
|
|
||||||
-- print(s)
|
-- add child
|
||||||
-- print(e2.child_count)
|
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