SetNapiModuleCreator
SetNapiModuleCreator is a C++ template method used to register a "Creator". This creator is a callable object (like a function or lambda) responsible for creating and binding your custom native module's methods within the JavaScript environment.
This API is a C++ interface, leveraging templates and C++11 features to provide enhanced type safety and flexibility. It automatically deduces your module type and ensures it correctly inherits from LynxExtensionModule.
Method Signature
Parameters
Creator Signature
Your creator function must have the following signature:
env: TheNapi::Envenvironment handle, which is the context for interacting with the JavaScript engine.exports: ANapi::Valuerepresenting a JavaScript object that you should populate with your module's native functions and properties.module_name: The name of the module.module: A reference to your custom module instance.YourModuleTypemust be a class that inherits fromlynx::pub::LynxExtensionModule. The API enforces this constraint internally with astatic_assert.- Return Value: You must return the
exportsobject after populating it.
Usage
Call this method only after SetCModule, because registration immediately accesses the associated C module. The host integration should perform both calls after creating the C module and before returning it to Lynx.
Code Example
The following example demonstrates how to define a custom LynxExtensionModule and use SetNapiModuleCreator to expose a native method to JavaScript.
See Also
OnRuntimeAttach(): The Creator function is invoked after this callback, as the N-API environment is ready by then.
Compatibility
LCD tables only load in the browser