You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This system adds the ability to extend entity logic with Lua scripts.
It has only been tested with entityx 0.1.0. 1.0.0 compatible version is still work in process.
Example
To use this system, first include the header entityx_lua.h. Create a component Position and export it to lua.
usingnamespaceentityx;usingnamespaceentityx::lua;structPosition : entityx::Component<Position> {
Position(float x = 0.0f, float y = 0.0f) : x(x), y(y) {}
float x, y;
};
export_component<Position>("Position",
// Use wrapped constructor to create an object from lua
wrap_ctor<Position, float, float>([](float x, float y) {
returnPosition(x, y);
}),
// Make x and y accessible from lua
[](MemberRegister<Position>& m) {
m.add("x", &Position::x);
m.add("y", &Position::y);
}
);
Create the lua state and export the entity manager.
Then you can use the entityx and the component Position in lua.
-- create a entity classPlayer=entityx.manager:new()
functionPlayer:init(o)
o=oor {}
-- this class has a component "Position"self.position=self:component("Position", o.positionor {0, 0})
end-- create an instance of this classp=Player:instance({position= {10, 20}})
-- set Position.x to 5p.position.x(5)
-- this will print 5, 20print(p.position.x(), p.position.y())