Skip to main content
SolarSharp provides a comprehensive implementation of the Lua standard library, organized into modular packages that can be selectively enabled using the CoreModules enum.

CoreModules Enum

The CoreModules enum allows fine-grained control over which standard library modules are loaded into your script environment. This is particularly useful for sandboxing and security.

Basic Modules

ModuleDescriptionFlag
BasicCore functions like print, type, tostring, assertCoreModules.Basic
GlobalConstsGlobal constants: _G, _VERSION, _SOLARSHARPCoreModules.GlobalConsts
TableIteratorsIterator functions: next, ipairs, pairsCoreModules.TableIterators
MetatablesMetatable operations: setmetatable, getmetatable, rawset, rawget, rawequal, rawlenCoreModules.Metatables
ErrorHandlingError handling: pcall, xpcallCoreModules.ErrorHandling

Package Modules

ModuleDescriptionFlag
StringString manipulation functionsCoreModules.String
TableTable manipulation functionsCoreModules.Table
MathMathematical functions and constantsCoreModules.Math
CoroutineCoroutine creation and managementCoreModules.Coroutine
Bit32Bitwise operationsCoreModules.Bit32
IOFile I/O operationsCoreModules.IO
OS_TimeTime and date functionsCoreModules.OS_Time
OS_SystemSystem operations (not available in Unity)CoreModules.OS_System
DebugDebugging utilities (limited support)CoreModules.Debug
JsonJSON parsing and serialization (SolarSharp extension)CoreModules.Json

LoadMethods

FlagDescription
LoadMethodsDynamic loading: load, loadsafe, loadfile, loadfilesafe, dofile, require

Presets

SolarSharp provides convenient presets for common use cases:

Preset_HardSandbox

CoreModules.Preset_HardSandbox = 
    GlobalConsts | TableIterators | String | Table | Basic | Math | Bit32
A restrictive sandbox with only pure computation capabilities. Suitable for untrusted code.

Preset_SoftSandbox

CoreModules.Preset_SoftSandbox = 
    Preset_HardSandbox | Metatables | ErrorHandling | 
    Coroutine | OS_Time | Json
Adds metaprogramming, coroutines, time functions, and JSON support while still restricting file and system access.

Preset_Default

CoreModules.Preset_Default = 
    Preset_SoftSandbox | LoadMethods | OS_System | IO
Includes everything except debug module. Warning: Allows unlimited system access.

Preset_Complete

CoreModules.Preset_Complete = Preset_Default | Debug
The complete standard library including debug utilities. Warning: Allows unlimited system access.

Usage Example

using SolarSharp.Interpreter;
using SolarSharp.Interpreter.Modules;

// Create a sandboxed script
var script = new Script(CoreModules.Preset_SoftSandbox);

// Or use specific modules
var customScript = new Script(
    CoreModules.Basic | 
    CoreModules.String | 
    CoreModules.Math | 
    CoreModules.Json
);

// Full standard library
var fullScript = new Script(CoreModules.Preset_Complete);

Important Notes

UTF-16 vs UTF-8

SolarSharp runs on .NET, which uses UTF-16 for strings internally. This differs from standard Lua’s UTF-8 encoding:
  • String length is measured in UTF-16 code units, not bytes
  • The string.byte() function returns UTF-16 code unit values
  • Pattern matching operates on UTF-16 characters
This is generally transparent for ASCII text but may affect behavior with Unicode characters.

Platform Limitations

  • IO and OS_System modules are not supported under Unity
  • Some debug functionality is platform-dependent
  • File operations require appropriate platform access configuration

Next Steps

Explore the individual module documentation:

Build docs developers (and LLMs) love