feat: added native manager impl

This commit is contained in:
2025-11-18 20:21:10 +01:00
parent 8fc83cde53
commit 989f7f4d73
2 changed files with 252 additions and 41 deletions

View File

@@ -22,10 +22,6 @@ namespace fxn
static void DispatchNative(fxn::NativeContext* context, NativeHash hash);
public:
void Initialize();
void Shutdown();
public:
const NativeHandler& GetNativeHandler(const NativeHash hash) const;
void RegisterNativeHandler(const NativeHash hash, const NativeHandler handler);
@@ -37,42 +33,5 @@ namespace fxn
public:
bool Invoke(fxn::NativeContext* context);
bool Schedule(fxn::NativeContext* context, bool waitForCompletion = true);
public:
template<typename R, typename... Args>
R Invoke(const NativeHash hash, Args&&... args)
{
fxn::NativeContext context(hash);
(context.PushArgument(std::forward<Args>(args)), ...);
if (!this->Invoke(&context))
{
throw std::runtime_error("Failed to invoke native with hash: " + std::to_string(hash));
}
if constexpr (!std::is_same_v<R, void>)
{
return context.GetResult<R>();
}
}
template<typename R, typename... Args>
R Schedule(const NativeHash hash, Args&&... args)
{
fxn::NativeContext context(hash);
(context.PushArgument(std::forward<Args>(args)), ...);
if (!this->Schedule(&context, true))
{
throw std::runtime_error("Failed to schedule native with hash: " + std::to_string(hash));
}
if constexpr (!std::is_same_v<R, void>)
{
return context.GetResult<R>();
}
}
};
}