ArrayStack: add Clone method (#1304)
* Provide ArrayStack.Clone method * Clean definition for old syntax. Co-authored-by: Kyle Sanderson <kyle.leet@gmail.com>
This commit is contained in:
parent
4a4b9ce7f0
commit
611bad4036
@ -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},
|
||||
|
@ -54,6 +54,14 @@ methodmap ArrayStack < Handle
|
||||
// new Array[X][32]
|
||||
public native ArrayStack(int blocksize=1);
|
||||
|
||||
// Clones an stack, returning a new handle with the same size and data.
|
||||
// This should NOT be confused with CloneHandle. This is a completely new
|
||||
// handle with the same data but no relation to the original. It should
|
||||
// closed when no longer needed.
|
||||
//
|
||||
// @return New handle to the cloned stack object
|
||||
public native ArrayStack Clone();
|
||||
|
||||
// Pushes a value onto the end of the stack, adding a new index.
|
||||
//
|
||||
// This may safely be used even if the stack has a blocksize
|
||||
|
Loading…
Reference in New Issue
Block a user