mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-18 09:21:35 +00:00
support normal arrays
This commit is contained in:
@ -45,6 +45,10 @@ export function sum(arr: Int32Array): i32 {
|
||||
return v;
|
||||
}
|
||||
|
||||
export function changeLength(arr: Array<i32>, length: i32): void {
|
||||
arr.length = length;
|
||||
}
|
||||
|
||||
export function varadd(a: i32 = 1, b: i32 = 2): i32 {
|
||||
return a + b;
|
||||
}
|
||||
@ -62,3 +66,4 @@ export function dotrace(num: f64): void {
|
||||
export const INT32ARRAY_ID = idof<Int32Array>();
|
||||
export const UINT32ARRAY_ID = idof<Uint32Array>();
|
||||
export const FLOAT32ARRAY_ID = idof<Float32Array>();
|
||||
export const ARRAYI32_ID = idof<Array<i32>>();
|
||||
|
Binary file not shown.
@ -72,6 +72,17 @@ assert.strictEqual(module.__getString(module.COLOR), "red");
|
||||
try { module.__release(ref); assert(false); } catch (e) {};
|
||||
}
|
||||
|
||||
// should be able to work with normal arrays
|
||||
{
|
||||
let arr = [1, 2, 3, 4, 5];
|
||||
let ref = module.__retain(module.__allocArray(module.ARRAYI32_ID, arr));
|
||||
assert(module.__instanceof(ref, module.ARRAYI32_ID));
|
||||
module.changeLength(ref, 3);
|
||||
assert.deepEqual(module.__getArray(ref), [1, 2, 3]);
|
||||
module.__release(ref);
|
||||
try { module.__release(ref); assert(false); } catch (e) {};
|
||||
}
|
||||
|
||||
// should be able to correctly call a function with variable arguments
|
||||
assert.strictEqual(module.varadd(), 3);
|
||||
assert.strictEqual(module.varadd(2, 3), 5);
|
||||
|
Reference in New Issue
Block a user