Add ADT array blocksize getter (#578)
Add GetArrayBlockSize and GetStackBlockSize and equivalent properties to the methodmaps to get the blocksize the array or stack was created with. Useful when getting array handles from other plugins you didn't create yourself.
This commit is contained in:
@@ -580,6 +580,21 @@ static cell_t FindValueInArray(IPluginContext *pContext, const cell_t *params)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static cell_t GetArrayBlockSize(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
CellArray *array;
|
||||
HandleError err;
|
||||
HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
|
||||
|
||||
if ((err = handlesys->ReadHandle(params[1], htCellArray, &sec, (void **)&array))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
|
||||
}
|
||||
|
||||
return array->blocksize();
|
||||
}
|
||||
|
||||
REGISTER_NATIVES(cellArrayNatives)
|
||||
{
|
||||
{"ClearArray", ClearArray},
|
||||
@@ -601,6 +616,7 @@ REGISTER_NATIVES(cellArrayNatives)
|
||||
{"CloneArray", CloneArray},
|
||||
{"FindStringInArray", FindStringInArray},
|
||||
{"FindValueInArray", FindValueInArray},
|
||||
{"GetArrayBlockSize", GetArrayBlockSize},
|
||||
|
||||
// Transitional syntax support.
|
||||
{"ArrayList.ArrayList", CreateArray},
|
||||
@@ -622,6 +638,7 @@ REGISTER_NATIVES(cellArrayNatives)
|
||||
{"ArrayList.Clone", CloneArray},
|
||||
{"ArrayList.FindString", FindStringInArray},
|
||||
{"ArrayList.FindValue", FindValueInArray},
|
||||
{"ArrayList.BlockSize.get", GetArrayBlockSize},
|
||||
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
@@ -369,6 +369,21 @@ static cell_t ArrayStack_PopArray(IPluginContext *pContext, const cell_t *params
|
||||
return 0;
|
||||
}
|
||||
|
||||
static cell_t GetStackBlockSize(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
HandleError err;
|
||||
CellArray *array;
|
||||
HandleSecurity sec(pContext->GetIdentity(), g_pCoreIdent);
|
||||
|
||||
if ((err = handlesys->ReadHandle(params[1], htCellStack, &sec, (void **)&array))
|
||||
!= HandleError_None)
|
||||
{
|
||||
return pContext->ThrowNativeError("Invalid Handle %x (error: %d)", params[1], err);
|
||||
}
|
||||
|
||||
return array->blocksize();
|
||||
}
|
||||
|
||||
REGISTER_NATIVES(cellStackNatives)
|
||||
{
|
||||
{"CreateStack", CreateStack},
|
||||
@@ -379,6 +394,7 @@ REGISTER_NATIVES(cellStackNatives)
|
||||
{"PushStackArray", PushStackArray},
|
||||
{"PushStackCell", PushStackCell},
|
||||
{"PushStackString", PushStackString},
|
||||
{"GetStackBlockSize", GetStackBlockSize},
|
||||
|
||||
// Transitional syntax support.
|
||||
{"ArrayStack.ArrayStack", CreateStack},
|
||||
@@ -389,6 +405,7 @@ REGISTER_NATIVES(cellStackNatives)
|
||||
{"ArrayStack.PushString", PushStackString},
|
||||
{"ArrayStack.PushArray", PushStackArray},
|
||||
{"ArrayStack.Empty.get", IsStackEmpty},
|
||||
{"ArrayStack.BlockSize.get", GetStackBlockSize},
|
||||
|
||||
{NULL, NULL},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user