This commit is contained in:
2026-07-25 21:54:02 +02:00
parent c62daa9c1c
commit d9dfff3339
6 changed files with 113 additions and 32 deletions

View File

@@ -20,6 +20,8 @@ public:
void loadPlugins();
sol::state& getLua() { return m_lua; }
// @ai @note maybe we should rewrite it...
// problem that i dont know how to pass args in sol::function dynamically
// so i used ai
@@ -38,11 +40,29 @@ public:
std::cout << err.what() << std::endl;
}
}
}
}
template<typename... Args>
int emitCommands(std::string event, Args&&... args) {
auto it = m_luaCommands.find(event);
if (it == m_luaCommands.end()) return 1;
for (auto& callback : it->second) {
sol::protected_function_result result = callback(std::forward<Args>(args)...);
if (!result.valid()) {
sol::error err = result;
std::cout << err.what() << std::endl;
}
}
return 0;
}
Minecraft* getMinecraft() { return m_minecraft; }
private:
std::unordered_map<std::string, std::vector<sol::function>> m_callbacks;
std::unordered_map<std::string, std::vector<sol::function>> m_luaCommands;
LuaServer m_srv;
sol::state m_lua;