Static function
Slow
Package.LoadFile
Compiles a .lua file and returns a function to run it. To be used for loading files in a sandboxed environment.<br/><br/>Supports the same searchers as <a href="#static-function-require">Package.Require</a>.
Syntax
Package.LoadFile(file_path)
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
file_path
|
string | — | Path to the script file to compile |
Returns
- function the compiled function to run the script, allowing you to pass a environment env table for the script
Examples
local func = Package.LoadFile("MyScript.lua"),,-- Only allows this file to access Console,local my_env = { Console = Console },,local content = func(my_env),,-- Access all global variables set by the script in my_env,my_env.GlobalVariableFromFile...