mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-01-19 12:07:13 +01:00
Specialize the buffer creation functions.
This commit is contained in:
parent
c2ac1f3fd8
commit
ad55025bc8
@ -7,6 +7,9 @@
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
namespace SqMod {
|
namespace SqMod {
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
extern Object CreateBufferWrapperMove(Buffer && b);
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
void Core::EmitCustomEvent(Int32 group, Int32 header, Object & payload)
|
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
|
// Replicate the data to the allocated buffer
|
||||||
b.Write(0, reinterpret_cast< Buffer::ConstPtr >(data), size);
|
b.Write(0, reinterpret_cast< Buffer::ConstPtr >(data), size);
|
||||||
// Wrap the buffer into a script object
|
// 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
|
// Wrap the buffer into a script object
|
||||||
if (o.IsNull())
|
if (o.IsNull())
|
||||||
{
|
{
|
||||||
|
@ -11,6 +11,56 @@ namespace SqMod {
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
extern void Register_BufferInterpreter(Table & bns);
|
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)
|
Object BufferWrapper::Create(SzType n)
|
||||||
{
|
{
|
||||||
@ -301,6 +351,7 @@ void Register_Buffer(HSQUIRRELVM vm)
|
|||||||
Class< BufferWrapper >(vm, _SC("SqBufferWrapper"))
|
Class< BufferWrapper >(vm, _SC("SqBufferWrapper"))
|
||||||
// Constructors
|
// Constructors
|
||||||
.Ctor()
|
.Ctor()
|
||||||
|
.Ctor< const BufferWrapper & >()
|
||||||
// Properties
|
// Properties
|
||||||
.Prop(_SC("Front"), &BufferWrapper::GetFront, &BufferWrapper::SetFront)
|
.Prop(_SC("Front"), &BufferWrapper::GetFront, &BufferWrapper::SetFront)
|
||||||
.Prop(_SC("Next"), &BufferWrapper::GetNext, &BufferWrapper::SetNext)
|
.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.
|
* Buffer constructor.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user