From 0507a7b971cddb3ae15fd8758a2668287962da23 Mon Sep 17 00:00:00 2001 From: Ivan Mogilko Date: Fri, 20 Dec 2024 13:10:43 +0300 Subject: [PATCH] Plugin API: added IAGSEngine.GetDynamicArrayLength() --- Engine/plugin/agsplugin.cpp | 10 ++++++++++ Engine/plugin/agsplugin.h | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Engine/plugin/agsplugin.cpp b/Engine/plugin/agsplugin.cpp index 4ae1bfe718..c64159d82f 100644 --- a/Engine/plugin/agsplugin.cpp +++ b/Engine/plugin/agsplugin.cpp @@ -868,6 +868,16 @@ void *IAGSEngine::CreateDynamicArray(size_t elem_count, size_t elem_size, bool i return obj_ref.Obj; } +size_t IAGSEngine::GetDynamicArrayLength(const void *arr) +{ + return arr ? CCDynamicArray::GetHeader(arr).ElemCount : 0u; +} + +size_t IAGSEngine::GetDynamicArraySize(const void *arr) +{ + return arr ? CCDynamicArray::GetHeader(arr).TotalSize : 0u; +} + // *********** General plugin implementation ********** void pl_stop_plugins() { diff --git a/Engine/plugin/agsplugin.h b/Engine/plugin/agsplugin.h index 0be76b92bb..b717e28f87 100644 --- a/Engine/plugin/agsplugin.h +++ b/Engine/plugin/agsplugin.h @@ -680,7 +680,12 @@ class IAGSEngine { // You may return this pointer from the registered plugin's function just like any other // managed object pointer. AGSIFUNC(void*) CreateDynamicArray(size_t elem_count, size_t elem_size, bool is_managed_type); - + // Retrieves dynamic array's length (number of elements). + // You should pass a dynamic array object either received from the engine in your registered + // script function, or created by you with CreateDynamicArray(). + AGSIFUNC(size_t) GetDynamicArrayLength(const void *arr); + // Retrieves dynamic array's size (total capacity in bytes). + AGSIFUNC(size_t) GetDynamicArraySize(const void *arr); };