57 lines
1.3 KiB
C++
57 lines
1.3 KiB
C++
/*
|
|
* =====================================================================================
|
|
*
|
|
* Filename: ScriptEngine.cpp
|
|
*
|
|
* Description:
|
|
*
|
|
* Created: 20/12/2018 00:42:55
|
|
*
|
|
* Author: Quentin Bazin, <quent42340@gmail.com>
|
|
*
|
|
* =====================================================================================
|
|
*/
|
|
#include "LuaMod.hpp"
|
|
#include "Player.hpp"
|
|
#include "Registry.hpp"
|
|
#include "ScriptEngine.hpp"
|
|
|
|
#include "CraftingRecipe.hpp"
|
|
#include "SmeltingRecipe.hpp"
|
|
|
|
#include "BlockFurnace.hpp"
|
|
#include "BlockWater.hpp"
|
|
#include "BlockWorkbench.hpp"
|
|
|
|
ScriptEngine *ScriptEngine::s_instance = nullptr;
|
|
|
|
void ScriptEngine::init() {
|
|
setInstance(this);
|
|
|
|
initUsertypes();
|
|
|
|
m_lua["registry"] = &Registry::getInstance();
|
|
|
|
m_lua.open_libraries(sol::lib::base);
|
|
m_lua.safe_script_file("mods/test.lua");
|
|
}
|
|
|
|
void ScriptEngine::initUsertypes() {
|
|
m_lua.new_usertype<Player>("Player",
|
|
"inventory", &Player::inventory);
|
|
|
|
m_lua.new_usertype<Inventory>("Inventory",
|
|
"add_stack", &Inventory::addStack
|
|
);
|
|
|
|
m_lua.new_usertype<LuaMod>("LuaMod",
|
|
sol::constructors<LuaMod(std::string)>(),
|
|
"id", &LuaMod::id,
|
|
"block", &LuaMod::registerBlock,
|
|
"item", &LuaMod::registerItem,
|
|
"crafting_recipe", &LuaMod::registerCraftingRecipe,
|
|
"smelting_recipe", &LuaMod::registerSmeltingRecipe
|
|
);
|
|
}
|
|
|