ArrayStack: add Clone method (#1304)

* Provide ArrayStack.Clone method

* Clean definition for old syntax.

Co-authored-by: Kyle Sanderson <[email protected]>
This commit is contained in:
Ҝℴţأķ
2020-07-08 20:59:17 -07:00
committed by GitHub
co-authored by Kyle Sanderson
parent 4a4b9ce7f0
commit 611bad4036
2 changed files with 36 additions and 0 deletions
+28
View File
@@ -83,6 +83,32 @@ static cell_t CreateStack(IPluginContext *pContext, const cell_t *params)
return hndl;
}
static cell_t CloneStack(IPluginContext *pContext, const cell_t *params)
{
CellArray *oldArray;
HandleError err;
HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&oldArray)) != HandleError_None)
{
return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
}
ICellArray *array = oldArray->clone();
if (!array)
{
return pContext->ThrowNativeError("Failed to clone stack. Out of memory.");
}
Handle_t hndl = handlesys->CreateHandle(htCellStack, array, pContext->GetIdentity(), g_pCoreIdent, NULL);
if (!hndl)
{
delete array;
}
return hndl;
}
static cell_t PushStackCell(IPluginContext *pContext, const cell_t *params)
{
CellArray *array;
@@ -387,6 +413,7 @@ static cell_t GetStackBlockSize(IPluginContext *pContext, const cell_t *params)
REGISTER_NATIVES(cellStackNatives)
{
{"CreateStack", CreateStack},
{"CloneStack", CloneStack},
{"IsStackEmpty", IsStackEmpty},
{"PopStackArray", PopStackArray},
{"PopStackCell", PopStackCell},
@@ -398,6 +425,7 @@ REGISTER_NATIVES(cellStackNatives)
// Transitional syntax support.
{"ArrayStack.ArrayStack", CreateStack},
{"ArrayStack.Clone", CloneStack},
{"ArrayStack.Pop", ArrayStack_Pop},
{"ArrayStack.PopString", ArrayStack_PopString},
{"ArrayStack.PopArray", ArrayStack_PopArray},