diff --git a/src/binding/CMakeLists.txt b/src/binding/CMakeLists.txt index d14876b..4ca806f 100644 --- a/src/binding/CMakeLists.txt +++ b/src/binding/CMakeLists.txt @@ -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 + ) diff --git a/src/binding/include/pw/scripting/script.hpp b/src/binding/include/pw/scripting/script.hpp index 8123757..7110ecc 100644 --- a/src/binding/include/pw/scripting/script.hpp +++ b/src/binding/include/pw/scripting/script.hpp @@ -34,7 +34,7 @@ public: script(); ~script(); - int eval(const std::string& s); + int eval(const std::string_view &s); static void initialize(); diff --git a/src/binding/src/runtime_lua.cpp b/src/binding/src/runtime_lua.cpp index 9446f40..5366647 100644 --- a/src/binding/src/runtime_lua.cpp +++ b/src/binding/src/runtime_lua.cpp @@ -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; } diff --git a/src/binding/src/script.cpp b/src/binding/src/script.cpp index c4c68fe..75cd034 100644 --- a/src/binding/src/script.cpp +++ b/src/binding/src/script.cpp @@ -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(); + auto results = _state.safe_script(code); + + return 0; + + + // sol2 + // return _state.script(s.c_str()).get(); } 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) - } diff --git a/src/binding/src/script_core.cpp b/src/binding/src/script_core.cpp index ac44524..31e11f0 100644 --- a/src/binding/src/script_core.cpp +++ b/src/binding/src/script_core.cpp @@ -13,9 +13,9 @@ // seems CRTP magic doesnt work with SOL namespace sol { - template <> struct is_automagical : std::false_type {}; - template <> struct is_automagical : std::false_type {}; - template <> struct is_automagical : std::false_type {}; +template <> struct is_automagical : std::false_type {}; +template <> struct is_automagical : std::false_type {}; +template <> struct is_automagical : std::false_type {}; } namespace pw { @@ -23,109 +23,113 @@ namespace pw { void register_core_function(sol::state& lua,sol::table& ns) { - typedef real_t Scalar; + typedef real_t Scalar; - ns.set("pi",pw::pi()); + ns.set("pi",pw::pi()); - ns.new_usertype("matrix4x4" - , sol::constructors() - , "row",&matrix4x4::row - , "column",&matrix4x4::column - , "set_identity",&matrix4x4::set_identity - , "inverse",&matrix4x4::inverse - ); + ns.new_usertype("matrix4x4" + , sol::constructors() + , "row",&matrix4x4::row + , "column",&matrix4x4::column + , "set_identity",&matrix4x4::set_identity + , "inverse",&matrix4x4::inverse + ); - ns.new_usertype("vector3" - ,sol::constructors() - ,"x", sol::property(sol::resolve(&vector3::x), [](vector3& v,vector3::value_type val){ v.x() = val;}) - ,"y", sol::property(sol::resolve(&vector3::y), [](vector3& v,vector3::value_type val){ v.y() = val;}) - ,"z", sol::property(sol::resolve(&vector3::z), [](vector3& v,vector3::value_type val){ v.z() = val;}) - ,"cross",&vector3::cross - ,"transposed",&vector3::transposed - ,"lerp",&vector3::lerp - ); + ns.new_usertype("vector3" + ,sol::constructors() + ,"x", sol::property(sol::resolve(&vector3::x), [](vector3& v,vector3::value_type val){ v.x() = val;}) + ,"y", sol::property(sol::resolve(&vector3::y), [](vector3& v,vector3::value_type val){ v.y() = val;}) + ,"z", sol::property(sol::resolve(&vector3::z), [](vector3& v,vector3::value_type val){ v.z() = val;}) + ,"cross",&vector3::cross + ,"transposed",&vector3::transposed + ,"lerp",&vector3::lerp + ); ns.new_usertype("quaternion" - , sol::constructors() + ,sol::constructors() ,"x", sol::property(sol::resolve(&quaternion::x), [](quaternion& v,quaternion::value_type val){ v.x() = val;}) ,"y", sol::property(sol::resolve(&quaternion::y), [](quaternion& v,quaternion::value_type val){ v.y() = val;}) ,"z", sol::property(sol::resolve(&quaternion::z), [](quaternion& v,quaternion::value_type val){ v.z() = val;}) ,"w", sol::property(sol::resolve(&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 + ,"inverse",sol::readonly_property(&quaternion::inverse) + ,"normalized",&quaternion::normalized + ,"lerp",&quaternion::lerp + ,"slerp",&quaternion::slerp ,"matrix",&quaternion::to_matrix - ); + ); - ns.new_usertype - ("axisangle", - sol::constructors(), - "axis",&axisangle::axis, - "angle",&axisangle::angle, - "from_matrix",&axisangle::from_matrix, - "to_matrix",&axisangle::to_matrix - ); + ns.new_usertype + ("axisangle", + sol::constructors(), + "axis",&axisangle::axis, + "angle",&axisangle::angle, + "from_matrix",&axisangle::from_matrix, + "to_matrix",&axisangle::to_matrix + ); - ns.new_usertype("size" - , sol::constructors() - , "width",&size::width - , "height",&size::height - ); + ns.new_usertype("size" + , sol::constructors() + , "width",&size::width + , "height",&size::height + ); ns.new_usertype("sizei" - , sol::constructors() - , "width",&sizei::width - , "height",&sizei::height + , sol::constructors() + , "width",&sizei::width + , "height",&sizei::height + ); + + ns.new_usertype("point", + sol::constructors(), + "x",&point::x, + "y",&point::y + ); + + + ns.new_usertype("debug", + "new",sol::no_constructor, + "get",&debug::get, + "write",&debug::write + // "none",sol::debug::level::none + ); + + + ns.new_usertype