@thi.ng/wasm-api
Version:
Generic, modular, extensible API bridge and infrastructure for hybrid JS & WebAssembly projects
52 lines • 2.1 kB
TypeScript
import type { Fn, IDeref } from "@thi.ng/api";
import type { IWasmMemoryAccess } from "./api.js";
/**
* Generic pointer facility which on {@link Pointer.deref()} calls wrapper
* function (provided as ctor arg) to realise the pointer's target value. The
* pointer's target address can be accessed via {@link Pointer.addr}
* (read/write).
*
* @remarks
* The pointer always behaves like `volatile`, i.e. memoization of target values
* is purposfully avoided and the wrapper function is executed anew _each_ time
* the pointer is deref'd.
*
* Pointers with addr=0 are interpreted as null/optional pointers and
* {@link Pointer.deref} will return `undefined` in these cases.
*/
export declare class Pointer<T> implements IDeref<T | undefined> {
readonly mem: IWasmMemoryAccess;
readonly base: number;
readonly fn: Fn<number, T>;
constructor(mem: IWasmMemoryAccess, base: number, fn: Fn<number, T>);
get addr(): number;
set addr(addr: number);
get isNull(): boolean;
deref(): T | undefined;
}
/**
* Generic pointer facility for
* [`WASM64`](https://docs.thi.ng/umbrella/wasm-api-bindgen/variables/WASM64.html)
* target, which on {@link Pointer64.deref()} calls wrapper function (provided
* as ctor arg) to realize the pointer's target value. The pointer's target
* address can be accessed via {@link Pointer.addr} (read/write).
*
* @remarks
* The pointer always behaves like `volatile`, i.e. memoization of target values
* is purposefully avoided and the wrapper function is executed anew _each_ time
* the pointer is deref'd.
*
* Pointers with addr=0 are interpreted as null/optional pointers and
* {@link Pointer64.deref} will return `undefined` in these cases.
*/
export declare class Pointer64<T> implements IDeref<T | undefined> {
readonly mem: IWasmMemoryAccess;
readonly base: bigint;
readonly fn: Fn<bigint, T>;
constructor(mem: IWasmMemoryAccess, base: bigint, fn: Fn<bigint, T>);
get addr(): bigint;
set addr(addr: bigint);
get isNull(): boolean;
deref(): T | undefined;
}
//# sourceMappingURL=pointer.d.ts.map