mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-16 15:17:13 +02:00
Code cleanup.
Get rid of ReleaseGently.
This commit is contained in:
@ -54,7 +54,7 @@ public:
|
||||
/// \param v VM that the array will exist in
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
ArrayBase(HSQUIRRELVM v = DefaultVM::Get()) : Object(v, true) {
|
||||
ArrayBase(HSQUIRRELVM v = SqVM()) : Object(v, true) {
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -100,7 +100,7 @@ public:
|
||||
/// \param v Squirrel VM that contains the Squirrel object given
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
ArrayBase(HSQOBJECT o, HSQUIRRELVM v = DefaultVM::Get()) : Object(o, v) {
|
||||
ArrayBase(HSQOBJECT o, HSQUIRRELVM v = SqVM()) : Object(o, v) {
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -625,7 +625,7 @@ public:
|
||||
/// \param v Squirrel VM that contains the Squirrel object given
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Array(HSQOBJECT o, HSQUIRRELVM v = DefaultVM::Get()) : ArrayBase(o, v) {
|
||||
Array(HSQOBJECT o, HSQUIRRELVM v = SqVM()) : ArrayBase(o, v) {
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -204,7 +204,7 @@ public:
|
||||
/// \param createTable Whether the underlying table that values are bound to is created by the constructor
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Enumeration(HSQUIRRELVM v = DefaultVM::Get(), bool createTable = true) : Object(v, false) {
|
||||
Enumeration(HSQUIRRELVM v = SqVM(), bool createTable = true) : Object(v, false) {
|
||||
if(createTable) {
|
||||
sq_newtable(vm);
|
||||
sq_getstackobj(vm,-1,&obj);
|
||||
@ -301,7 +301,7 @@ public:
|
||||
/// \param v VM to get the ConstTable for
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
ConstTable(HSQUIRRELVM v = DefaultVM::Get()) : Enumeration(v, false) {
|
||||
ConstTable(HSQUIRRELVM v = SqVM()) : Enumeration(v, false) {
|
||||
sq_pushconsttable(vm);
|
||||
sq_getstackobj(vm,-1, &obj);
|
||||
sq_pop(v,1); // No addref needed, since the consttable is always around
|
||||
|
@ -56,8 +56,8 @@ struct Function {
|
||||
}
|
||||
// Copy constructor
|
||||
Function(const Function& sf) : mEnv(sf.mEnv), mObj(sf.mObj) {
|
||||
sq_addref(DefaultVM::Get_(), &mEnv);
|
||||
sq_addref(DefaultVM::Get_(), &mObj);
|
||||
sq_addref(SqVM(), &mEnv);
|
||||
sq_addref(SqVM(), &mObj);
|
||||
}
|
||||
// Move constructor
|
||||
Function(Function&& sf) noexcept : mEnv(sf.mEnv), mObj(sf.mObj) {
|
||||
@ -66,15 +66,15 @@ struct Function {
|
||||
}
|
||||
// Constructs a Function from a slot in an Object
|
||||
Function(const Object& e, const SQChar* slot) : mEnv(e.GetObj()) {
|
||||
sq_addref(DefaultVM::Get_(), &mEnv);
|
||||
sq_addref(SqVM(), &mEnv);
|
||||
Object so = e.GetSlot(slot);
|
||||
mObj = so.GetObj();
|
||||
sq_addref(DefaultVM::Get_(), &mObj);
|
||||
sq_addref(SqVM(), &mObj);
|
||||
#if !defined (SCRAT_NO_ERROR_CHECKING)
|
||||
SQObjectType value_type = so.GetType();
|
||||
if (value_type != OT_CLOSURE && value_type != OT_NATIVECLOSURE) {
|
||||
// Note that classes can also be considered functions in Squirrel
|
||||
SQTHROW(DefaultVM::Get_(), _SC("function not found in slot"));
|
||||
SQTHROW(SqVM(), _SC("function not found in slot"));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -115,8 +115,8 @@ struct Function {
|
||||
mEnv = sf.mEnv;
|
||||
mObj = sf.mObj;
|
||||
if (!sf.IsNull()) {
|
||||
sq_addref(DefaultVM::Get_(), &mEnv);
|
||||
sq_addref(DefaultVM::Get_(), &mObj);
|
||||
sq_addref(SqVM(), &mEnv);
|
||||
sq_addref(SqVM(), &mObj);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@ -151,27 +151,16 @@ struct Function {
|
||||
}
|
||||
// Gets the Squirrel VM for this Function
|
||||
HSQUIRRELVM GetVM() const {
|
||||
return DefaultVM::Get_();
|
||||
return SqVM();
|
||||
}
|
||||
// Sets the Function to null (removing its references to underlying Squirrel objects)
|
||||
void Release() {
|
||||
if(!IsNull()) {
|
||||
sq_release(DefaultVM::Get_(), &mEnv);
|
||||
sq_release(DefaultVM::Get_(), &mObj);
|
||||
if(!sq_isnull(mEnv)) {
|
||||
sq_release(SqVM(), &mEnv);
|
||||
sq_resetobject(&mEnv);
|
||||
sq_resetobject(&mObj);
|
||||
}
|
||||
}
|
||||
// Sets the Function to null (removing its references to underlying Squirrel objects)
|
||||
// This doesn't call release if the reference count is 1.
|
||||
// Workaround for some weird squirrel behavior that generates an assert in debug mode.
|
||||
void ReleaseGently() {
|
||||
if(!IsNull()) {
|
||||
sq_release(DefaultVM::Get_(), &mEnv);
|
||||
if (sq_getrefcount(DefaultVM::Get_(), &mObj) > 1) {
|
||||
sq_release(DefaultVM::Get_(), &mObj);
|
||||
}
|
||||
sq_resetobject(&mEnv);
|
||||
if(!sq_isnull(mObj)) {
|
||||
sq_release(SqVM(), &mObj);
|
||||
sq_resetobject(&mObj);
|
||||
}
|
||||
}
|
||||
@ -231,7 +220,7 @@ struct Function {
|
||||
// Runs the Function and returns its value as a SharedPtr
|
||||
template<class R, class... Args> SharedPtr<R> Evaluate(Args &&... args) {
|
||||
static constexpr unsigned ARGC = sizeof...(Args) + 1; // + environment
|
||||
HSQUIRRELVM vm = DefaultVM::Get_();
|
||||
HSQUIRRELVM vm = SqVM();
|
||||
const SQInteger top = sq_gettop(vm);
|
||||
// Push the environment followed by the function
|
||||
sq_pushobject(vm, mObj);
|
||||
@ -271,7 +260,7 @@ struct Function {
|
||||
template< class... Args >
|
||||
void Execute(Args &&... args) {
|
||||
static constexpr unsigned ARGC = sizeof...(Args) + 1; // + environment
|
||||
HSQUIRRELVM vm = DefaultVM::Get_();
|
||||
HSQUIRRELVM vm = SqVM();
|
||||
const SQInteger top = sq_gettop(vm);
|
||||
// Push the environment followed by the function
|
||||
sq_pushobject(vm, mObj);
|
||||
|
@ -122,7 +122,7 @@ public:
|
||||
/// \param v VM that the object will exist in
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Object(HSQOBJECT o, HSQUIRRELVM v = DefaultVM::Get()) : vm(v), obj(o), release(!sq_isnull(o)) {
|
||||
Object(HSQOBJECT o, HSQUIRRELVM v = SqVM()) : vm(v), obj(o), release(!sq_isnull(o)) {
|
||||
sq_addref(vm, &obj);
|
||||
}
|
||||
|
||||
@ -133,7 +133,7 @@ public:
|
||||
/// \param v VM that the object will exist in
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Object(SQInteger i, HSQUIRRELVM v = DefaultVM::Get()) : vm(v), release(true) {
|
||||
Object(SQInteger i, HSQUIRRELVM v = SqVM()) : vm(v), release(true) {
|
||||
if (SQ_FAILED(sq_getstackobj(vm, i, &obj))) {
|
||||
sq_resetobject(&obj);
|
||||
release = false;
|
||||
@ -152,7 +152,7 @@ public:
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
Object(T* instance, HSQUIRRELVM v = DefaultVM::Get()) : vm(v), release(true) {
|
||||
Object(T* instance, HSQUIRRELVM v = SqVM()) : vm(v), release(true) {
|
||||
// Preserve the stack state
|
||||
const StackGuard sg(vm);
|
||||
// Push the instance on the stack
|
||||
@ -794,9 +794,9 @@ template < typename T > Object MakeObject(const T & v)
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Transform the specified value into a script object
|
||||
PushVar< T >(DefaultVM::Get(), v);
|
||||
PushVar< T >(SqVM(), v);
|
||||
// Get the object from the stack and return it
|
||||
return Var< Object >(DefaultVM::Get(), -1).value;
|
||||
return Var< Object >(SqVM(), -1).value;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -838,7 +838,7 @@ struct LightObj {
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
LightObj(const LightObj& so) : mObj(so.mObj) {
|
||||
sq_addref(DefaultVM::Get(), &mObj);
|
||||
sq_addref(SqVM(), &mObj);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -858,7 +858,7 @@ struct LightObj {
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
LightObj(HSQOBJECT o) : mObj(o) {
|
||||
sq_addref(DefaultVM::Get(), &mObj);
|
||||
sq_addref(SqVM(), &mObj);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -868,7 +868,7 @@ struct LightObj {
|
||||
/// \param v VM that the object will exist in
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
LightObj(SQInteger i, HSQUIRRELVM v = DefaultVM::Get()) {
|
||||
LightObj(SQInteger i, HSQUIRRELVM v = SqVM()) {
|
||||
if (SQ_FAILED(sq_getstackobj(v, i, &mObj))) {
|
||||
sq_resetobject(&mObj);
|
||||
} else {
|
||||
@ -884,7 +884,7 @@ struct LightObj {
|
||||
/// \param v VM that the object will exist in
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
LightObj(const SQChar * s, SQInteger l, HSQUIRRELVM v = DefaultVM::Get()) {
|
||||
LightObj(const SQChar * s, SQInteger l, HSQUIRRELVM v = SqVM()) {
|
||||
sq_pushstring(v, s, l);
|
||||
if (SQ_FAILED(sq_getstackobj(v, -1, &mObj))) {
|
||||
sq_resetobject(&mObj);
|
||||
@ -916,7 +916,7 @@ struct LightObj {
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
LightObj(T* instance, HSQUIRRELVM v = DefaultVM::Get()) {
|
||||
LightObj(T* instance, HSQUIRRELVM v = SqVM()) {
|
||||
// Preserve the stack state
|
||||
const StackGuard sg(v);
|
||||
// Push the instance on the stack
|
||||
@ -967,7 +967,7 @@ struct LightObj {
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template<class T>
|
||||
LightObj(DeleteGuard<T> guard, HSQUIRRELVM v = DefaultVM::Get()) : LightObj(guard.Get(), v) {
|
||||
LightObj(DeleteGuard<T> guard, HSQUIRRELVM v = SqVM()) : LightObj(guard.Get(), v) {
|
||||
guard.Release();
|
||||
}
|
||||
|
||||
@ -991,7 +991,7 @@ struct LightObj {
|
||||
if (this != &so) {
|
||||
Release();
|
||||
mObj = so.mObj;
|
||||
sq_addref(DefaultVM::Get(), &mObj);
|
||||
sq_addref(SqVM(), &mObj);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@ -1084,7 +1084,7 @@ struct LightObj {
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
inline HSQUIRRELVM GetVM() const {
|
||||
return DefaultVM::Get();
|
||||
return SqVM();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -1094,7 +1094,7 @@ struct LightObj {
|
||||
void Release() {
|
||||
// Should we release any object?
|
||||
if (!sq_isnull(mObj)) {
|
||||
sq_release(DefaultVM::Get(), &mObj);
|
||||
sq_release(SqVM(), &mObj);
|
||||
sq_resetobject(&mObj);
|
||||
}
|
||||
}
|
||||
@ -1107,7 +1107,7 @@ struct LightObj {
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
void Bind(const SQChar* name, LightObj& obj) {
|
||||
HSQUIRRELVM vm = DefaultVM::Get();
|
||||
HSQUIRRELVM vm = SqVM();
|
||||
sq_pushobject(vm, mObj);
|
||||
sq_pushstring(vm, name, -1);
|
||||
sq_pushobject(vm, obj.mObj);
|
||||
@ -1128,7 +1128,7 @@ struct LightObj {
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template <class T>
|
||||
T Cast() const {
|
||||
HSQUIRRELVM vm = DefaultVM::Get();
|
||||
HSQUIRRELVM vm = SqVM();
|
||||
sq_pushobject(vm, mObj);
|
||||
Var<T> v(vm, -1);
|
||||
sq_pop(vm, 1);
|
||||
@ -1148,7 +1148,7 @@ struct LightObj {
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template <class T>
|
||||
T * CastI() const {
|
||||
HSQUIRRELVM vm = DefaultVM::Get();
|
||||
HSQUIRRELVM vm = SqVM();
|
||||
sq_pushobject(vm, mObj);
|
||||
Var<T *> v(vm, -1);
|
||||
sq_pop(vm, 1);
|
||||
@ -1244,9 +1244,9 @@ template < typename T > LightObj MakeLightObj(const T & v)
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Transform the specified value into a script object
|
||||
PushVar< T >(DefaultVM::Get(), v);
|
||||
PushVar< T >(SqVM(), v);
|
||||
// Get the object from the stack and return it
|
||||
return Var< LightObj >(DefaultVM::Get(), -1).value;
|
||||
return Var< LightObj >(SqVM(), -1).value;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -53,7 +53,7 @@ public:
|
||||
/// \param v VM that the Script will be associated with
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Script(HSQUIRRELVM v = DefaultVM::Get()) : Object(v, true) {
|
||||
Script(HSQUIRRELVM v = SqVM()) : Object(v, true) {
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -54,7 +54,7 @@ public:
|
||||
/// \param v VM that the table will exist in
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
TableBase(HSQUIRRELVM v = DefaultVM::Get()) : Object(v, true) {
|
||||
TableBase(HSQUIRRELVM v = SqVM()) : Object(v, true) {
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -100,7 +100,7 @@ public:
|
||||
/// \param v Squirrel VM that contains the Squirrel object given
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
TableBase(HSQOBJECT o, HSQUIRRELVM v = DefaultVM::Get()) : Object(o, v) {
|
||||
TableBase(HSQOBJECT o, HSQUIRRELVM v = SqVM()) : Object(o, v) {
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -576,7 +576,7 @@ public:
|
||||
/// \param v Squirrel VM that contains the Squirrel object given
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
Table(HSQOBJECT o, HSQUIRRELVM v = DefaultVM::Get()) : TableBase(o, v) {
|
||||
Table(HSQOBJECT o, HSQUIRRELVM v = SqVM()) : TableBase(o, v) {
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -652,7 +652,7 @@ public:
|
||||
/// \param v VM to get the RootTable for
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
RootTable(HSQUIRRELVM v = DefaultVM::Get()) : TableBase(v) {
|
||||
RootTable(HSQUIRRELVM v = SqVM()) : TableBase(v) {
|
||||
sq_pushroottable(vm);
|
||||
sq_getstackobj(vm,-1,&obj);
|
||||
sq_addref(vm, &obj);
|
||||
@ -673,7 +673,7 @@ public:
|
||||
/// \param v VM to get the RegistryTable for
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
RegistryTable(HSQUIRRELVM v = DefaultVM::Get()) : TableBase(v) {
|
||||
RegistryTable(HSQUIRRELVM v = SqVM()) : TableBase(v) {
|
||||
sq_pushregistrytable(v);
|
||||
sq_getstackobj(vm,-1,&obj);
|
||||
sq_addref(vm, &obj);
|
||||
|
@ -233,8 +233,8 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/// Alias for DefaultVM::Get()
|
||||
inline HSQUIRRELVM SqVM() noexcept { return DefaultVM::Get(); }
|
||||
/// Alias for SqVM()
|
||||
inline HSQUIRRELVM SqVM() noexcept { return DefaultVM::Get_(); }
|
||||
|
||||
#if !defined (SCRAT_NO_ERROR_CHECKING) && !defined (SCRAT_USE_EXCEPTIONS)
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -1631,7 +1631,7 @@ struct StackGuard
|
||||
/// Default constructor.
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
StackGuard()
|
||||
: m_VM(DefaultVM::Get()), m_Top(sq_gettop(m_VM))
|
||||
: m_VM(SqVM()), m_Top(sq_gettop(m_VM))
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
@ -1848,7 +1848,7 @@ struct StackStrF
|
||||
{
|
||||
if (!sq_isnull(mObj))
|
||||
{
|
||||
sq_release(mVM ? mVM : DefaultVM::Get(), &mObj);
|
||||
sq_release(mVM ? mVM : SqVM(), &mObj);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1867,7 +1867,7 @@ struct StackStrF
|
||||
// Release
|
||||
if (!sq_isnull(mObj))
|
||||
{
|
||||
sq_release(mVM ? mVM : DefaultVM::Get(), &mObj);
|
||||
sq_release(mVM ? mVM : SqVM(), &mObj);
|
||||
sq_resetobject(&mObj);
|
||||
}
|
||||
// Replicate
|
||||
@ -1895,7 +1895,7 @@ struct StackStrF
|
||||
{
|
||||
if (!sq_isnull(mObj))
|
||||
{
|
||||
sq_release(mVM ? mVM : DefaultVM::Get(), &mObj);
|
||||
sq_release(mVM ? mVM : SqVM(), &mObj);
|
||||
}
|
||||
mPtr = _SC("");
|
||||
mLen = 0;
|
||||
|
Reference in New Issue
Block a user