support normal arrays

This commit is contained in:
dcode
2019-05-25 01:14:26 +02:00
parent 9620f18249
commit c34ed66fd9
42 changed files with 831 additions and 468 deletions

View File

@ -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>>();

View File

@ -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);