From e1cdfd27cad943290a0233119548a8dd8876bd52 Mon Sep 17 00:00:00 2001 From: Andy Belle-Isle Date: Thu, 29 Aug 2019 20:02:35 -0400 Subject: Replaced LuaBridge with sol2 and completely encapsulated scripting within script system --- src/components/Component.hpp | 4 +- src/components/Position.hpp | 14 +++---- src/main.cpp | 84 --------------------------------------- src/script.hpp | 93 +++++++++++++++++++------------------------- src/script/script.hpp | 70 --------------------------------- 5 files changed, 50 insertions(+), 215 deletions(-) delete mode 100644 src/script/script.hpp (limited to 'src') diff --git a/src/components/Component.hpp b/src/components/Component.hpp index 84e860c..9c6b79d 100644 --- a/src/components/Component.hpp +++ b/src/components/Component.hpp @@ -19,7 +19,7 @@ #ifndef COMPONENT_HPP_ #define COMPONENT_HPP_ -#include "LuaBridge/LuaBridge.h" +#include "sol/sol.hpp" template class Component @@ -27,7 +27,7 @@ class Component public: Component(){}; - virtual T FromLua(luabridge::LuaRef) = 0; + virtual T FromLua(sol::object) = 0; }; #endif//COMPONENT_HPP_ diff --git a/src/components/Position.hpp b/src/components/Position.hpp index aaa99f9..856b3d7 100644 --- a/src/components/Position.hpp +++ b/src/components/Position.hpp @@ -29,17 +29,17 @@ struct Position : Component, entityx::Component Position(float _x, float _y): x(_x), y(_y) {} Position(void){x = y = 0.0;} - Position FromLua(luabridge::LuaRef ref) + Position FromLua(sol::object ref) { - if (ref.isTable()){ - if (!ref["x"].isNil()) - this->x = ref["x"]; - if (!ref["y"].isNil()) - this->y = ref["y"]; + if (ref.get_type() == sol::type::table){ + sol::table tab = ref; + if (tab["x"] != nullptr) + this->x = tab["x"]; + if (tab["y"] != nullptr) + this->y = tab["y"]; } else { throw std::string("Position table not formatted properly"); } - return *this; } }; diff --git a/src/main.cpp b/src/main.cpp index 386aafc..3dc7bed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,7 +20,6 @@ #include #include -#include #include "engine.hpp" @@ -50,86 +49,3 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[]) return 0; } - -/* -using namespace entityx; -namespace lb = luabridge; - -EventManager events; -EntityManager entities(events); - -lua_State* L; - -//lb::LuaRef spawn(lb::LuaRef ref) -//{ -// lb::LuaRef entity(L); -// entity = lb::newTable(L); -// -// if (ref.isTable()) { -// -// Entity e = entities.create(); -// -// for (auto &&comp : lb::pairs(ref)) { -// if (comp.first.cast() == "Position") { -// entity["Position"] = -// e.assign(Position().FromLua(comp.second)).get(); -// } else if (comp.first.cast() == "init") { -// entity["init"] = comp.second; -// } -// } -// } else { -// std::cerr << "Parameter to spawn() must be a table!" << std::endl; -// } -// -// return entity; -//} -// - -ScriptSystem sc; - -lb::LuaRef spawn(lb::LuaRef ref) -{ - return sc.spawn(ref); -} - - -void LuaTest(void) -{ - - sc.configure(entities, events); - - // Functions export - lb::getGlobalNamespace(sc.getState()) - .beginNamespace("game") - .addFunction("spawn", spawn) - .endNamespace(); - - sc.doFile(); - - - //L = luaL_newstate(); - //luaL_openlibs(L); - - //lb::getGlobalNamespace(L). - // beginNamespace("comp") - // .beginClass("Position") - // .addConstructor() - // .addProperty("x", &Position::x) - // .addProperty("y", &Position::y) - // .endClass() - // .endNamespace(); - - //lb::getGlobalNamespace(L) - // .beginNamespace("game") - // .addFunction("spawn", spawn) - // .endNamespace(); - - //if (luaL_dofile(L, "Scripts/init.lua")) { - // std::cout << "Lua error: " << lua_tostring(L, -1) << std::endl; - //} - - //entities.each([&](Entity, Position& p){std::cout << p.x << "," << p.y << std::endl;}); - - //lua_close(L); -} -*/ diff --git a/src/script.hpp b/src/script.hpp index e9373c0..f6111d0 100644 --- a/src/script.hpp +++ b/src/script.hpp @@ -21,22 +21,18 @@ #include #include -#include -#include