CoreModules enum is a flags enumeration that specifies which standard Lua libraries should be loaded when creating a Script instance.
Usage
Pass aCoreModules value to the Script constructor:
Module Flags
No modules loaded. Creates a completely empty environment.
Global constants:
_G, _VERSION, and _SOLARSHARP.Table iterators:
next, ipairs, and pairs.Metatable methods:
setmetatable, getmetatable, rawset, rawget, rawequal, and rawlen.The
string package with all string manipulation functions.Load methods:
load, loadsafe, loadfile, loadfilesafe, dofile, and require.Warning: Allows dynamic code execution and file system access.The
table package for table manipulation.Basic methods:
assert, collectgarbage, error, print, select, type, tonumber, and tostring.Error handling methods:
pcall and xpcall.The
math package with all math functions.The
coroutine package for coroutine management.The
bit32 package for bitwise operations.Time methods of the
os package: clock, difftime, date, and time.Safe for sandboxed environments.System methods of the
os package (excluding time methods).Warning: Not supported under Unity. Provides system-level access.The
io and file packages for file I/O.Warning: Not supported under Unity. Provides file system access.The
debug package (limited support).The
json package (introduced by SolarSharp).Presets
A strict sandbox preset for untrusted code.Includes:
GlobalConsts, TableIterators, String, Table, Basic, Math, Bit32Use for: Running untrusted user scripts with minimal system access.A softer sandbox with more features.Includes:
Preset_HardSandbox + Metatables, ErrorHandling, Coroutine, OS_Time, JsonUse for: Semi-trusted environments where you want Lua features but not file system access.The default preset with nearly everything except debug.Includes:
Preset_SoftSandbox + LoadMethods, OS_System, IOWarning: Allows unlimited system access. Only use with trusted code.Everything including debug.Includes:
Preset_Default + DebugWarning: Full access to everything. Only for development/debugging.Examples
Minimal Environment
Custom Combination
Secure Sandbox
Game Modding Environment
Development Environment
Testing Individual Modules
Security Considerations
Safe Modules (Sandbox-Friendly)
Basic(exceptdofile/loadwhich are in LoadMethods)StringTableMathBit32GlobalConstsTableIteratorsMetatablesErrorHandlingCoroutineOS_TimeJson
Unsafe Modules (System Access)
LoadMethods- Dynamic code execution, file loadingOS_System- Shell command execution, process controlIO- File system accessDebug- Can inspect/modify program state