mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-15 22:57:12 +02:00
Remove duplicate code that converts a buffer to a script string object.
This commit is contained in:
@ -96,6 +96,33 @@ Function & NullFunction()
|
||||
return f;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object BufferToStrObj(const Buffer & b)
|
||||
{
|
||||
// Obtain the initial stack size
|
||||
const StackGuard sg(DefaultVM::Get());
|
||||
// Push the string onto the stack
|
||||
sq_pushstring(DefaultVM::Get(), b.Data(), b.Position());
|
||||
// Obtain the object from the stack and return it
|
||||
return Var< Object >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Object BufferToStrObj(const Buffer & b, Uint32 size)
|
||||
{
|
||||
// Perform a range check on the specified buffer
|
||||
if (size > b.Capacity())
|
||||
{
|
||||
SqThrowF("The specified buffer size is out of range: %u >= %u", size, b.Capacity());
|
||||
}
|
||||
// Obtain the initial stack size
|
||||
const StackGuard sg(DefaultVM::Get());
|
||||
// Push the string onto the stack
|
||||
sq_pushstring(DefaultVM::Get(), b.Data(), size);
|
||||
// Obtain the object from the stack and return it
|
||||
return Var< Object >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
bool SToB(CSStr str)
|
||||
{
|
||||
|
@ -239,6 +239,16 @@ Array & NullArray();
|
||||
*/
|
||||
Function & NullFunction();
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Create a script string object from a buffer.
|
||||
*/
|
||||
Object BufferToStrObj(const Buffer & b);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Create a script string object from a portion of a buffer.
|
||||
*/
|
||||
Object BufferToStrObj(const Buffer & b, Uint32 size);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Create a script object from the specified value on the default VM.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user