From 787393dd86d6c37b5680847dd4eef14406a86687 Mon Sep 17 00:00:00 2001 From: Andy Belle-Isle Date: Tue, 27 Aug 2019 00:24:05 -0400 Subject: Created basic init script --- Scripts/init.lua | 11 +++++++++++ src/main.cpp | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 Scripts/init.lua diff --git a/Scripts/init.lua b/Scripts/init.lua new file mode 100644 index 0000000..ded10ec --- /dev/null +++ b/Scripts/init.lua @@ -0,0 +1,11 @@ +Player = entityx.manager:new() +function Player:init(o) + o = o or {} + self.position = self:component("Position", o.position or {0, 0}) +end + +p = Player:instance({position = {10, 20}}) +p.position.x(5) +print(p.position.x(), p.position.y()) + +print("HEY") diff --git a/src/main.cpp b/src/main.cpp index 0597d48..b3d4744 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -139,15 +139,38 @@ void logicLoop(void) } } +struct Position : entityx::Component +{ + Position(float _x, float _y): x(_x), y(_y) {} + + float x,y; +}; + void LuaTest(void) { using namespace entityx; using namespace entityx::lua; + //export_component("Position", + // wrap_ctor([](float x, float y) { + // return Position(x, y); + // }), + // [](MemberRegister& m) { + // m.add("x", &Position::x); + // m.add("y", &Position::y); + // } + //); + lua_State* L = luaL_newstate(); luaL_openlibs(L); setup_entityx_api(L); + std::shared_ptr events(new EventManager()); + std::shared_ptr entities(new EntityManager(*events)); + new_entity_manager(L, entities, "manager"); + + luaL_dofile(L, "Scripts/init.lua"); + lua_close(L); } -- cgit v1.2.3