mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 08:47:17 +01:00
Specialize the buffer creation functions.
This commit is contained in:
parent
c2ac1f3fd8
commit
ad55025bc8
@ -7,6 +7,9 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
extern Object CreateBufferWrapperMove(Buffer && b);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Core::EmitCustomEvent(Int32 group, Int32 header, Object & payload)
|
||||
{
|
||||
@ -1066,7 +1069,7 @@ void Core::EmitClientScriptData(Int32 player_id, const uint8_t * data, size_t si
|
||||
// Replicate the data to the allocated buffer
|
||||
b.Write(0, reinterpret_cast< Buffer::ConstPtr >(data), size);
|
||||
// Wrap the buffer into a script object
|
||||
const Object o = MakeObject(m_VM, BufferWrapper(std::move(b)));
|
||||
const Object o = CreateBufferWrapperMove(std::move(b));
|
||||
// Wrap the buffer into a script object
|
||||
if (o.IsNull())
|
||||
{
|
||||
|
@ -11,6 +11,56 @@ namespace SqMod {
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
extern void Register_BufferInterpreter(Table & bns);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object CreateBufferWrapperCopy(const Buffer & b)
|
||||
{
|
||||
// Attempt to create the requested buffer
|
||||
try
|
||||
{
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Transform the pointer into a script object
|
||||
PushVar< const BufferWrapper & >(DefaultVM::Get(), BufferWrapper(b));
|
||||
// Get the object from the stack and return it
|
||||
return Var< Object >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
throw e; // Re-throw
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
STHROWF("%s", e.what()); // Re-package
|
||||
}
|
||||
// Shouldn't really reach this point
|
||||
return NullObject();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object CreateBufferWrapperMove(Buffer && b)
|
||||
{
|
||||
// Attempt to create the requested buffer
|
||||
try
|
||||
{
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Transform the pointer into a script object
|
||||
PushVar< const BufferWrapper & >(DefaultVM::Get(), BufferWrapper(std::move(b)));
|
||||
// Get the object from the stack and return it
|
||||
return Var< Object >(DefaultVM::Get(), -1).value;
|
||||
}
|
||||
catch (const Sqrat::Exception & e)
|
||||
{
|
||||
throw e; // Re-throw
|
||||
}
|
||||
catch (const std::exception & e)
|
||||
{
|
||||
STHROWF("%s", e.what()); // Re-package
|
||||
}
|
||||
// Shouldn't really reach this point
|
||||
return NullObject();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object BufferWrapper::Create(SzType n)
|
||||
{
|
||||
@ -301,6 +351,7 @@ void Register_Buffer(HSQUIRRELVM vm)
|
||||
Class< BufferWrapper >(vm, _SC("SqBufferWrapper"))
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< const BufferWrapper & >()
|
||||
// Properties
|
||||
.Prop(_SC("Front"), &BufferWrapper::GetFront, &BufferWrapper::SetFront)
|
||||
.Prop(_SC("Next"), &BufferWrapper::GetNext, &BufferWrapper::SetNext)
|
||||
|
@ -57,6 +57,15 @@ public:
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Buffer constructor.
|
||||
*/
|
||||
BufferWrapper(const Buffer & b)
|
||||
: m_Buffer(new Buffer(b))
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Buffer constructor.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user