1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Update sqratObject.h

This commit is contained in:
Sandu Liviu Catalin 2021-04-10 17:19:12 +03:00
parent 34159d1662
commit c3a0d23a32

View File

@ -159,6 +159,31 @@ public:
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Constructs an Object from a C++ instance only if that instance exists. Otherwise, null is beings used.
///
/// \param instance Pointer to a C++ class instance that has been bound already
/// \param v VM that the object will exist in
///
/// \tparam T Type of instance
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<class T>
Object(T* instance, std::nullptr_t, HSQUIRRELVM vm = SqVM()) : mRelease(true) {
// Preserve the stack state
const StackGuard sg(vm);
// Push the instance on the stack
ClassType<T>::PushInstance(vm, instance, nullptr);
// Attempt to retrieve it
if (SQ_FAILED(sq_getstackobj(vm, -1, &mObj))) {
sq_resetobject(&mObj);
// nothing to release anymore
mRelease = false;
} else {
sq_addref(vm, &mObj);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Constructs an Object from a C++ type
///