Skip to content

Latest commit

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Lua Bindings for EntityX

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.

lua_State* L = luaL_newstate();
luaL_openlibs(L);
setup_entityx_api(L);
ptr<EventManager> events(new EventManager());
ptr<EntityManager> entities(new EntityManager(events));
new_entity_manager(L, entities, "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())

Event system is not supported yet.

About

Lua binding for entityx

Resources

Stars

10 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages