mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Remove duplicate code that converts a buffer to a script string object.
This commit is contained in:
parent
4cac7d2d30
commit
20ae383c42
@ -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.
|
||||
*/
|
||||
|
@ -1077,17 +1077,6 @@ Buffer SysEnv::NullDir()
|
||||
return std::move(b);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object BufferToObj(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;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static bool SqEnv_Has(CCStr name)
|
||||
{
|
||||
@ -1097,13 +1086,13 @@ static bool SqEnv_Has(CCStr name)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object SqEnv_Get(CCStr name)
|
||||
{
|
||||
return BufferToObj(SysEnv::Get(name, nullptr));
|
||||
return BufferToStrObj(SysEnv::Get(name, nullptr));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object SqEnv_GetOr(CCStr name, CCStr fallback)
|
||||
{
|
||||
return BufferToObj(SysEnv::Get(name, fallback));
|
||||
return BufferToStrObj(SysEnv::Get(name, fallback));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -1115,73 +1104,73 @@ static void SqEnv_Set(CCStr name, CCStr value)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object SqEnv_ExpandVars(CCStr str)
|
||||
{
|
||||
return BufferToObj(SysEnv::ExpandVars(str));
|
||||
return BufferToStrObj(SysEnv::ExpandVars(str));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object SqEnv_ExpandPath(CCStr path)
|
||||
{
|
||||
return BufferToObj(SysEnv::ExpandPath(path));
|
||||
return BufferToStrObj(SysEnv::ExpandPath(path));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object SqEnv_WorkingDir()
|
||||
{
|
||||
return BufferToObj(SysEnv::WorkingDir());
|
||||
return BufferToStrObj(SysEnv::WorkingDir());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object SqEnv_HomeDir()
|
||||
{
|
||||
return BufferToObj(SysEnv::HomeDir());
|
||||
return BufferToStrObj(SysEnv::HomeDir());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object SqEnv_ConfigHomeDir()
|
||||
{
|
||||
return BufferToObj(SysEnv::ConfigHomeDir());
|
||||
return BufferToStrObj(SysEnv::ConfigHomeDir());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object SqEnv_DataHomeDir()
|
||||
{
|
||||
return BufferToObj(SysEnv::DataHomeDir());
|
||||
return BufferToStrObj(SysEnv::DataHomeDir());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object SqEnv_TempHomeDir()
|
||||
{
|
||||
return BufferToObj(SysEnv::TempHomeDir());
|
||||
return BufferToStrObj(SysEnv::TempHomeDir());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object SqEnv_CacheHomeDir()
|
||||
{
|
||||
return BufferToObj(SysEnv::CacheHomeDir());
|
||||
return BufferToStrObj(SysEnv::CacheHomeDir());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object SqEnv_TempDir()
|
||||
{
|
||||
return BufferToObj(SysEnv::TempDir());
|
||||
return BufferToStrObj(SysEnv::TempDir());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object SqEnv_ConfigDir()
|
||||
{
|
||||
return BufferToObj(SysEnv::ConfigDir());
|
||||
return BufferToStrObj(SysEnv::ConfigDir());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object SqEnv_SystemDir()
|
||||
{
|
||||
return BufferToObj(SysEnv::SystemDir());
|
||||
return BufferToStrObj(SysEnv::SystemDir());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static Object SqEnv_NullDir()
|
||||
{
|
||||
return BufferToObj(SysEnv::NullDir());
|
||||
return BufferToStrObj(SysEnv::NullDir());
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
|
@ -278,14 +278,7 @@ Int32 SysPath::Cmp(const SysPath & o) const
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object SysPath::ToString() const
|
||||
{
|
||||
// Transform the path components into a string
|
||||
Buffer b(ToBuffer());
|
||||
// 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;
|
||||
return BufferToStrObj(ToBuffer());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -687,14 +680,7 @@ Buffer SysPath::ToBuffer(Style style) const
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object SysPath::ToStr(Int32 style) const
|
||||
{
|
||||
// Transform the path components into a string
|
||||
Buffer b(ToBuffer(static_cast< Style >(style)));
|
||||
// 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;
|
||||
return BufferToStrObj(ToBuffer(static_cast< Style >(style)));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user