Luau
API for creating and running isolated Luau environments.
Functions
Luau.createSandbox
Creates a new Luau sandbox.
Luau.createSandbox(): sandbox
Returns
Name | Type | Description |
---|---|---|
sandbox | sandbox | The new sandbox. |
Luau.setSandboxGlobals
Sets the global environment for a sandbox.
Luau.setSandboxGlobals(sandbox: sandbox, globals: table)
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
sandbox | sandbox | Required | The sandbox to set the globals for. |
globals | table | Required | The globals to set. |
Luau.getScriptPath
Gets the path of the current caller, or alternatively, the path of the caller referenced by the level.
Luau.getScriptPath(level?: number): string?
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
level | number? | 1 | The level of the caller to get the path of. |
Returns
Name | Type | Description |
---|---|---|
path | string? | The path of the caller. |
Luau.getScriptDirectory
Gets the directory of the current caller, or alternatively, the directory of the caller referenced by the level.
Luau.getScriptDirectory(level?: number): string?
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
level | number? | 1 | The level of the caller to get the directory of. |
Returns
Name | Type | Description |
---|---|---|
directory | string? | The directory of the caller. |
Luau.run
Runs a script in a sandbox. The given path is used when resolving relative file paths, such as when calling Filesystem.toAbsolutePath
.
Luau.run(sandbox: sandbox, scriptPath: string, sourceCode: string): any
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
sandbox | sandbox | Required | The sandbox to run the script in. The executed script has access to the sandbox using the THIS_SANDBOX global. |
scriptPath | string | Required | The path to use for the script. The executed script has access to the path using the SCRIPT_PATH global. |
sourceCode | string | Required | The source code of the script. |
Returns
Name | Type | Description |
---|---|---|
result | any | The result of the script. |
Luau.runFile
Runs a script file in a sandbox.
Luau.runFile(sandbox: sandbox, path: string): any
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
sandbox | sandbox | Required | The sandbox to run the script in. |
path | string | Required | The path to the script file. |
Returns
Name | Type | Description |
---|---|---|
result | any | The result of the script. |
Luau.createRequire
Creates a function which runs each required module in a sandbox and caches the result.
Luau.createRequire(sandbox: sandbox): fun(path: string): any
Parameters
Name | Type | Default Value | Description |
---|---|---|---|
sandbox | sandbox | Required | The sandbox to run the required modules in. |
Returns
Name | Type | Description |
---|---|---|
require | fun(path: string): any | The require function. |