From 7fd86cc8f773f6380f1d00bd488ec10a21f08468 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 16 Apr 2014 22:17:06 -0400 Subject: [PATCH] lib: add `NativeArray::length` Engines should be able to store the allocated size. Unlike `NativeString` that is a char*, `NativeArray` is a special Nit opaque structure. Signed-off-by: Jean Privat --- lib/standard/collection/array.nit | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/standard/collection/array.nit b/lib/standard/collection/array.nit index d40a220..6ae145d 100644 --- a/lib/standard/collection/array.nit +++ b/lib/standard/collection/array.nit @@ -650,8 +650,14 @@ interface ArrayCapable[E] protected fun calloc_array(size: Int): NativeArray[E] is intern end -# Native C array (void ...). +# Native Nit array +# Access are unchecked and it has a fixed size +# Not for public use: may become private. universal NativeArray[E] + # The length of the array + fun length: Int is intern + # Use `self` to initialize a standard Nit Array. + fun to_a: Array[E] do return new Array[E].with_native(self, length) fun [](index: Int): E is intern fun []=(index: Int, item: E) is intern fun copy_to(dest: NativeArray[E], length: Int) is intern -- 1.7.9.5