Bicameral Engine
GPU-resident engine for a magic-research open-world game
Loading...
Searching...
No Matches
bicameral::script::LuauSandbox Class Reference

#include <luau_sandbox.h>

Collaboration diagram for bicameral::script::LuauSandbox:
[legend]

Public Member Functions

 ~LuauSandbox ()
 LuauSandbox (const LuauSandbox &)=delete
LuauSandbox & operator= (const LuauSandbox &)=delete
std::expected< void, ScriptError > RegisterFunction (const char *tableName, const char *name, HostFunction function, void *context)
void Seal ()
std::expected< RunResult, ScriptError > Run (std::string_view chunkName, std::string_view source, const RunOptions &options={})
bool IsSealed () const
uint64_t MemoryBytes () const

Static Public Member Functions

static std::expected< std::unique_ptr< LuauSandbox >, std::string > Create (SandboxLimits limits)
static void * HostContext (lua_State *state)

Private Member Functions

 LuauSandbox (SandboxLimits limits)
std::expected< void, std::string > OpenLibraries ()
void ReseedRandom ()
std::expected< RunResult, ScriptError > RunThread (lua_State *thread, std::string_view chunkName, const char *bytecode, size_t bytecodeSize, const RunOptions &options)
std::expected< RunResult, ScriptError > CollectResults (lua_State *thread, std::string_view chunkName, const RunOptions &options)
void BeginModules (lua_State *thread, const ModuleResolver *modules)
void EndModules ()
std::expected< void, std::string > LoadModule (lua_State *state, std::string_view name)
std::expected< void, std::string > RunModule (lua_State *state, const std::string &chunkName, std::string_view source)

Static Private Member Functions

static void * Allocate (void *userData, void *pointer, size_t oldSize, size_t newSize)
static void Interrupt (lua_State *state, int gc)
static int Print (lua_State *state)
static int Require (lua_State *state)

Private Attributes

SandboxLimits m_limits
lua_State * m_state = nullptr
bool m_sealed = false
uint64_t m_memoryBytes = 0
uint64_t m_safepointCount = 0
bool m_safepointExceeded = false
bool m_memoryExceeded = false
std::string m_currentChunk
const ModuleResolver * m_modules = nullptr
int m_moduleCacheRef = 0
std::vector< std::string > m_moduleLoading

Detailed Description

Definition at line 82 of file luau_sandbox.h.

Constructor & Destructor Documentation

◆ ~LuauSandbox()

bicameral::script::LuauSandbox::~LuauSandbox ( )

Definition at line 175 of file luau_sandbox.cpp.

References m_state.

◆ LuauSandbox() [1/2]

bicameral::script::LuauSandbox::LuauSandbox ( const LuauSandbox & )
delete

References LuauSandbox().

Referenced by Allocate(), Create(), Interrupt(), LuauSandbox(), operator=(), Print(), and Require().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LuauSandbox() [2/2]

bicameral::script::LuauSandbox::LuauSandbox ( SandboxLimits limits)
explicitprivate

Definition at line 173 of file luau_sandbox.cpp.

References m_limits.

Member Function Documentation

◆ Allocate()

void * bicameral::script::LuauSandbox::Allocate ( void * userData,
void * pointer,
size_t oldSize,
size_t newSize )
staticprivate

Definition at line 480 of file luau_sandbox.cpp.

References LuauSandbox().

Referenced by Create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BeginModules()

void bicameral::script::LuauSandbox::BeginModules ( lua_State * thread,
const ModuleResolver * modules )
private

Definition at line 355 of file luau_sandbox.cpp.

References m_moduleCacheRef, m_moduleLoading, m_modules, m_state, and Require().

Referenced by Run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CollectResults()

std::expected< RunResult, ScriptError > bicameral::script::LuauSandbox::CollectResults ( lua_State * thread,
std::string_view chunkName,
const RunOptions & options )
nodiscardprivate

Definition at line 328 of file luau_sandbox.cpp.

References bicameral::script::RunOptions::captureValues, m_safepointCount, bicameral::script::RunResult::returns, bicameral::script::Runtime, bicameral::script::RunResult::safepointCount, and bicameral::script::RunResult::values.

Referenced by RunThread().

Here is the caller graph for this function:

◆ Create()

std::expected< std::unique_ptr< LuauSandbox >, std::string > bicameral::script::LuauSandbox::Create ( SandboxLimits limits)
staticnodiscard

Definition at line 180 of file luau_sandbox.cpp.

References Allocate(), Interrupt(), and LuauSandbox().

Referenced by bicameral::script::anonymous_namespace{reaction_table_loader.cpp}::LoadPackageSet().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EndModules()

void bicameral::script::LuauSandbox::EndModules ( )
private

Definition at line 370 of file luau_sandbox.cpp.

References m_moduleCacheRef, m_moduleLoading, m_modules, and m_state.

Referenced by Run().

Here is the caller graph for this function:

◆ HostContext()

void * bicameral::script::LuauSandbox::HostContext ( lua_State * state)
staticnodiscard

Definition at line 258 of file luau_sandbox.cpp.

◆ Interrupt()

void bicameral::script::LuauSandbox::Interrupt ( lua_State * state,
int gc )
staticprivate

Definition at line 508 of file luau_sandbox.cpp.

References LuauSandbox().

Referenced by Create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsSealed()

bool bicameral::script::LuauSandbox::IsSealed ( ) const
inlinenodiscard

Definition at line 106 of file luau_sandbox.h.

References m_sealed.

Referenced by bicameral::script::LoadPackages().

Here is the caller graph for this function:

◆ LoadModule()

std::expected< void, std::string > bicameral::script::LuauSandbox::LoadModule ( lua_State * state,
std::string_view name )
nodiscardprivate

Definition at line 399 of file luau_sandbox.cpp.

References m_moduleCacheRef, m_moduleLoading, m_modules, and RunModule().

Here is the call graph for this function:

◆ MemoryBytes()

uint64_t bicameral::script::LuauSandbox::MemoryBytes ( ) const
inlinenodiscard

Definition at line 107 of file luau_sandbox.h.

References m_memoryBytes.

◆ OpenLibraries()

std::expected< void, std::string > bicameral::script::LuauSandbox::OpenLibraries ( )
nodiscardprivate

Definition at line 197 of file luau_sandbox.cpp.

References m_state, and Print().

Here is the call graph for this function:

◆ operator=()

LuauSandbox & bicameral::script::LuauSandbox::operator= ( const LuauSandbox & )
delete

References LuauSandbox().

Here is the call graph for this function:

◆ Print()

int bicameral::script::LuauSandbox::Print ( lua_State * state)
staticprivate

Definition at line 523 of file luau_sandbox.cpp.

References bicameral::Info, bicameral::Log(), LuauSandbox(), and bicameral::Tool.

Referenced by OpenLibraries().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegisterFunction()

std::expected< void, ScriptError > bicameral::script::LuauSandbox::RegisterFunction ( const char * tableName,
const char * name,
HostFunction function,
void * context )
nodiscard

Definition at line 224 of file luau_sandbox.cpp.

References m_sealed, m_state, and bicameral::script::Usage.

◆ Require()

int bicameral::script::LuauSandbox::Require ( lua_State * state)
staticprivate

Definition at line 379 of file luau_sandbox.cpp.

References LuauSandbox().

Referenced by BeginModules().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReseedRandom()

void bicameral::script::LuauSandbox::ReseedRandom ( )
private

Definition at line 264 of file luau_sandbox.cpp.

References m_limits, and m_state.

Referenced by Run().

Here is the caller graph for this function:

◆ Run()

std::expected< RunResult, ScriptError > bicameral::script::LuauSandbox::Run ( std::string_view chunkName,
std::string_view source,
const RunOptions & options = {} )
nodiscard

Definition at line 275 of file luau_sandbox.cpp.

References BeginModules(), bicameral::script::Compile, EndModules(), m_currentChunk, m_memoryExceeded, m_safepointCount, m_safepointExceeded, m_sealed, m_state, bicameral::script::Memory, bicameral::script::RunOptions::modules, ReseedRandom(), RunThread(), and bicameral::script::Usage.

Referenced by bicameral::script::anonymous_namespace{luau_package.cpp}::ReadManifest(), and bicameral::script::anonymous_namespace{luau_package.cpp}::RunEntry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RunModule()

std::expected< void, std::string > bicameral::script::LuauSandbox::RunModule ( lua_State * state,
const std::string & chunkName,
std::string_view source )
nodiscardprivate

Definition at line 429 of file luau_sandbox.cpp.

References bicameral::script::Compile, and m_moduleLoading.

Referenced by LoadModule().

Here is the caller graph for this function:

◆ RunThread()

std::expected< RunResult, ScriptError > bicameral::script::LuauSandbox::RunThread ( lua_State * thread,
std::string_view chunkName,
const char * bytecode,
size_t bytecodeSize,
const RunOptions & options )
nodiscardprivate

Definition at line 311 of file luau_sandbox.cpp.

References CollectResults(), bicameral::script::Compile, m_memoryExceeded, and m_safepointExceeded.

Referenced by Run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Seal()

void bicameral::script::LuauSandbox::Seal ( )

Definition at line 250 of file luau_sandbox.cpp.

References m_sealed, and m_state.

Member Data Documentation

◆ m_currentChunk

std::string bicameral::script::LuauSandbox::m_currentChunk
private

Definition at line 145 of file luau_sandbox.h.

Referenced by Run().

◆ m_limits

SandboxLimits bicameral::script::LuauSandbox::m_limits
private

Definition at line 136 of file luau_sandbox.h.

Referenced by LuauSandbox(), and ReseedRandom().

◆ m_memoryBytes

uint64_t bicameral::script::LuauSandbox::m_memoryBytes = 0
private

Definition at line 141 of file luau_sandbox.h.

Referenced by MemoryBytes().

◆ m_memoryExceeded

bool bicameral::script::LuauSandbox::m_memoryExceeded = false
private

Definition at line 144 of file luau_sandbox.h.

Referenced by Run(), and RunThread().

◆ m_moduleCacheRef

int bicameral::script::LuauSandbox::m_moduleCacheRef = 0
private

Definition at line 149 of file luau_sandbox.h.

Referenced by BeginModules(), EndModules(), and LoadModule().

◆ m_moduleLoading

std::vector<std::string> bicameral::script::LuauSandbox::m_moduleLoading
private

Definition at line 150 of file luau_sandbox.h.

Referenced by BeginModules(), EndModules(), LoadModule(), and RunModule().

◆ m_modules

const ModuleResolver* bicameral::script::LuauSandbox::m_modules = nullptr
private

Definition at line 148 of file luau_sandbox.h.

Referenced by BeginModules(), EndModules(), and LoadModule().

◆ m_safepointCount

uint64_t bicameral::script::LuauSandbox::m_safepointCount = 0
private

Definition at line 142 of file luau_sandbox.h.

Referenced by CollectResults(), and Run().

◆ m_safepointExceeded

bool bicameral::script::LuauSandbox::m_safepointExceeded = false
private

Definition at line 143 of file luau_sandbox.h.

Referenced by Run(), and RunThread().

◆ m_sealed

bool bicameral::script::LuauSandbox::m_sealed = false
private

Definition at line 138 of file luau_sandbox.h.

Referenced by IsSealed(), RegisterFunction(), Run(), and Seal().

◆ m_state

lua_State* bicameral::script::LuauSandbox::m_state = nullptr
private

The documentation for this class was generated from the following files: