module program parameters




Module and Program Parameters

Some Jai modules expose compile-time parameters through their #module_parameters. You pass those parameters at the import site by adding an argument list after the module import:

    
#import "Basic"()(MEMORY_DEBUGGER = true);
    

These values are compile-time constants. The expression on the right side must be resolvable at the point where the import is processed.

Program Parameters

Some module parameters effectively configure behavior for the whole program. Basic.MEMORY_DEBUGGER is an example: it controls whether Basic installs allocation-checking hooks around alloc, free, and realloc. Parameters like this should be supplied from the main program. If another imported module writes #import "Basic";, that import does not need to repeat the parameter list.

Because the parameter expression is evaluated in the importing scope, any constants it uses must already be visible. This often matters for build configuration constants.

    
#import "tbx/engine";
#import "Basic"()(MEMORY_DEBUGGER = BUILD_TYPE == .DEVELOPMENT);
    

In this example, tbx/engine exports BUILD_TYPE, so importing it first makes BUILD_TYPE visible to the main program before the parameterized Basic import is evaluated. This can look surprising if tbx/engine also imports Basic internally, but the main program is still the place that supplies the program-level parameter value.

Reversing the order is different:

    
#import "Basic"()(MEMORY_DEBUGGER = BUILD_TYPE == .DEVELOPMENT);
#import "tbx/engine";
    

Here, BUILD_TYPE has not been brought into scope yet when the compiler tries to evaluate the Basic import parameters. Depending on the surrounding imports, this may show up as an undeclared identifier or as a circular dependency report while the compiler tries to resolve the missing dependency through modules that themselves depend on Basic.

Rule of Thumb

Put build settings used by module parameters somewhere the main program can see before the parameterized import. If a setting is exported by another module, import that module first, then import the parameterized module from the main program. Avoid making the parameterized module depend on the module that defines the setting; that shape can create circular dependencies.