Represents a `Il2CppArraySize`.
| 14 | |
| 15 | /** Represents a `Il2CppArraySize`. */ |
| 16 | class Il2CppArray extends native_struct.NativeStruct { |
| 17 | /** @internal */ |
| 18 | static from(klass, lengthOrElements) { |
| 19 | const length = typeof lengthOrElements == "number" ? lengthOrElements : lengthOrElements.length; |
| 20 | const array = new Il2Cpp.Array(Il2Cpp.Api._arrayNew(klass, length)); |
| 21 | if (Array.isArray(lengthOrElements)) { |
| 22 | array.elements.write(lengthOrElements); |
| 23 | } |
| 24 | return array; |
| 25 | } |
| 26 | |
| 27 | /** @internal Gets a pointer to the first element of the current array. */ |
| 28 | get elements() { |
| 29 | return new Il2Cpp.Pointer(Il2Cpp.Api._arrayGetElements(this), this.elementType); |
| 30 | } |
| 31 | |
| 32 | /** Gets the size of the object encompassed by the current array. */ |
| 33 | get elementSize() { |
| 34 | return this.elementType.class.arrayElementSize; |
| 35 | } |
| 36 | |
| 37 | /** Gets the type of the object encompassed by the current array. */ |
| 38 | get elementType() { |
| 39 | return this.object.class.type.class.baseType; |
| 40 | } |
| 41 | |
| 42 | /** Gets the total number of elements in all the dimensions of the current array. */ |
| 43 | get length() { |
| 44 | return Il2Cpp.Api._arrayGetLength(this); |
| 45 | } |
| 46 | |
| 47 | /** Gets the encompassing object of the current array. */ |
| 48 | get object() { |
| 49 | return new Il2Cpp.Object(this); |
| 50 | } |
| 51 | |
| 52 | /** Gets the element at the specified index of the current array. */ |
| 53 | get(index) { |
| 54 | if (index < 0 || index >= this.length) { |
| 55 | console.raise(`cannot get element at index ${index}: array length is ${this.length}`); |
| 56 | } |
| 57 | return this.elements.get(index); |
| 58 | } |
| 59 | |
| 60 | /** Sets the element at the specified index of the current array. */ |
| 61 | set(index, value) { |
| 62 | if (index < 0 || index >= this.length) { |
| 63 | console.raise(`cannot get element at index ${index}: array length is ${this.length}`); |
| 64 | } |
| 65 | this.elements.set(index, value); |
| 66 | } |
| 67 | |
| 68 | /** */ |
| 69 | toString() { |
| 70 | return this.isNull() ? "null" : `[${this.elements.read(this.length, 0)}]`; |
| 71 | } |
| 72 | |
| 73 | /** Iterable. */ |
nothing calls this directly
no outgoing calls
no test coverage detected