From f32a7f59f0461a39ae166f236797eb70906eded9 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Mon, 19 Aug 2019 22:28:47 +0300 Subject: [PATCH] Update sqratTypes.h Add a utility wrapper for member functions with raw bindings. --- include/sqrat/sqratTypes.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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); +} }