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

Update sqratLightObj.h

In place construction.
This commit is contained in:
Sandu Liviu Catalin 2021-01-30 19:39:56 +02:00
parent 1c84c7f35a
commit 444b0120ea

View File

@ -180,6 +180,30 @@ struct LightObj {
instance.Release(); instance.Release();
} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Constructs a LightObj from a C++ type
///
/// \param t Identity of the type to create.
/// \param v VM that the object will exist in.
/// \param a Arguments to forward to the type constructor.
///
/// \tparam T Type of instance
///
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template<class T>
LightObj(SqInPlace SQ_UNUSED_ARG(t), HSQUIRRELVM vm, T value) {
// Push the value on the stack
Var<T>::PushInstance(vm, std::forward< T >(value));
// Attempt to retrieve it
if (SQ_FAILED(sq_getstackobj(vm, -1, &mObj))) {
sq_resetobject(&mObj);
} else {
sq_addref(vm, &mObj);
}
// Pop the value from the stack
sq_poptop(vm);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Constructs an LightObj from a C++ instance wrapped inside a DeleteGuard /// Constructs an LightObj from a C++ instance wrapped inside a DeleteGuard
/// ///