mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 08:47:17 +01:00
Update sqratObject.h
This commit is contained in:
parent
34159d1662
commit
c3a0d23a32
@ -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
|
/// Constructs an Object from a C++ type
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user