Table of Contents

Interface ILuaContext

Namespace
EncDotNet.S100.Scripting
Assembly
EncDotNet.S100.Core.dll

An isolated Lua execution environment that can load scripts, set/get globals, and call functions. Corresponds to a single Lua state.

public interface ILuaContext : IDisposable
Inherited Members

Methods

Call(string, params object?[])

Calls a global Lua function by name with the given arguments. Returns the first return value, or null if the function returns nothing.

object? Call(string functionName, params object?[] args)

Parameters

functionName string
args object[]

Returns

object

CallMultiReturn(string, params object?[])

Calls a global Lua function and returns all return values.

object?[] CallMultiReturn(string functionName, params object?[] args)

Parameters

functionName string
args object[]

Returns

object[]

DescribeError(Exception)

Describes an exception thrown by this context, including the Lua source location when the engine records one.

string DescribeError(Exception exception)

Parameters

exception Exception

Returns

string

Execute(string)

Executes a chunk of Lua source code in this context. Any functions or globals defined by the chunk become available for subsequent calls.

void Execute(string source)

Parameters

source string

GetGlobal(string)

Gets the value of a global variable, converted to the closest .NET type. Returns null for Lua nil.

object? GetGlobal(string name)

Parameters

name string

Returns

object

SetGlobal(string, object?)

Sets a global variable in the Lua environment.

Supported .NET → Lua type mappings:

void SetGlobal(string name, object? value)

Parameters

name string
value object

SetModuleLoader(Func<string, string?>)

Registers a callback that resolves module names to Lua source code, enabling the Lua require() function. When a script calls require("moduleName"), the callback is invoked with the module name; it should return the source code or null if not found.

void SetModuleLoader(Func<string, string?> loader)

Parameters

loader Func<string, string>