Lynx Native Libraries
A Lynx native library is a native library that registers capabilities with the Lynx runtime. It can be linked into an embedder directly, or distributed with an application package. In Lynxtron apps, it is often delivered through npm so the host build can install, stage, and load the platform artifact.
native-module: native APIs exposed to Lynx JS throughNativeModules.<ModuleName>.custom element: custom native elements exposed as Lynx elements. The concrete tag name is declared by the library and then used like a normal Lynx element.
This page focuses on how Lynxtron consumes these packages. For authoring and package layout details, see:
Loading Model
The basic model is static registration plus host-side native library loading:
- The library's C/C++ code registers Lynx capabilities with static registration
macros such as
LYNX_REGISTER_NATIVE_MODULE(...)andLYNX_REGISTER_ELEMENT(...). - The host integration layer loads the native binary for the current platform. In Lynxtron this can be generated by AutoLink from package metadata, or implemented by application code.
- If the Lynxtron artifact is a
.nodefile, the host can load it through normal Node.jsrequire(). Loading the binary activates the static Lynx registrations in the Lynx runtime, so app code can useNativeModules.<ModuleName>and custom elements.
The .node file can also expose a normal Node-API addon surface when the
library needs host-side entry points. If the library only needs to make Lynx
capabilities available, the Node-API addon surface can be empty; the load side
effect is enough to activate static registration.
Runtime Boundaries
Lynxtron has both a Node.js host and a Lynx JS runtime. A native library must keep these two environments separate.
Do not make capabilities available in the Lynx runtime by calling low-level registration APIs from application code. The library registers them in native code; the application only needs to load the library.
Create and Use a Lynx Library in Lynxtron with AutoLink
The steps below show the minimal Lynxtron path.
Create an AutoLink Library for Lynxtron
Create a Lynx library with Lynxtron metadata and a minimal native module or element scaffold. For the full package format, see AutoLink.
Implement Native Module or Element
The generated AutoLink library keeps the cross-platform native implementation
under shared/ and the Lynxtron loading entry under lynxtron/:
Keep the generated implementation for a quick smoke test, or edit
shared/nativeModule/ for a native module and shared/elements/ for an
element. To learn how to implement each capability, see
Native Modules and
Custom Element.
Build and Publish
Build the current OS/architecture artifact and pack it as the package that a Lynxtron app can install:
Use npm publish instead of npm pack when publishing to a real registry.
Consume the Lynx Library in Lynxtron
Install the packed library into an existing Lynxtron app. If you need a base app
first, follow Getting Started. This AutoLink flow
depends on pluginLynxtron() in the host Rspack config; the plugin provides
Lynxtron-side AutoLink loading:
After the host build loads the library through AutoLink, the capabilities are available in the Lynx runtime: app code can call the native module or render the custom element.