diff --git a/include/sqrat/sqratTypes.h b/include/sqrat/sqratTypes.h index f8456645..b3a09a21 100644 --- a/include/sqrat/sqratTypes.h +++ b/include/sqrat/sqratTypes.h @@ -1519,6 +1519,25 @@ struct ArgFwd { } }; +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +/// Used to wrap calling a static member function as a raw function by providing the actual instance before the VM. +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +template < class T, SQInteger (*Fn)(T &, HSQUIRRELVM) > inline SQInteger SqRawMemberFnWrap(HSQUIRRELVM vm) +{ + // The wrapped instance + T * inst = nullptr; + // Attempt to extract the argument values + try + { + inst = Var< T * >(vm, 1).value; + } + catch (const Sqrat::Exception & e) + { + return sq_throwerror(vm, e.what()); + } + // Forward the call (assume the instance is valid!) + return Fn(*inst, vm); +} }