Builtin Library
README.md
script_context
Builds the environment of a file the engine loads itself, from the context its asset type declares.
An asset type states, in the contexts: block of its type.yaml, which of its files run in an environment of their own and what that environment holds:
contexts:
- name: sceneBuild
file: "build.luau"
surface: "scene's `build.luau`"
globals:
build: "the build surface ..."
hooks: [content, editorOnly]
modules: true
nameis the context's name.fileis the file of the type's asset folder that runs in it.surfaceis how a diagnostic names that file.globalsare the names the loader binds into each chunk, each with the note an unknown-global message gives a file that lacks it.hooksare the functions the engine calls by name, which the language server does not report as unused.modules: truesays the loader binds the modules that join the context.
A module joins a context with a line in its leading comment block, and its exports are then globals in every file of that context:
--!context sceneBuild sceneModule
local M = {}
function M.Mesh(geometry, material) ... end
return M
A name that starts with _ stays inside its module.
ScriptContext.bind(env, path, values) binds a file's context into the environment it runs in: the loader's own values, which must be names the context declares, then each joining module's exports. Two sources binding one name is an error naming both. It returns the modules it bound, so a loader can call what they export around a run of the file (a scene build calls _beginRun and _finish).
asset.context(path) reads the declaration a file runs in, and the language server declares the same names from it, so what a file may use and what it finds when it runs are one answer.