For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/api/lynx-native-api/lynx-extension-module/on-runtime-init.md.
Lynx
  • English
  • OnRuntimeInit

    OnRuntimeInit is a virtual lifecycle method in the LynxExtensionModule class. It is called by the Lynx framework when the BTS (Background Thread Script) Runtime instance is created and initialized for the associated LynxView.

    This callback is always invoked on the UI thread. It signals that the JavaScript execution environment is being set up, but it is not yet ready to execute code. This is an early opportunity to prepare any resources that your module might need to interact with the runtime later.

    Method Signature

    virtual void OnRuntimeInit();

    Usage

    Override this method in your LynxExtensionModule subclass to perform pre-setup tasks before the JavaScript runtime is fully active. For example, you might prepare data structures or initialize native modules that will later be exposed to JavaScript.

    Example

    #include "lynx_extension_module.h"
    
    class MyExtensionModule : public lynx::pub::LynxExtensionModule {
    public:
        void OnRuntimeInit() override {
            // The BTS runtime is being initialized.
            // This is called on the UI thread.
            printf("MyExtensionModule: BTS Runtime is initializing.\\n");
            // Prepare any runtime-dependent resources here.
        }
    
        // ... other lifecycle methods
    };

    Lifecycle Sequence

    The OnRuntimeInit callback occurs in the following sequence:

    1. OnLynxViewCreate (UI Thread)
    2. OnRuntimeInit (UI Thread)
    3. OnRuntimeAttach (BTS Thread)
    4. OnRuntimeReady (BTS Thread)

    See Also

    Compatibility

    LCD tables only load in the browser

    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.