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

Code cleanup.

Get rid of ReleaseGently.
This commit is contained in:
Sandu Liviu Catalin 2020-04-27 13:10:54 +03:00
parent 48005a98f0
commit 22a17fe3c4
28 changed files with 212 additions and 223 deletions

View File

@ -647,11 +647,11 @@ String SqTypeName(HSQUIRRELVM vm, SQInteger idx)
Object BufferToStrObj(const Buffer & b)
{
// Obtain the initial stack size
const StackGuard sg(DefaultVM::Get());
const StackGuard sg(SqVM());
// Push the string onto the stack
sq_pushstring(DefaultVM::Get(), b.Data(), b.Position());
sq_pushstring(SqVM(), b.Data(), b.Position());
// Obtain the object from the stack and return it
return Var< Object >(DefaultVM::Get(), -1).value;
return Var< Object >(SqVM(), -1).value;
}
// --------------------------------------------------------------------------------------------
@ -663,11 +663,11 @@ Object BufferToStrObj(const Buffer & b, Uint32 size)
STHROWF("The specified buffer size is out of range: %u >= %u", size, b.Capacity());
}
// Obtain the initial stack size
const StackGuard sg(DefaultVM::Get());
const StackGuard sg(SqVM());
// Push the string onto the stack
sq_pushstring(DefaultVM::Get(), b.Data(), size);
sq_pushstring(SqVM(), b.Data(), size);
// Obtain the object from the stack and return it
return Var< Object >(DefaultVM::Get(), -1).value;
return Var< Object >(SqVM(), -1).value;
}
// ------------------------------------------------------------------------------------------------

View File

@ -492,7 +492,7 @@ void Core::Terminate(bool shutdown)
NullTable().Release();
NullObject().Release();
NullLightObj().Release();
NullFunction().ReleaseGently();
NullFunction().Release();
// Release null entity instances
m_NullBlip.Release();
m_NullCheckpoint.Release();

View File

@ -1835,11 +1835,11 @@ void Core::EmitClientScriptData(Int32 player_id, const uint8_t * data, size_t si
// Create a protected instance of a buffer wrapper
DeleteGuard< SqBuffer > ad(new SqBuffer(std::move(b)));
// Transform the pointer into a script object
PushVar< SqBuffer * >(DefaultVM::Get(), ad.Get());
PushVar< SqBuffer * >(SqVM(), ad.Get());
// The script took over the instance now
ad.Release();
// Get the object from the stack and store it
o = Var< LightObj >(DefaultVM::Get(), -1).value;
o = Var< LightObj >(SqVM(), -1).value;
}
catch (const std::exception & e)
{

View File

@ -382,11 +382,11 @@ void Core::BlipInst::InitEvents()
return;
}
// Create a new table on the stack
sq_newtableex(DefaultVM::Get(), 4);
sq_newtableex(SqVM(), 4);
// Grab the table object from the stack
mEvents = LightObj(-1, DefaultVM::Get());
mEvents = LightObj(-1, SqVM());
// Pop the table object from the stack
sq_pop(DefaultVM::Get(), 1);
sq_pop(SqVM(), 1);
// Proceed to initializing the events
InitSignalPair(mOnDestroyed, mEvents, "Destroyed");
InitSignalPair(mOnCustom, mEvents, "Custom");
@ -409,11 +409,11 @@ void Core::CheckpointInst::InitEvents()
return;
}
// Create a new table on the stack
sq_newtableex(DefaultVM::Get(), 8);
sq_newtableex(SqVM(), 8);
// Grab the table object from the stack
mEvents = LightObj(-1, DefaultVM::Get());
mEvents = LightObj(-1, SqVM());
// Pop the table object from the stack
sq_pop(DefaultVM::Get(), 1);
sq_pop(SqVM(), 1);
// Proceed to initializing the events
InitSignalPair(mOnDestroyed, mEvents, "Destroyed");
InitSignalPair(mOnCustom, mEvents, "Custom");
@ -450,11 +450,11 @@ void Core::KeybindInst::InitEvents()
return;
}
// Create a new table on the stack
sq_newtableex(DefaultVM::Get(), 8);
sq_newtableex(SqVM(), 8);
// Grab the table object from the stack
mEvents = LightObj(-1, DefaultVM::Get());
mEvents = LightObj(-1, SqVM());
// Pop the table object from the stack
sq_pop(DefaultVM::Get(), 1);
sq_pop(SqVM(), 1);
// Proceed to initializing the events
InitSignalPair(mOnDestroyed, mEvents, "Destroyed");
InitSignalPair(mOnCustom, mEvents, "Custom");
@ -481,11 +481,11 @@ void Core::ObjectInst::InitEvents()
return;
}
// Create a new table on the stack
sq_newtableex(DefaultVM::Get(), 12);
sq_newtableex(SqVM(), 12);
// Grab the table object from the stack
mEvents = LightObj(-1, DefaultVM::Get());
mEvents = LightObj(-1, SqVM());
// Pop the table object from the stack
sq_pop(DefaultVM::Get(), 1);
sq_pop(SqVM(), 1);
// Proceed to initializing the events
InitSignalPair(mOnDestroyed, mEvents, "Destroyed");
InitSignalPair(mOnCustom, mEvents, "Custom");
@ -524,11 +524,11 @@ void Core::PickupInst::InitEvents()
return;
}
// Create a new table on the stack
sq_newtableex(DefaultVM::Get(), 16);
sq_newtableex(SqVM(), 16);
// Grab the table object from the stack
mEvents = LightObj(-1, DefaultVM::Get());
mEvents = LightObj(-1, SqVM());
// Pop the table object from the stack
sq_pop(DefaultVM::Get(), 1);
sq_pop(SqVM(), 1);
// Proceed to initializing the events
InitSignalPair(mOnDestroyed, mEvents, "Destroyed");
InitSignalPair(mOnCustom, mEvents, "Custom");
@ -573,11 +573,11 @@ void Core::PlayerInst::InitEvents()
return;
}
// Create a new table on the stack
sq_newtableex(DefaultVM::Get(), 86);
sq_newtableex(SqVM(), 86);
// Grab the table object from the stack
mEvents = LightObj(-1, DefaultVM::Get());
mEvents = LightObj(-1, SqVM());
// Pop the table object from the stack
sq_pop(DefaultVM::Get(), 1);
sq_pop(SqVM(), 1);
// Proceed to initializing the events
InitSignalPair(mOnDestroyed, mEvents, "Destroyed");
InitSignalPair(mOnCustom, mEvents, "Custom");
@ -758,11 +758,11 @@ void Core::VehicleInst::InitEvents()
return;
}
// Create a new table on the stack
sq_newtableex(DefaultVM::Get(), 32);
sq_newtableex(SqVM(), 32);
// Grab the table object from the stack
mEvents = LightObj(-1, DefaultVM::Get());
mEvents = LightObj(-1, SqVM());
// Pop the table object from the stack
sq_pop(DefaultVM::Get(), 1);
sq_pop(SqVM(), 1);
// Proceed to initializing the events
InitSignalPair(mOnDestroyed, mEvents, "Destroyed");
InitSignalPair(mOnCustom, mEvents, "Custom");

View File

@ -47,11 +47,11 @@ void Core::InitEvents()
return;
}
// Create a new table on the stack
sq_newtableex(DefaultVM::Get(), 128);
sq_newtableex(SqVM(), 128);
// Grab the table object from the stack
m_Events = LightObj(-1, DefaultVM::Get());
m_Events = LightObj(-1, SqVM());
// Pop the table object from the stack
sq_pop(DefaultVM::Get(), 1);
sq_pop(SqVM(), 1);
// Proceed to initializing the events
InitSignalPair(mOnCustomEvent, m_Events, "CustomEvent");
InitSignalPair(mOnBlipCreated, m_Events, "BlipCreated");

View File

@ -206,11 +206,11 @@ Object IniDocument::SaveData(bool signature)
STHROWF("Unable to save INI document");
}
// Obtain the initial stack size
const StackGuard sg(DefaultVM::Get());
const StackGuard sg(SqVM());
// Transform it into a script object
sq_pushstring(DefaultVM::Get(), source.c_str(), source.size());
sq_pushstring(SqVM(), source.c_str(), source.size());
// Get the object from the stack and return it
return Var< Object >(DefaultVM::Get(), -1).value;
return Var< Object >(SqVM(), -1).value;
}
// ------------------------------------------------------------------------------------------------

View File

@ -321,7 +321,7 @@ LightObj GetEntryAsString(const MMDB_entry_data_s & ed)
// Obtain the initial stack size
const StackGuard sg;
// The default vm
HSQUIRRELVM vm = DefaultVM::Get();
HSQUIRRELVM vm = SqVM();
// Identify the type of entry data
switch (ed.type)
{

View File

@ -1551,7 +1551,7 @@ void Account::SetSSL(CSStr key, CSStr cert, CSStr ca, CSStr ca_path, CSStr ciphe
Table Account::GetOptionsTable() const
{
// Allocate an empty table
Table tbl(DefaultVM::Get(), m_Options.size());
Table tbl(SqVM(), m_Options.size());
// Insert every option into the table
for (const auto & opt : m_Options)
{
@ -2431,9 +2431,9 @@ Object Field::GetString() const
// Obtain the initial stack size
const StackGuard sg;
// Retrieve the value directly from the row and push it on the stack
sq_pushstring(DefaultVM::Get(), m_Handle->mRow[m_Index], m_Handle->mLengths[m_Index]);
sq_pushstring(SqVM(), m_Handle->mRow[m_Index], m_Handle->mLengths[m_Index]);
// Obtain the object from the stack
Object stro(-1, DefaultVM::Get());
Object stro(-1, SqVM());
// Restore the stack
sg.Restore();
// Return it the string object
@ -2612,10 +2612,10 @@ Array ResultSet::GetFieldNames() const
// Is there even something to process?
if (!fcount || !fields)
{
return Array(DefaultVM::Get(), 0);
return Array(SqVM(), 0);
}
// Allocate an array with the same amount of elements as the number of fields
Array arr(DefaultVM::Get(), fcount);
Array arr(SqVM(), fcount);
// Iterate over all the available fields and insert them into the created array
for (SQInteger n = 0; n < fcount; ++n)
{
@ -2634,12 +2634,12 @@ Array ResultSet::GetFieldsArray() const
// Is there even something to process?
if (!fcount)
{
return Array(DefaultVM::Get(), 0);
return Array(SqVM(), 0);
}
// Create a field instance to insert as copy
Field field(m_Handle);
// Allocate an array with the same amount of elements as the number of fields
Array arr(DefaultVM::Get(), fcount);
Array arr(SqVM(), fcount);
// Iterate over all the available fields and insert them into the created array
for (SQInteger n = 0; n < fcount; ++n)
{
@ -2659,12 +2659,12 @@ Array ResultSet::FetchFieldsArray(Array & fields) const
// Is there even something to process?
if (!m_Handle->mFieldCount || fields.Length() == 0)
{
return Array(DefaultVM::Get(), 0);
return Array(SqVM(), 0);
}
// Create a field instance to insert as copy
Field field(m_Handle);
// Allocate an array with the same amount of elements as the number of fields
Array arr(DefaultVM::Get(), fields.Length());
Array arr(SqVM(), fields.Length());
// Iterate the specified fields array
fields.Foreach([&field, &arr](HSQUIRRELVM vm, SQInteger i) -> SQRESULT {
// Update the field index
@ -2694,7 +2694,7 @@ Table ResultSet::GetFieldsTable() const
// Create a field instance to insert as copy
Field field(m_Handle);
// Allocate a table to be populated with field instances
Table tbl(DefaultVM::Get(), fcount);
Table tbl(SqVM(), fcount);
// Iterate over all the available fields and insert them into the created table
for (SQInteger n = 0; n < fcount; ++n)
{
@ -2719,7 +2719,7 @@ Table ResultSet::FetchFieldsTable(Array & fields) const
// Create a field instance to insert as copy
Field field(m_Handle);
// Allocate a table to be populated with field instances
Table tbl(DefaultVM::Get(), fields.Length());
Table tbl(SqVM(), fields.Length());
// Grab the array with field instances
const ResHnd::FieldType * pfields = m_Handle->mFields;
// Iterate the specified fields array

View File

@ -1437,9 +1437,9 @@ void SQLiteParameter::SetValue(const Object & value)
// Remember the current stack size
const StackGuard sg;
// Push the object onto the stack
Var< Object >::push(DefaultVM::Get(), value);
Var< Object >::push(SqVM(), value);
// Pop the object from the stack as a string
const Var< CSStr > str(DefaultVM::Get(), -1);
const Var< CSStr > str(SqVM(), -1);
// Attempt to bind the specified value
SetStringRaw(str.value, ConvTo< SQInteger >::From(str.size));
} break;
@ -2187,23 +2187,23 @@ Object SQLiteColumn::GetValue() const
// Is this a null value?
case SQLITE_NULL:
{
sq_pushnull(DefaultVM::Get());
sq_pushnull(SqVM());
} break;
// Is this an integer?
case SQLITE_INTEGER:
{
sq_pushinteger(DefaultVM::Get(), sqlite3_column_integer(m_Handle->mPtr, m_Index));
sq_pushinteger(SqVM(), sqlite3_column_integer(m_Handle->mPtr, m_Index));
} break;
// Is this a floating point?
case SQLITE_FLOAT:
{
sq_pushfloat(DefaultVM::Get(),
sq_pushfloat(SqVM(),
ConvTo< SQFloat >::From(sqlite3_column_double(m_Handle->mPtr, m_Index)));
} break;
// Is this a string?
case SQLITE_TEXT:
{
sq_pushstring(DefaultVM::Get(),
sq_pushstring(SqVM(),
reinterpret_cast< CSStr >(sqlite3_column_text(m_Handle->mPtr, m_Index)),
sqlite3_column_bytes(m_Handle->mPtr, m_Index));
} break;
@ -2215,13 +2215,13 @@ Object SQLiteColumn::GetValue() const
// Retrieve the the actual blob data that must be returned
auto data = reinterpret_cast< CCStr >(sqlite3_column_blob(m_Handle->mPtr, m_Index));
// Attempt to create a buffer with the blob data on the stack
Var< const SqBuffer & >::push(DefaultVM::Get(), SqBuffer(data, size, 0));
Var< const SqBuffer & >::push(SqVM(), SqBuffer(data, size, 0));
} break;
// Unknown type
default: STHROWF("Unknown value to fetch at index: %d", m_Index);
}
// Obtain the object with the value from the stack and return it
return Var< Object >(DefaultVM::Get(), -1).value;
return Var< Object >(SqVM(), -1).value;
}
// ------------------------------------------------------------------------------------------------
@ -2236,17 +2236,17 @@ Object SQLiteColumn::GetNumber() const
// Is this a null value?
case SQLITE_NULL:
{
sq_pushinteger(DefaultVM::Get(), 0);
sq_pushinteger(SqVM(), 0);
} break;
// Is this an integer?
case SQLITE_INTEGER:
{
sq_pushinteger(DefaultVM::Get(), sqlite3_column_integer(m_Handle->mPtr, m_Index));
sq_pushinteger(SqVM(), sqlite3_column_integer(m_Handle->mPtr, m_Index));
} break;
// Is this a floating point?
case SQLITE_FLOAT:
{
sq_pushfloat(DefaultVM::Get(),
sq_pushfloat(SqVM(),
ConvTo< SQFloat >::From(sqlite3_column_double(m_Handle->mPtr, m_Index)));
} break;
// Is this a string?
@ -2256,17 +2256,17 @@ Object SQLiteColumn::GetNumber() const
// Is there even a string to parse?
if (!str || *str == '\0')
{
sq_pushinteger(DefaultVM::Get(), 0);
sq_pushinteger(SqVM(), 0);
}
// Can we treat this string as a float?
else if (!std::strchr(str, '.'))
{
sq_pushfloat(DefaultVM::Get(),
sq_pushfloat(SqVM(),
ConvTo< SQFloat >::From(std::strtod(str, nullptr)));
}
else
{
sq_pushinteger(DefaultVM::Get(),
sq_pushinteger(SqVM(),
ConvTo< SQInteger >::From(std::strtoll(str, nullptr, 10)));
}
@ -2275,7 +2275,7 @@ Object SQLiteColumn::GetNumber() const
default: STHROWF("Unknown number to fetch at index: %d", m_Index);
}
// Obtain the object with the value from the stack and return it
return Var< Object >(DefaultVM::Get(), -1).value;
return Var< Object >(SqVM(), -1).value;
}
// ------------------------------------------------------------------------------------------------
@ -2309,10 +2309,10 @@ Object SQLiteColumn::GetString() const
// Obtain the initial stack size
const StackGuard sg;
// Push the column text on the stack
sq_pushstring(DefaultVM::Get(), reinterpret_cast< CSStr >(sqlite3_column_text(m_Handle->mPtr, m_Index)),
sq_pushstring(SqVM(), reinterpret_cast< CSStr >(sqlite3_column_text(m_Handle->mPtr, m_Index)),
sqlite3_column_bytes(m_Handle->mPtr, m_Index));
// Get the object from the stack and return it
return Var< Object >(DefaultVM::Get(), -1).value;
return Var< Object >(SqVM(), -1).value;
}
// ------------------------------------------------------------------------------------------------
@ -2342,9 +2342,9 @@ Object SQLiteColumn::GetBuffer() const
// Retrieve the the actual blob data that must be returned
auto data = reinterpret_cast< CCStr >(sqlite3_column_blob(m_Handle->mPtr, m_Index));
// Attempt to create a buffer with the blob data on the stack
Var< const SqBuffer & >::push(DefaultVM::Get(), SqBuffer(data, size, 0));
Var< const SqBuffer & >::push(SqVM(), SqBuffer(data, size, 0));
// Get the object from the stack and return it
return Var< Object >(DefaultVM::Get(), -1).value;
return Var< Object >(SqVM(), -1).value;
}
// ------------------------------------------------------------------------------------------------
@ -2356,7 +2356,7 @@ Object SQLiteColumn::GetBlob() const
// Obtain the size of the data
const Int32 sz = sqlite3_column_bytes(m_Handle->mPtr, m_Index);
// Allocate a blob of the same size
SQUserPointer p = sqstd_createblob(DefaultVM::Get(), sz);
SQUserPointer p = sqstd_createblob(SqVM(), sz);
// Obtain a pointer to the data
const void * b = sqlite3_column_blob(m_Handle->mPtr, m_Index);
// Could the memory blob be allocated?
@ -2368,9 +2368,9 @@ Object SQLiteColumn::GetBlob() const
else if (!b)
{
// Pop the memory blob from the stack
sq_pop(DefaultVM::Get(), 1);
sq_pop(SqVM(), 1);
// Push a null value instead
sq_pushnull(DefaultVM::Get());
sq_pushnull(SqVM());
}
// Copy the data into the memory blob
else
@ -2378,7 +2378,7 @@ Object SQLiteColumn::GetBlob() const
std::memcpy(p, b, sz);
}
// Get the object from the stack and return it
return Var< Object >(DefaultVM::Get(), -1).value;
return Var< Object >(SqVM(), -1).value;
}
// ------------------------------------------------------------------------------------------------
@ -2729,7 +2729,7 @@ Array SQLiteStatement::GetArray(Int32 min, Int32 max) const
STHROWF("Maximum is out of range: %d:%d", max, m_Handle->mColumns);
}
// Allocate an array large enough to hold the values from selected columns
Array arr(DefaultVM::Get(), max-min);
Array arr(SqVM(), max-min);
// Create a column instance to retrieve the values
SQLiteColumn column(m_Handle);
// Array element counter
@ -2771,7 +2771,7 @@ Table SQLiteStatement::GetTable(Int32 min, Int32 max) const
STHROWF("Maximum is out of range: %d:%d", max, m_Handle->mColumns);
}
// Create a table to hold the selected column values
Table tbl(DefaultVM::Get());
Table tbl(SqVM());
// Create a column instance to retrieve the values
SQLiteColumn column(m_Handle);
// Process the range of selected columns

View File

@ -231,7 +231,7 @@ LightObj SqBuffer::ReadRawString(SQInteger length)
// Remember the current stack size
const StackGuard sg;
// Attempt to create the string as an object
sq_pushstring(DefaultVM::Get(), &m_Buffer->Cursor(), len);
sq_pushstring(SqVM(), &m_Buffer->Cursor(), len);
// Advance the cursor after the string
m_Buffer->Advance(len);
// Return the resulted object
@ -258,7 +258,7 @@ LightObj SqBuffer::ReadClientString()
// Remember the current stack size
const StackGuard sg;
// Attempt to create the string as an object
sq_pushstring(DefaultVM::Get(), &m_Buffer->Cursor(), length);
sq_pushstring(SqVM(), &m_Buffer->Cursor(), length);
// Advance the cursor after the string
m_Buffer->Advance(length);
// Return the resulted object

View File

@ -294,13 +294,13 @@ void Logger::BindCb(Uint8 level, Object & env, Function & func)
// Is the specified callback function null?
if (func.IsNull())
{
cb.ReleaseGently(); // Then release the current callback
cb.Release(); // Then release the current callback
}
// Does this function need a custom environment?
else if (env.IsNull())
{
// Use the root table instead
RootTable root(DefaultVM::Get_());
RootTable root(SqVM());
// Bind the root table with the function
cb = Function(env.GetVM(), root, func.GetFunc());
}
@ -334,7 +334,7 @@ void Logger::Release()
{
for (auto & f : m_LogCb)
{
f.ReleaseGently();
f.Release();
}
}
@ -351,7 +351,7 @@ SQBool Logger::ProcessCb(Uint8 level, bool sub)
// Grab the associated function
Function & fn = m_LogCb[idx];
// Grab the default VM
HSQUIRRELVM vm = DefaultVM::Get_();
HSQUIRRELVM vm = SqVM();
// Gram the top of the stack
SQInteger top = sq_gettop(vm);
// Push the function followed by the environment
@ -467,7 +467,7 @@ void Logger::Debug(CCStr fmt, va_list args)
{
using namespace Sqrat;
// Retrieve the default Squirrel VM
HSQUIRRELVM vm = DefaultVM::Get();
HSQUIRRELVM vm = SqVM();
// Used to acquire
SQStackInfos si;
// Write the message to the buffer

View File

@ -143,13 +143,13 @@ static inline Array Player_AllWhereNameEquals(bool neg, bool cs, CSStr name)
// Remember the current stack size
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
sq_newarray(SqVM(), 0);
// Process each entity in the pool
EachEquals(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
ValidInstFunc< CPlayer >(), PlayerName(),
AppendElemFunc< CPlayer >(), name, !neg, cs);
// Return the array at the top of the stack
return Var< Array >(DefaultVM::Get(), -1).value;
return Var< Array >(SqVM(), -1).value;
}
/* ------------------------------------------------------------------------------------------------
@ -161,13 +161,13 @@ static inline Array Player_AllWhereNameBegins(bool neg, bool cs, CSStr name)
// Remember the current stack size
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
sq_newarray(SqVM(), 0);
// Process each entity in the pool
EachBegins(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
ValidInstFunc< CPlayer >(), PlayerName(),
AppendElemFunc< CPlayer >(), name, strlen(name), !neg, cs);
// Return the array at the top of the stack
return Var< Array >(DefaultVM::Get(), -1).value;
return Var< Array >(SqVM(), -1).value;
}
/* ------------------------------------------------------------------------------------------------
@ -179,13 +179,13 @@ static inline Array Player_AllWhereNameEnds(bool neg, bool cs, CSStr name)
// Remember the current stack size
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
sq_newarray(SqVM(), 0);
// Process each entity in the pool
EachEnds(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
ValidInstFunc< CPlayer >(), PlayerName(),
AppendElemFunc< CPlayer >(), name, strlen(name), !neg, cs);
// Return the array at the top of the stack
return Var< Array >(DefaultVM::Get(), -1).value;
return Var< Array >(SqVM(), -1).value;
}
/* ------------------------------------------------------------------------------------------------
@ -197,13 +197,13 @@ static inline Array Player_AllWhereNameContains(bool neg, bool cs, CSStr name)
// Remember the current stack size
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
sq_newarray(SqVM(), 0);
// Process each entity in the pool
EachContains(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
ValidInstFunc< CPlayer >(), PlayerName(),
AppendElemFunc< CPlayer >(), name, !neg, cs);
// Return the array at the top of the stack
return Var< Array >(DefaultVM::Get(), -1).value;
return Var< Array >(SqVM(), -1).value;
}
/* ------------------------------------------------------------------------------------------------
@ -215,13 +215,13 @@ static inline Array Player_AllWhereNameMatches(bool neg, bool cs, CSStr name)
// Remember the current stack size
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
sq_newarray(SqVM(), 0);
// Process each entity in the pool
EachMatches(InstSpec< CPlayer >::CBegin(), InstSpec< CPlayer >::CEnd(),
ValidInstFunc< CPlayer >(), PlayerName(),
AppendElemFunc< CPlayer >(), name, !neg, cs);
// Return the array at the top of the stack
return Var< Array >(DefaultVM::Get(), -1).value;
return Var< Array >(SqVM(), -1).value;
}
/* ------------------------------------------------------------------------------------------------

View File

@ -895,7 +895,7 @@ template < typename T > struct AppendElemFunc
/* --------------------------------------------------------------------------------------------
* Base constructor.
*/
explicit AppendElemFunc(SQInteger idx = -2, HSQUIRRELVM vm = DefaultVM::Get())
explicit AppendElemFunc(SQInteger idx = -2, HSQUIRRELVM vm = SqVM())
: mIdx(idx), mVM(vm)
{
/* ... */
@ -971,7 +971,7 @@ public:
*/
bool operator () (const typename InstSpec< T >::Instance & inst)
{
HSQUIRRELVM vm = DefaultVM::Get();
HSQUIRRELVM vm = SqVM();
// Push the callback object
sq_pushobject(vm, mFunc.mObj);
// Push the callback environment object
@ -1045,7 +1045,7 @@ public:
*/
bool operator () (const typename InstSpec< T >::Instance & inst)
{
HSQUIRRELVM vm = DefaultVM::Get();
HSQUIRRELVM vm = SqVM();
// Push the callback object
sq_pushobject(vm, mFunc.mObj);
// Push the callback environment object
@ -1212,11 +1212,11 @@ public:
{
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
sq_newarray(SqVM(), 0);
// Process each entity in the pool
Collect(Inst::CBegin(), Inst::CEnd(), ValidInst(), AppendElem());
// Return the array at the top of the stack
return Var< Array >(DefaultVM::Get(), -1).value;
return Var< Array >(SqVM(), -1).value;
}
/* --------------------------------------------------------------------------------------------
@ -1228,11 +1228,11 @@ public:
// Remember the current stack size
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
sq_newarray(SqVM(), 0);
// Process each entity in the pool
EachEquals(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), AppendElem(), tag, !neg, cs);
// Return the array at the top of the stack
return Var< Array >(DefaultVM::Get(), -1).value;
return Var< Array >(SqVM(), -1).value;
}
/* --------------------------------------------------------------------------------------------
@ -1244,11 +1244,11 @@ public:
// Remember the current stack size
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
sq_newarray(SqVM(), 0);
// Process each entity in the pool
EachBegins(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), AppendElem(), tag, strlen(tag), !neg, cs);
// Return the array at the top of the stack
return Var< Array >(DefaultVM::Get(), -1).value;
return Var< Array >(SqVM(), -1).value;
}
/* --------------------------------------------------------------------------------------------
@ -1260,11 +1260,11 @@ public:
// Remember the current stack size
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
sq_newarray(SqVM(), 0);
// Process each entity in the pool
EachEnds(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), AppendElem(), tag, strlen(tag), !neg, cs);
// Return the array at the top of the stack
return Var< Array >(DefaultVM::Get(), -1).value;
return Var< Array >(SqVM(), -1).value;
}
/* --------------------------------------------------------------------------------------------
@ -1276,11 +1276,11 @@ public:
// Remember the current stack size
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
sq_newarray(SqVM(), 0);
// Process each entity in the pool
EachContains(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), AppendElem(), tag, !neg, cs);
// Return the array at the top of the stack
return Var< Array >(DefaultVM::Get(), -1).value;
return Var< Array >(SqVM(), -1).value;
}
/* --------------------------------------------------------------------------------------------
@ -1292,11 +1292,11 @@ public:
// Remember the current stack size
const StackGuard sg;
// Allocate an empty array on the stack
sq_newarray(DefaultVM::Get(), 0);
sq_newarray(SqVM(), 0);
// Process each entity in the pool
EachMatches(Inst::CBegin(), Inst::CEnd(), ValidInst(), InstTag(), AppendElem(), tag, !neg, cs);
// Return the array at the top of the stack
return Var< Array >(DefaultVM::Get(), -1).value;
return Var< Array >(SqVM(), -1).value;
}
/* --------------------------------------------------------------------------------------------

View File

@ -81,7 +81,7 @@ bool Area::Manage()
}
// We expect this to be called only from the script so that the first parameter in the vm
// is the area instance
LightObj obj(1, DefaultVM::Get());
LightObj obj(1, SqVM());
// Attempt to manage this area
AreaManager::Get().InsertArea(*this, obj);
// Return whether the area is now managed by any cells

View File

@ -105,9 +105,9 @@ Object & Controller::Attach(Object && obj, Listener * ptr)
// Obtain the initial stack size
const StackGuard sg;
// Push the instance on the stack
ClassType< Listener >::PushInstance(DefaultVM::Get(), ptr);
ClassType< Listener >::PushInstance(SqVM(), ptr);
// Grab the instance from the stack
obj = Var< Object >(DefaultVM::Get(), -1).value;
obj = Var< Object >(SqVM(), -1).value;
}
// Are we supposed to grab the instance?
else if (ptr == nullptr)
@ -362,7 +362,7 @@ Int32 Controller::Exec(Context & ctx)
if (ctx.mInstance->m_Associate)
{
// Create the associative container
Table args(DefaultVM::Get());
Table args(SqVM());
// Copy the arguments into the table
for (Uint32 arg = 0; arg < ctx.mArgc; ++arg)
{
@ -393,7 +393,7 @@ Int32 Controller::Exec(Context & ctx)
else
{
// Reserve an array for the extracted arguments
Array args(DefaultVM::Get(), ctx.mArgc);
Array args(SqVM(), ctx.mArgc);
// Copy the arguments into the array
for (Uint32 arg = 0; arg < ctx.mArgc; ++arg)
{
@ -513,15 +513,15 @@ bool Controller::Parse(Context & ctx)
if (itr != ctx.mArgument.end())
{
// Transform it into a script object
sq_pushstring(DefaultVM::Get(), &(*itr), std::distance(itr, ctx.mArgument.cend()));
sq_pushstring(SqVM(), &(*itr), std::distance(itr, ctx.mArgument.cend()));
}
// Just push an empty string
else
{
sq_pushstring(DefaultVM::Get(), _SC(""), 0);
sq_pushstring(SqVM(), _SC(""), 0);
}
// Get the object from the stack and add it to the argument list along with it's type
ctx.mArgv.emplace_back(CMDARG_STRING, Var< Object >(DefaultVM::Get(), -1).value);
ctx.mArgv.emplace_back(CMDARG_STRING, Var< Object >(SqVM(), -1).value);
// Include this argument into the count
++ctx.mArgc;
// Nothing left to parse
@ -615,16 +615,16 @@ bool Controller::Parse(Context & ctx)
if (str >= end)
{
// Just push an empty string
sq_pushstring(DefaultVM::Get(), _SC(""), 0);
sq_pushstring(SqVM(), _SC(""), 0);
}
// Add it to the argument list along with it's type
else
{
// Transform it into a script object
sq_pushstring(DefaultVM::Get(), str, end - str - 1);
sq_pushstring(SqVM(), str, end - str - 1);
}
// Get the object from the stack and add it to the argument list along with it's type
ctx.mArgv.emplace_back(CMDARG_STRING, Var< Object >(DefaultVM::Get(), -1).value);
ctx.mArgv.emplace_back(CMDARG_STRING, Var< Object >(SqVM(), -1).value);
// Advance to the next argument and obtain its flags
arg_flags = ctx.mInstance->m_ArgSpec[++ctx.mArgc];
}
@ -656,9 +656,9 @@ bool Controller::Parse(Context & ctx)
// Remember the current stack size
const StackGuard sg;
// Transform it into a script object
sq_pushinteger(DefaultVM::Get(), ConvTo< SQInteger >::From(value));
sq_pushinteger(SqVM(), ConvTo< SQInteger >::From(value));
// Get the object from the stack and add it to the argument list along with it's type
ctx.mArgv.emplace_back(CMDARG_INTEGER, Var< Object >(DefaultVM::Get(), -1).value);
ctx.mArgv.emplace_back(CMDARG_INTEGER, Var< Object >(SqVM(), -1).value);
// We've identified the correct value type
identified = true;
}
@ -680,9 +680,9 @@ bool Controller::Parse(Context & ctx)
// Remember the current stack size
const StackGuard sg;
// Transform it into a script object
sq_pushfloat(DefaultVM::Get(), ConvTo< SQFloat >::From(value));
sq_pushfloat(SqVM(), ConvTo< SQFloat >::From(value));
// Get the object from the stack and add it to the argument list along with it's type
ctx.mArgv.emplace_back(CMDARG_FLOAT, Var< Object >(DefaultVM::Get(), -1).value);
ctx.mArgv.emplace_back(CMDARG_FLOAT, Var< Object >(SqVM(), -1).value);
// We've identified the correct value type
identified = true;
}
@ -709,7 +709,7 @@ bool Controller::Parse(Context & ctx)
if (std::strcmp(lc, "true") == 0 || std::strcmp(lc, "on") == 0)
{
// Transform it into a script object
sq_pushbool(DefaultVM::Get(), static_cast< SQBool >(true));
sq_pushbool(SqVM(), static_cast< SQBool >(true));
// We've identified the correct value type
identified = true;
}
@ -717,7 +717,7 @@ bool Controller::Parse(Context & ctx)
else if (std::strcmp(lc, "false") == 0 || std::strcmp(lc, "off") == 0)
{
// Transform it into a script object
sq_pushbool(DefaultVM::Get(), static_cast< SQBool >(false));
sq_pushbool(SqVM(), static_cast< SQBool >(false));
// We've identified the correct value type
identified = true;
}
@ -725,7 +725,7 @@ bool Controller::Parse(Context & ctx)
if (identified)
{
// Get the object from the stack and add it to the argument list along with it's type
ctx.mArgv.emplace_back(CMDARG_BOOLEAN, Var< Object >(DefaultVM::Get(), -1).value);
ctx.mArgv.emplace_back(CMDARG_BOOLEAN, Var< Object >(SqVM(), -1).value);
}
}
// If everything else failed then simply treat the value as a string
@ -742,7 +742,7 @@ bool Controller::Parse(Context & ctx)
*chr = static_cast< CharT >(std::tolower(*str));
}
// Transform it into a script object
sq_pushstring(DefaultVM::Get(), ctx.mBuffer.Get< SQChar >(), sz);
sq_pushstring(SqVM(), ctx.mBuffer.Get< SQChar >(), sz);
}
// Do we have to make the string uppercase?
else if (arg_flags & CMDARG_UPPER)
@ -753,15 +753,15 @@ bool Controller::Parse(Context & ctx)
*chr = static_cast< CharT >(std::toupper(*str));
}
// Transform it into a script object
sq_pushstring(DefaultVM::Get(), ctx.mBuffer.Get< SQChar >(), sz);
sq_pushstring(SqVM(), ctx.mBuffer.Get< SQChar >(), sz);
}
else
{
// Transform it into a script object
sq_pushstring(DefaultVM::Get(), str, sz);
sq_pushstring(SqVM(), str, sz);
}
// Get the object from the stack and add it to the argument list along with it's type
ctx.mArgv.emplace_back(CMDARG_STRING, Var< Object >(DefaultVM::Get(), -1).value);
ctx.mArgv.emplace_back(CMDARG_STRING, Var< Object >(SqVM(), -1).value);
}
// Advance to the next argument and obtain its flags
arg_flags = ctx.mInstance->m_ArgSpec[++ctx.mArgc];

View File

@ -516,8 +516,8 @@ public:
// Clear the command listeners
ctr->Clear();
// Release the script callbacks, if any
ctr->m_OnFail.ReleaseGently();
ctr->m_OnAuth.ReleaseGently();
ctr->m_OnFail.Release();
ctr->m_OnAuth.Release();
}
}
@ -631,7 +631,7 @@ public:
// Are we supposed to unbind current callback?
if (func.IsNull())
{
m_OnFail.ReleaseGently();
m_OnFail.Release();
}
// Was there a custom environment specified?
else if (env.IsNull())
@ -660,7 +660,7 @@ public:
// Are we supposed to unbind current callback?
if (func.IsNull())
{
m_OnAuth.ReleaseGently();
m_OnAuth.Release();
}
// Was there a custom environment specified?
if (env.IsNull())
@ -743,7 +743,7 @@ public:
Array GetCommandsArray() const
{
// Allocate an array with an adequate size
Array arr(DefaultVM::Get(), m_Commands.size());
Array arr(SqVM(), m_Commands.size());
// Index of the currently processed command listener
SQInteger index = 0;
// Populate the array with the command listeners
@ -761,7 +761,7 @@ public:
Table GetCommandsTable() const
{
// Allocate an empty table
Table tbl(DefaultVM::Get());
Table tbl(SqVM());
// Populate the table with the command listeners
for (const auto & cmd : m_Commands)
{
@ -1296,10 +1296,10 @@ public:
m_Controller.Lock()->Detach(this);
}
// Release callbacks
m_OnExec.ReleaseGently();
m_OnAuth.ReleaseGently();
m_OnPost.ReleaseGently();
m_OnFail.ReleaseGently();
m_OnExec.Release();
m_OnAuth.Release();
m_OnPost.Release();
m_OnFail.Release();
// Is there an element behind us?
if (m_Prev != nullptr)
{
@ -1420,9 +1420,9 @@ public:
// Obtain the initial stack size
const StackGuard sg;
// Push the instance on the stack
ClassType< Manager >::PushInstance(DefaultVM::Get(), m_Controller.Lock()->m_Manager);
ClassType< Manager >::PushInstance(SqVM(), m_Controller.Lock()->m_Manager);
// Grab the instance from the stack
return Var< Object >(DefaultVM::Get(), -1).value;
return Var< Object >(SqVM(), -1).value;
}
/* --------------------------------------------------------------------------------------------
@ -1515,7 +1515,7 @@ public:
Array GetArgTags() const
{
// Allocate an array to encapsulate all tags
Array arr(DefaultVM::Get(), SQMOD_MAX_CMD_ARGS);
Array arr(SqVM(), SQMOD_MAX_CMD_ARGS);
// Put the tags to the allocated array
for (Uint32 arg = 0; arg < SQMOD_MAX_CMD_ARGS; ++arg)
{
@ -1752,7 +1752,7 @@ public:
// Are we supposed to unbind current callback?
if (func.IsNull())
{
m_OnExec.ReleaseGently();
m_OnExec.Release();
}
// Was there a custom environment specified?
else if (env.IsNull())
@ -1781,7 +1781,7 @@ public:
// Are we supposed to unbind current callback?
if (func.IsNull())
{
m_OnAuth.ReleaseGently();
m_OnAuth.Release();
}
// Was there a custom environment specified?
else if (env.IsNull())
@ -1810,7 +1810,7 @@ public:
// Are we supposed to unbind current callback?
if (func.IsNull())
{
m_OnPost.ReleaseGently();
m_OnPost.Release();
}
// Was there a custom environment specified?
else if (env.IsNull())
@ -1839,7 +1839,7 @@ public:
// Are we supposed to unbind current callback?
if (func.IsNull())
{
m_OnFail.ReleaseGently();
m_OnFail.Release();
}
// Was there a custom environment specified?
else if (env.IsNull())

View File

@ -142,7 +142,7 @@ private:
else if (!mSuspended)
{
// Grab the virtual machine once
HSQUIRRELVM vm = DefaultVM::Get();
HSQUIRRELVM vm = SqVM();
// Push the function on the stack
sq_pushobject(vm, mFunc);
// Push the environment on the stack

View File

@ -1521,11 +1521,11 @@ LightObj Signal::CreateFree()
// Create the signal instance
DeleteGuard< Signal > dg(new Signal());
// Attempt to create the signal instance
ClassType< Signal >::PushInstance(DefaultVM::Get(), dg.Get());
ClassType< Signal >::PushInstance(SqVM(), dg.Get());
// This is now managed by the script
dg.Release();
// Return the created signal
return Var< LightObj >(DefaultVM::Get(), -1).value;
return Var< LightObj >(SqVM(), -1).value;
}
// ------------------------------------------------------------------------------------------------
@ -1555,11 +1555,11 @@ LightObj Signal::Create(StackStrF & name)
// Grab the signal instance pointer
Signal * ptr = dg.Get();
// Attempt to create the signal instance
ClassType< Signal >::PushInstance(DefaultVM::Get(), ptr);
ClassType< Signal >::PushInstance(SqVM(), ptr);
// This is now managed by the script
dg.Release();
// Grab a reference to the instance created on the stack
s_Signals.emplace_back(hash, SignalPair(ptr, Var< LightObj >(DefaultVM::Get(), -1).value));
s_Signals.emplace_back(hash, SignalPair(ptr, Var< LightObj >(SqVM(), -1).value));
// Return the created signal
return s_Signals.back().second.second.mObj;
}

View File

@ -127,7 +127,7 @@ protected:
, mThisRef(env)
, mFuncRef(func)
{
HSQUIRRELVM vm = DefaultVM::Get();
HSQUIRRELVM vm = SqVM();
// Remember the current stack size
const StackGuard sg(vm);
// Is there an explicit environment?
@ -175,8 +175,8 @@ protected:
// Track reference
if (mFuncHash != 0)
{
sq_addref(DefaultVM::Get(), &mThisRef);
sq_addref(DefaultVM::Get(), &mFuncRef);
sq_addref(SqVM(), &mThisRef);
sq_addref(SqVM(), &mFuncRef);
}
}
@ -217,8 +217,8 @@ protected:
mThisRef = o.mThisRef;
mFuncRef = o.mFuncRef;
// Track reference
sq_addref(DefaultVM::Get(), &const_cast< HSQOBJECT & >(o.mThisRef));
sq_addref(DefaultVM::Get(), &const_cast< HSQOBJECT & >(o.mFuncRef));
sq_addref(SqVM(), &const_cast< HSQOBJECT & >(o.mThisRef));
sq_addref(SqVM(), &const_cast< HSQOBJECT & >(o.mFuncRef));
}
return *this;
@ -278,7 +278,7 @@ protected:
// Should we release any environment object?
if (mThisHash != 0)
{
sq_release(DefaultVM::Get(), &mThisRef);
sq_release(SqVM(), &mThisRef);
sq_resetobject(&mThisRef);
// Also reset the hash
mThisHash = 0;
@ -286,7 +286,7 @@ protected:
// Should we release any callback object?
if (mFuncHash != 0)
{
sq_release(DefaultVM::Get(), &mFuncRef);
sq_release(SqVM(), &mFuncRef);
sq_resetobject(&mFuncRef);
// Also reset the hash
mFuncHash = 0;
@ -681,7 +681,7 @@ protected:
*/
template < typename T > void PushParameters(T v)
{
Var< T >::push(DefaultVM::Get(), v);
Var< T >::push(SqVM(), v);
}
/* --------------------------------------------------------------------------------------------
@ -689,7 +689,7 @@ protected:
*/
template < typename T, typename... Args > void PushParameters(T v, Args... args)
{
Var< T >::push(DefaultVM::Get(), v);
Var< T >::push(SqVM(), v);
PushParameters(args...);
}
@ -732,7 +732,7 @@ public:
// Activate the current scope and create a guard to restore it
const AutoAssign< Scope * > aa(m_Scope, scope.mParent, &scope);
// Grab the default virtual machine
HSQUIRRELVM vm = DefaultVM::Get();
HSQUIRRELVM vm = SqVM();
// Process the slots from this scope
while (scope.mItr != scope.mEnd)
{

View File

@ -35,7 +35,7 @@ void Tasks::Task::Init(HSQOBJECT & func, HSQOBJECT & inst, Interval intrv, Itera
mEntity = ConvTo< Int16 >::From(id);
mType = ConvTo< Uint8 >::From(type);
// Grab the virtual machine once
HSQUIRRELVM vm = DefaultVM::Get();
HSQUIRRELVM vm = SqVM();
// Remember the current stack size
const StackGuard sg(vm);
// Is there a valid function?
@ -71,7 +71,7 @@ Tasks::Interval Tasks::Task::Execute()
return 0; // Dunno how we got here but it ends now
}
// Grab the virtual machine once
HSQUIRRELVM vm = DefaultVM::Get();
HSQUIRRELVM vm = SqVM();
// Push the function on the stack
sq_pushobject(vm, mFunc);
// Push the environment on the stack

View File

@ -179,7 +179,7 @@ private:
STHROWF("Invalid callback type %s", SqTypeName(mFunc.GetType()));
}
// Grab the virtual machine once
HSQUIRRELVM vm = DefaultVM::Get();
HSQUIRRELVM vm = SqVM();
// Remember the current stack size
const StackGuard sg(vm);
// Push the callback on the stack

View File

@ -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) {
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -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

View File

@ -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);

View File

@ -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;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -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) {
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -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);

View File

@ -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;