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

Update sqratLightObj.h

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

View File

@ -152,6 +152,29 @@ struct LightObj {
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Constructs a LightObj 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>
explicit LightObj(T* instance, std::nullptr_t, HSQUIRRELVM vm = SqVM()) {
// 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);
} else {
sq_addref(vm, &mObj);
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Constructs a LightObj from a C++ type
///