worked out a simple way to call a lua function as a method based on the overridable_function_members.cpp
example
This commit is contained in:
parent
e267a0d2ed
commit
29da543ed7
2 changed files with 37 additions and 15 deletions
|
@ -4,21 +4,38 @@
|
||||||
#include "pw/system/input.hpp"
|
#include "pw/system/input.hpp"
|
||||||
#include "pw/system/display.hpp"
|
#include "pw/system/display.hpp"
|
||||||
|
|
||||||
|
#include "pw/core/debug.hpp"
|
||||||
|
|
||||||
// hijacking
|
// hijacking
|
||||||
//#include "pw/visual/pipeline.hpp"
|
//#include "pw/visual/pipeline.hpp"
|
||||||
|
|
||||||
namespace pw {
|
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<sol::function>(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)
|
void script_system::load(sol::table &ns)
|
||||||
{
|
{
|
||||||
ns.new_usertype<window>("window",
|
ns.new_usertype<window_lua>("window",
|
||||||
"update",&window::update,
|
sol::constructors<window_lua(sol::this_state)>(),
|
||||||
"set_on_update",&window::set_on_update,
|
"on_update",&window_lua::lua_update,
|
||||||
"title",sol::writeonly_property(&window::set_title),
|
"update",&window::update,
|
||||||
"size",sol::property(&window::size,&window::set_size),
|
"title",sol::writeonly_property(&window::set_title),
|
||||||
"position",sol::property(&window::position,&window::set_position),
|
"size",sol::property(&window::size,&window::set_size),
|
||||||
"fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen)
|
"position",sol::property(&window::position,&window::set_position),
|
||||||
);
|
"fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen)
|
||||||
|
);
|
||||||
|
|
||||||
ns.new_usertype<input>("input",
|
ns.new_usertype<input>("input",
|
||||||
"new", sol::no_constructor,
|
"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
|
// // hijack part
|
||||||
// //
|
// //
|
||||||
// ns.new_usertype<pipeline>("pipeline",
|
// ns.new_usertype<pipeline>("pipeline",
|
||||||
// "create",&pipeline::create
|
// "create",&pipeline::create
|
||||||
// );
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,11 @@ local w = pw.window.new()
|
||||||
-- set title
|
-- set title
|
||||||
w.title = "pixwerx 0.1"
|
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
|
-- set size
|
||||||
w.size = pw.size.new(800,600)
|
w.size = pw.size.new(800,600)
|
||||||
-- move window
|
-- move window
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue