VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
HostCallback.hpp
Go to the documentation of this file.
1#pragma once
2
6#include <cstdint>
7#include <exception>
8
9namespace VoltMod::Internal
10{
11
12/** The C function the host calls for @p Member, with its owner as the context. Nothing may unwind
13 * into the host. */
14template <auto Member>
16
17template <class Owner, class Result, class... Args, Result (Owner::*Member)(Args...)>
19{
20 static Result Call(void* owner, Args... args) noexcept
21 {
22 try
23 {
24 return (static_cast<Owner*>(owner)->*Member)(args...);
25 }
26 catch (const std::exception& error)
27 {
28 Log::Error("Unhandled exception in a host event: {}", error.what());
29 return Result();
30 }
31 catch (...)
32 {
33 Log::Error("Unhandled non-standard exception in a host event.");
34 return Result();
35 }
36 }
37};
38
39/** Unsubscribes host event @p token when dropped; @p events must outlive it. */
44
45} // namespace VoltMod::Internal
Owns one registration and releases it on destruction.
Subscription HostSubscription(IPluginEvents &events, uint64_t token)
void Error(std::format_string< Args... > fmt, Args &&... args)
Definition Log.hpp:97
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::expected< T, Error > Result
Definition Result.hpp:64
static Result Call(void *owner, Args... args) noexcept