nanos world API Reference Unofficial documentation
Static function Shared 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

Lua
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

Loading a .lua file sandboxed
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...