Skip to content

Instantly share code, notes, and snippets.

@ThePhD

ThePhD/stuff.cpp Secret

Last active December 29, 2015 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThePhD/a5f814afe71ccc507ea7 to your computer and use it in GitHub Desktop.
Save ThePhD/a5f814afe71ccc507ea7 to your computer and use it in GitHub Desktop.
Arf.
template <typename R, typename... Args>
int RegisterGlobalFunction(R(*fptr)(Args...), std::string name, CallConv callconv = callConv<R(*)(Args...)>(nullptr))
{
int r = engine->RegisterGlobalFunction(decompose(name, fptr).c_str(), AS_::asFunctionPtr(fptr), (AS_::asECallConvTypes)callconv);
ASThrow(r);
return r;
}
// Const
template <typename R, typename T, typename... Args>
int RegisterGlobalFunction(R(T::*mfptr)(Args...)const, std::string name, T* instance = nullptr, CallConv callconv = CallConv::Thiscall_global)
{
if (instance == nullptr)
{ //static member function..I hope
callconv = CallConv::Cdecl;
}
int r = engine->RegisterGlobalFunction(decompose(name, mfptr).c_str(), AS_::asSMethodPtr<sizeof(void (T::*)())>::Convert(mfptr), (AS_::asECallConvTypes)callconv, instance);
ASThrow(r);
return r;
}
// Non Const
template <typename R, typename T, typename... Args>
int RegisterGlobalFunction(R(T::*mfptr)(Args...), std::string name, T* instance = nullptr, CallConv callconv = CallConv::Thiscall_global)
{
if (instance == nullptr)
{ //static member function..I hope
callconv = CallConv::Cdecl;
}
int r = engine->RegisterGlobalFunction(decompose(name, mfptr).c_str(), AS_::asSMethodPtr<sizeof(void (T::*)())>::Convert(mfptr), (AS_::asECallConvTypes)callconv, instance);
ASThrow(r);
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment