/* * Copyright (C) 2019 Belle-Isle, Andrew * Author: Belle-Isle, Andrew * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef SCRIPT_NAMESPACE_HPP_ #define SCRIPT_NAMESPACE_HPP_ #include #include #include #include entityx::EventManager events; entityx::EntityManager manager(events); entityx::Entity e; namespace Script { sol::state lua; sol::table newPosition([[maybe_unused]]sol::table tab) { sol::table toRet = lua.create_table_with(); e.assign(4.5, 2.3).get(); toRet["Position"] = e.component().get(); return toRet; } void CreateNewState() { e = manager.create(); lua.open_libraries(sol::lib::base); //lua["q"] = Position(4.5, 3.4); lua.new_usertype("Position", sol::constructors(), "x", &Position::x, "y", &Position::y); auto gamespace = lua["game"].get_or_create(); gamespace.set_function("testfunc", newPosition); lua.script_file("Scripts/init.lua"); auto p = e.component().get(); std::cout << p->x << "," << p->y << std::endl; } } #endif//SCRIPT_NAMESPACE_HPP_