diff --git a/src/scripting/src/script_system.cpp b/src/scripting/src/script_system.cpp index f838ebe..b3a8c6d 100644 --- a/src/scripting/src/script_system.cpp +++ b/src/scripting/src/script_system.cpp @@ -4,21 +4,38 @@ #include "pw/system/input.hpp" #include "pw/system/display.hpp" +#include "pw/core/debug.hpp" + // hijacking //#include "pw/visual/pipeline.hpp" namespace pw { +struct window_lua : public window { + // overridable function + sol::function lua_update; + + window_lua(sol::this_state L) + // default is an empty callback + : lua_update(sol::make_reference(L.lua_state(), [](){})) + { + // set this internal callback of the window to the lua callback + _on_update = [this](window&){this->lua_update();}; + } +}; + + void script_system::load(sol::table &ns) { - ns.new_usertype("window", - "update",&window::update, - "set_on_update",&window::set_on_update, - "title",sol::writeonly_property(&window::set_title), - "size",sol::property(&window::size,&window::set_size), - "position",sol::property(&window::position,&window::set_position), - "fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen) - ); + ns.new_usertype("window", + sol::constructors(), + "on_update",&window_lua::lua_update, + "update",&window::update, + "title",sol::writeonly_property(&window::set_title), + "size",sol::property(&window::size,&window::set_size), + "position",sol::property(&window::position,&window::set_position), + "fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen) + ); ns.new_usertype("input", "new", sol::no_constructor, @@ -35,15 +52,15 @@ void script_system::load(sol::table &ns) ); -// ns.set_function("my_class_func_2", &my_class::func); + // ns.set_function("my_class_func_2", &my_class::func); - // -// // hijack part -// // -// ns.new_usertype("pipeline", -// "create",&pipeline::create -// ); + // + // // hijack part + // // + // ns.new_usertype("pipeline", + // "create",&pipeline::create + // ); } } diff --git a/src/scripts/demos/simple_000.lua b/src/scripts/demos/simple_000.lua index 89763b5..f7419dd 100644 --- a/src/scripts/demos/simple_000.lua +++ b/src/scripts/demos/simple_000.lua @@ -70,6 +70,11 @@ local w = pw.window.new() -- set title w.title = "pixwerx 0.1" +-- setup a lua callback function +w.on_update = function(self) + print("test on update",w.position.x,w.position.y) +end + -- set size w.size = pw.size.new(800,600) -- move window