GdlrModuleDefinition

Inherits: RefCounted < Object

Configures a module at runtime.

Description

A module definition wraps a module script and adds imports, providers, exports, and tree exports with chained calls. Use it when a module needs configuration that static declarations cannot express, for example a value known only at startup:

class_name ConfigModule
extends GdlrModule

static var PROVIDERS = {&"api_url": {"use": "http://localhost"}}
static var TREE_EXPORTS = [&"api_url"]

static func for_root(api_url: String) -> GdlrModuleDefinition:
    var definition := GdlrModuleDefinition.new()
    definition.ModuleScript = ConfigModule
    return definition.providers({&"api_url": {"use": api_url}})

Pass the definition to GdlrModuleManager.mount() or list it in the IMPORTS of another module. Godular merges the static declarations of the script with the definition. Providers in the definition replace static providers with the same token.

Tutorials

Properties

Methods


Property Descriptions

GDScript ModuleScript 🔗

The script that contains the module class.


Method Descriptions

Dictionary[GDScript, GdlrModuleDefinition] get_imports() 🔗

Returns the imported module definitions keyed by module script. The dictionary is complete after GdlrModuleGraph.compile().


Dictionary[Variant, bool] get_exports() 🔗

Returns the exported tokens as dictionary keys.


Dictionary[Variant, Dictionary] get_providers() 🔗

Returns the provider configurations keyed by token. See GdlrModule for the configuration keys.


Dictionary[Variant, bool] get_tree_exports() 🔗

Returns the tree export tokens as dictionary keys.


GdlrModuleDefinition imports(imports_: Array = []) 🔗

Adds imported modules and returns this definition. Each entry is a module script, a GdlrModuleDefinition, or a GdbPromise that resolves to one of them.


GdlrModuleDefinition providers(providers_: Dictionary = {}) 🔗

Adds provider configurations keyed by token and returns this definition. See GdlrModule for the configuration keys.


GdlrModuleDefinition tree_exports(tree_exports_: Array = []) 🔗

Adds tokens that GdlrModuleManager.request() can return, and returns this definition.


GdlrModuleDefinition exports(exports_: Array = []) 🔗

Adds tokens that importing modules can consume, and returns this definition.


GDScript get_module_class(ModuleScript_: GDScript) static 🔗

Returns the class that Godular instantiates for a module script. When ModuleScript_ extends GdlrModule, the method returns it. Otherwise the method returns the first inner class of the script that extends GdlrModule, and fails when there is none.