/* * ===================================================================================== * * Filename: ScriptEngine.cpp * * Description: * * Created: 20/12/2018 00:42:55 * * Author: Quentin Bazin, * * ===================================================================================== */ #include "LuaCore.hpp" #include "LuaGUI.hpp" #include "LuaMod.hpp" #include "Registry.hpp" #include "ScriptEngine.hpp" #include "ServerPlayer.hpp" #include "ServerWorld.hpp" ScriptEngine *ScriptEngine::s_instance = nullptr; void ScriptEngine::init() { setInstance(this); initUsertypes(); // FIXME: Remove these lines when they're not needed anymore m_lua["registry"] = &Registry::getInstance(); // Note: To be safe, don't add sol::lib::io and provide a better way to load/save data // With a feature like this, it would be way easier to add io restrictions m_lua.open_libraries( sol::lib::base, sol::lib::math, sol::lib::table ); m_lua.safe_script_file("mods/test.lua"); } void ScriptEngine::initUsertypes() { m_lua.new_usertype("Registry", "get_recipe", &Registry::getRecipe ); m_lua.new_usertype("World", "get_block", &World::getBlock, "get_data", &World::getData, "set_data", &World::setData, "get_block_data", &World::getBlockData ); m_lua.new_usertype("Chunk", "get_block", &Chunk::getBlock, "get_data", &Chunk::getData, "get_block_data", &Chunk::getBlockData ); m_lua.new_usertype("BlockData", "inventory", &BlockData::inventory, "data", &BlockData::data ); m_lua.new_usertype("Player", "inventory", &Player::inventory ); m_lua.new_usertype("Inventory", "add_stack", &Inventory::addStack, "get_stack", &Inventory::getStack, "set_stack", &Inventory::setStack ); m_lua.new_usertype("Recipe", "type", &Recipe::type, "result", &Recipe::result ); m_lua.new_usertype("ItemStack", "amount", &ItemStack::amount, "item", &ItemStack::item ); m_lua.new_usertype("Item", "id", &Item::id, "name", &Item::name, "burn_time", &Item::burnTime ); m_lua.new_usertype("ivec3", "x", &glm::ivec3::x, "y", &glm::ivec3::y, "z", &glm::ivec3::z ); LuaCore::initUsertype(m_lua); LuaMod::initUsertype(m_lua); LuaGUI::initUsertype(m_lua); }