lib: add `NativeArray::length`
authorJean Privat <jean@pryen.org>
Thu, 17 Apr 2014 02:17:06 +0000 (22:17 -0400)
committerJean Privat <jean@pryen.org>
Thu, 17 Apr 2014 02:17:06 +0000 (22:17 -0400)
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 <jean@pryen.org>

lib/standard/collection/array.nit

index d40a220..6ae145d 100644 (file)
@@ -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