@rezi-ui/native is the Node.js N-API binding that connects the TypeScript core to the Zireael C rendering engine. This addon provides FFI functions for engine lifecycle, frame submission, and event polling.
Overview
Package:@rezi-ui/nativeLocation:
packages/native/Binding: Node-API (N-API)
Engine: Zireael (C implementation) Responsibilities:
- Engine lifecycle (create, destroy)
- Frame submission (drawlist execution)
- Event polling (keyboard, mouse, resize)
- Terminal state management (raw mode, alternate screen)
- SharedArrayBuffer interop
FFI Functions
engine_create(config)
Creates and initializes a Zireael engine instance.
Parameters:
EngineHandle (opaque integer handle)
Errors:
ERR_OOM— Memory allocation failedERR_PLATFORM— Terminal initialization failed
engine_destroy(handle)
Destroys an engine instance and frees resources.
Parameters:
handle: EngineHandle— Engine instance to destroy
ZrResult.OK on success
Errors:
ERR_INVALID_ARGUMENT— Invalid or null handle
engine_present(handle, drawlist)
Submits a ZRDL drawlist and presents the frame to the terminal.
Parameters:
handle: EngineHandle— Engine instancedrawlist: Uint8Array | SharedArrayBuffer— ZRDL binary buffer
ZrResult.OK on success
Errors:
ERR_INVALID_ARGUMENT— Invalid handle or null bufferERR_FORMAT— Malformed ZRDL header or magic mismatchERR_UNSUPPORTED— Unknown drawlist version or opcodeERR_LIMIT— Drawlist exceeds engine caps
- Exactly one write to terminal on success
- Zero writes on failure
- No partial ANSI sequences
engine_poll_events(handle, buffer)
Polls terminal for input events and writes ZREV batch to buffer.
Parameters:
handle: EngineHandle— Engine instancebuffer: Uint8Array— Destination buffer for ZREV batch
> 0— Number of bytes written to buffer0— No events available< 0— Error code (ZrResult)
ERR_INVALID_ARGUMENT— Invalid handle or null bufferERR_LIMIT— Buffer too small for event batchERR_PLATFORM— Terminal read failed
0 immediately.
engine_get_size(handle)
Returns the current terminal size.
Returns:
engine_set_raw_mode(enabled)
Toggles terminal raw mode (no line buffering, no echo).
Parameters:
enabled: boolean— Enable or disable raw mode
ZrResult.OK on success
Errors:
ERR_PLATFORM— Terminal ioctl failed
engine_set_alternate_screen(enabled)
Toggles alternate screen buffer.
Parameters:
enabled: boolean— Enable or disable alternate screen
ZrResult.OK on success
SharedArrayBuffer Support
The addon supports SharedArrayBuffer for zero-copy drawlist submission:- Zero-copy submission
- No transfer overhead
- Faster frame times
- Node.js 16+ or
--experimental-shared-array-buffer - SharedArrayBuffer available in environment
Thread Safety
The native addon is not thread-safe. All FFI calls must be made from the same thread that created the engine. Worker mode: Engine runs on dedicated worker thread. Main thread never calls FFI directly. Inline mode: Engine runs on main thread. All FFI calls from main thread.Error Handling
All FFI functions returnZrResult (int32):
Building the Addon
The addon is built usingnode-gyp:
build/Release/rezi_native.node— Native addon
- Node.js headers
- C compiler (GCC, Clang, MSVC)
- Python 3 (for node-gyp)
Platform Support
| Platform | Status | Notes |
|---|---|---|
| Linux | Supported | Tested on Ubuntu 20.04+ |
| macOS | Supported | Tested on macOS 11+ |
| Windows | Supported | Requires Visual Studio 2019+ |
| WSL | Supported | Works but with scheduler jitter |
ABI Versioning
The addon exports ABI version constants:Debug Utilities
The addon provides debug utilities whenREZI_DEBUG=1:
Related Documentation
- Node.js Backend — Backend implementation
- Worker Model — Thread ownership
- Protocol Overview — Binary formats
- ABI Pins — Version constants