mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-04 00:36:14 +00:00
start working on event handlers
This commit is contained in:
parent
5468e5c854
commit
6af471f025
@ -10,6 +10,7 @@
|
|||||||
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
#include <boost/date_time/posix_time/posix_time_duration.hpp>
|
||||||
#include <boost/thread/scoped_thread.hpp>
|
#include <boost/thread/scoped_thread.hpp>
|
||||||
#include <boost/thread/synchronized_value.hpp>
|
#include <boost/thread/synchronized_value.hpp>
|
||||||
|
#include <sol/forward.hpp>
|
||||||
#include <sol/variadic_args.hpp>
|
#include <sol/variadic_args.hpp>
|
||||||
#include <spdlog/logger.h>
|
#include <spdlog/logger.h>
|
||||||
|
|
||||||
@ -93,6 +94,11 @@ private:
|
|||||||
/// This asio context schedules all tasks. It's run in the m_thread thread.
|
/// This asio context schedules all tasks. It's run in the m_thread thread.
|
||||||
boost::asio::io_context m_io;
|
boost::asio::io_context m_io;
|
||||||
|
|
||||||
|
/// Event handlers which are legacy-style (by name)
|
||||||
|
HashMap<std::string, std::string> m_event_handlers_named {};
|
||||||
|
/// Event handlers which are functions (v4 style)
|
||||||
|
HashMap<std::string, sol::protected_function> m_event_handlers {};
|
||||||
|
|
||||||
/// Main (and usually only) lua state of this plugin.
|
/// Main (and usually only) lua state of this plugin.
|
||||||
/// ONLY access this from the m_thread thread.
|
/// ONLY access this from the m_thread thread.
|
||||||
sol::state m_state;
|
sol::state m_state;
|
||||||
|
@ -131,6 +131,9 @@ Error LuaPlugin::initialize_libraries() {
|
|||||||
glob["MP"]["GetPluginPath"] = [this] {
|
glob["MP"]["GetPluginPath"] = [this] {
|
||||||
return std::filesystem::absolute(m_path).string();
|
return std::filesystem::absolute(m_path).string();
|
||||||
};
|
};
|
||||||
|
glob["MP"]["RegisterEvent"] = [this] (const std::string& event_name, const std::string& handler) {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
glob["MP"]["ScheduleCallRepeat"] = [this](size_t ms, sol::function fn, sol::variadic_args args) {
|
glob["MP"]["ScheduleCallRepeat"] = [this](size_t ms, sol::function fn, sol::variadic_args args) {
|
||||||
return l_mp_schedule_call_repeat(ms, fn, args);
|
return l_mp_schedule_call_repeat(ms, fn, args);
|
||||||
|
@ -170,6 +170,11 @@ int BeamMPServerMain(MainArguments Arguments) {
|
|||||||
PluginManager PluginManager;
|
PluginManager PluginManager;
|
||||||
(void)PluginManager.add_plugin(Plugin::make_pointer<LuaPlugin>("Resources/Server/Test"));
|
(void)PluginManager.add_plugin(Plugin::make_pointer<LuaPlugin>("Resources/Server/Test"));
|
||||||
|
|
||||||
|
PluginManager.trigger_event("onInit", std::make_shared<Value>(HashMap<std::string, Value> {
|
||||||
|
{ "big", "balls" },
|
||||||
|
{ "longer", "falls" },
|
||||||
|
}));
|
||||||
|
|
||||||
if (Application::Settings.HTTPServerEnabled) {
|
if (Application::Settings.HTTPServerEnabled) {
|
||||||
Http::Server::THttpServerInstance HttpServerInstance {};
|
Http::Server::THttpServerInstance HttpServerInstance {};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user