Generated Loader
Lux replaces hand-written GMod loader code with a generated loader tree. The
goal is to remove repeated if SERVER then AddCSLuaFile(...) end boilerplate
and make load order a compiler-owned property. autorun is only an optional
thin forwarder into that loader tree.
Generated files are still ordinary Lua, but developers should treat them as build output.
Loader Files
Loader files live under runtime_base:
When autorun = true, Lux also writes a small addon-style forwarder:
Set autorun = false when an existing gamemode, framework, or hand-written
entry point should include the generated loaders itself. This does not disable
the Lux loader.
AddCSLuaFile Batching
The generator batches client-send files instead of repeating the same if SERVER guard on every line.
This keeps generated loaders readable even when a project has many client artifacts.
Module Factories
Modules are emitted as factories. The loader provides __lux_import; modules
return their export table.
The global environment does not get a public Lux import function. Import stays inside generated loader scope.
Private Registry
The loader stores module exports in a bundle-private registry.
Using a local registry avoids cross-addon collisions while keeping generated Lua simple.
Registering Modules
Each emitted module file returns a factory. The loader calls it once and stores the exports.
Import order is therefore deterministic: dependencies are registered before modules that import them.
Load Order
Lux computes load order from:
- package dependency graph;
- module import graph;
- realm artifacts;
- module entry part order;
- local
beforeandafterpart constraints.
Developers should not encode load order through artificial 00_, 10_, or
20_ file prefixes. Use part order in the entry part when initialization
order matters.
Do Not Edit Generated Files
Generated files are marked clearly.
If generated Lua looks wrong, the fix belongs in source lowering, module graph resolution, or loader generation.