mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-23 06:10:02 +08:00
- Extend native FFI with additional scalar widths and writable byte spans. - Compile stored text codecs and supported bundled module patterns without a JavaScript engine. - Document supported limits.
20 lines
996 B
TypeScript
20 lines
996 B
TypeScript
declare function nativeCreate(): number;
|
|
declare function nativeDestroy(handle: number): void;
|
|
declare function nativeAppend(handle: number, text: string): void;
|
|
declare function nativeRead(handle: number, target: Uint8Array): number;
|
|
declare function nativeRender(text: string, target: Uint8Array): number;
|
|
|
|
const handle = nativeCreate();
|
|
if (handle === 0) throw new Error("OpenTUI text buffer creation failed");
|
|
// Temporary strings exercise the adapter's retained copies.
|
|
nativeAppend(handle, ["Hello", ", "].join(""));
|
|
nativeAppend(handle, ["scriptc!", " café 🎉"].join(""));
|
|
const output = new Uint8Array(128);
|
|
const written = nativeRead(handle, output.subarray(3));
|
|
console.log(new TextDecoder().decode(output.subarray(3, 3 + written)));
|
|
console.log(output[0], output[1], output[2]);
|
|
nativeDestroy(handle);
|
|
const frame = new Uint8Array(256);
|
|
const frameLength = nativeRender("Hello, static OpenTUI!", frame);
|
|
console.log(new TextDecoder().decode(frame.subarray(0, frameLength)).trim());
|