Interface ILuaContext
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
Returns
CallMultiReturn(string, params object?[])
Calls a global Lua function and returns all return values.
object?[] CallMultiReturn(string functionName, params object?[] args)
Parameters
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
exceptionException
Returns
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
sourcestring
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
namestring
Returns
SetGlobal(string, object?)
Sets a global variable in the Lua environment.
Supported .NET → Lua type mappings:
void SetGlobal(string name, object? value)
Parameters
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)