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,16 +4,33 @@
|
|||
#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<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)
|
||||
{
|
||||
ns.new_usertype<window>("window",
|
||||
ns.new_usertype<window_lua>("window",
|
||||
sol::constructors<window_lua(sol::this_state)>(),
|
||||
"on_update",&window_lua::lua_update,
|
||||
"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),
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue