This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
Files
YimMenu/src/lua/bindings/event.hpp
maybegreat48 70efa40afe Lua Scripting (#1334)
Closes #83
Fixes #1309
Fixes #1287
Fixes #1129 (actually fixed now)
2023-06-06 09:40:40 +02:00

23 lines
660 B
C++

#pragma once
#include "fiber_pool.hpp"
#include "lua/lua_module.hpp"
#include "script_mgr.hpp"
namespace lua::event
{
static void register_handler(const std::string& name, sol::function func, sol::this_state state)
{
auto module = sol::state_view(state)["!this"].get<big::lua_module*>();
auto hash = rage::joaat(name);
module->m_event_callbacks.emplace(hash, std::vector<sol::function>());
module->m_event_callbacks[hash].push_back(func);
}
static void bind(sol::state& state)
{
auto ns = state["event"].get_or_create<sol::table>();
ns["register_handler"] = register_handler;
// TODO: triggering events through script?
}
}