Giter VIP home page Giter VIP logo

entityx_lua's Introduction

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.

using namespace entityx;
using namespace entityx::lua;

struct Position : 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) {
		return Position(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 class
Player = entityx.manager:new()
function Player:init(o)
	o = o or {}
	-- this class has a component "Position"
	self.position = self:component("Position", o.position or {0, 0})
end
-- create an instance of this class
p = Player:instance({position = {10, 20}})
-- set Position.x to 5
p.position.x(5)
-- this will print 5, 20
print(p.position.x(), p.position.y())

Event system is not supported yet.

entityx_lua's People

Contributors

acaly avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.