dcodeIO 9c770d801e Add initial newArray and getArray helpers to loader
Essentially creates an unmanaged typed array in memory that one can work with and free again respectively obtain from the AS side. No support for GC or generic arrays yet, and is likely to change substentially once WASM GC becomes a thing.
2018-09-18 15:17:44 +02:00

53 lines
993 B
TypeScript

import "allocator/tlsf";
export { memory };
export const COLOR: string = "red";
export function strlen(str: string): i32 {
return str.length;
}
export namespace math {
export function add(a: i32, b: i32): i32 {
return a + b;
}
}
export class Car {
static readonly MAX_DOORS: i32 = 5;
static readonly usualDoors: i32 = 3;
numDoors: i32;
private doorsOpen: bool = false;
get isDoorsOpen(): bool { return this.doorsOpen; }
set isDoorsOpen(value: bool) { this.doorsOpen = value; }
constructor(numDoors: i32) {
this.numDoors = numDoors;
}
openDoors(): bool {
if (this.doorsOpen) return false;
this.doorsOpen = true;
return true;
}
closeDoors(): bool {
if (!this.doorsOpen) return false;
this.doorsOpen = false;
return true;
}
dispose(): void {
memory.free(changetype<usize>(this));
}
}
export function sum(arr: Int32Array): i32 {
var v = 0;
for (let i = 0, k = arr.length; i < k; ++i) v += arr[i];
return v;
}