Class Luau
- Namespace
- LuauInterop
- Assembly
- LuauInterop.dll
Represents a Luau instance.
public class Luau : IDisposable
- Inheritance
-
Luau
- Implements
- Inherited Members
Constructors
Luau()
Initializes a new Luau instance and allocates a fresh native state.
public Luau()
Exceptions
- OutOfMemoryException
Thrown if the native state could not be allocated.
Fields
Callbacks
List of callbacks registered in this instance.
public readonly List<LuauCallback> Callbacks
Field Value
Properties
IsDisposed
Gets a value indicating whether this instance has been disposed.
public bool IsDisposed { get; }
Property Value
this[string]
Gets or sets a global variable by name.
public object? this[string name] { get; set; }
Parameters
namestringThe name of the global variable.
Property Value
State
Gets the underlying native Luau state.
public LuaState State { get; }
Property Value
Methods
Compile(string, LuauCompileOptions?)
Compiles a Luau source string into a LuauChunk.
public LuauChunk Compile(string chunk, LuauCompileOptions? options = null)
Parameters
chunkstringThe Luau source code to compile.
optionsLuauCompileOptionsOptional compiler options. Pass null to use defaults.
Returns
CreateThread()
Creates a new Luau coroutine thread.
public LuauThread CreateThread()
Returns
- LuauThread
A LuauThread that can be resumed independently.
Exceptions
- ObjectDisposedException
Thrown if this instance has been disposed.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Dispose(bool)
protected virtual void Dispose(bool disposing)
Parameters
disposingbool
DoChunk(LuauChunk, string)
Executes a pre-compiled LuauChunk, returning any values it produces.
public object?[] DoChunk(LuauChunk chunk, string chunkName = "chunk")
Parameters
chunkLuauChunkThe compiled chunk to execute.
chunkNamestringA name for the chunk used in error messages. Defaults to
"chunk".
Returns
- object[]
An array of values returned by the chunk, or an empty array if it returns nothing.
Exceptions
- LuauException
Thrown if execution fails.
- ObjectDisposedException
Thrown if this instance has been disposed.
DoString(string, string)
Compiles and executes a Luau source string, returning any values it produces.
public object?[] DoString(string chunk, string chunkName = "chunk")
Parameters
chunkstringThe Luau source code to execute.
chunkNamestringA name for the chunk used in error messages. Defaults to
"chunk".
Returns
- object[]
An array of values returned by the chunk, or an empty array if it returns nothing.
Exceptions
- LuauException
Thrown if compilation or execution fails.
- ObjectDisposedException
Thrown if this instance has been disposed.
~Luau()
protected ~Luau()
GetErrorMessage(LuaState)
Gets the error message from the top of the stack, if any, and pops it off the stack. If there is no error message, returns a default message.
public string GetErrorMessage(LuaState state)
Parameters
stateLuaState
Returns
- string
The error message from the top of the stack, or a default message if there is no error message.
Exceptions
- ObjectDisposedException
Thrown if this instance has been disposed.
GetFFlag(string)
Gets the value of an FFlag.
public bool GetFFlag(string name)
Parameters
namestringThe name of the FFlag to get.
Returns
GetObject(int, LuaState)
Gets the value at the specified index on the stack, converting it to an appropriate C# type.
public object? GetObject(int index, LuaState state)
Parameters
indexintThe index of the value to get.
stateLuaStateThe Lua state to use for retrieving the value.
Returns
- object
The value at the specified index, converted to an appropriate C# type.
Exceptions
- ObjectDisposedException
Thrown if this instance has been disposed.
GetValue(int, LuaState)
Gets the value at the specified index on the stack.
public LuauValue GetValue(int index, LuaState state)
Parameters
Returns
- LuauValue
The value at the specified index.
Exceptions
- ObjectDisposedException
Thrown if this instance has been disposed.
LoadString(string, LuaState, string)
Compiles a Luau source string and loads it onto the stack as a callable function, without executing it.
public LuauStatus LoadString(string chunk, LuaState targetState, string chunkName = "chunk")
Parameters
chunkstringThe Luau source code to compile and load.
targetStateLuaStateThe Lua state to load the compiled function onto. If the current state is different from the target state, the compiled function will be moved to the target state after loading.
chunkNamestringA name for the chunk used in error messages. Defaults to
"chunk".
Returns
- LuauStatus
OK on success, or an error status if compilation or loading fails.
Exceptions
- ObjectDisposedException
Thrown if this instance has been disposed.
LoadString(string, string)
Compiles a Luau source string and loads it onto the stack as a callable function, without executing it.
public LuauStatus LoadString(string chunk, string chunkName = "chunk")
Parameters
chunkstringThe Luau source code to compile and load.
chunkNamestringA name for the chunk used in error messages. Defaults to
"chunk".
Returns
- LuauStatus
OK on success, or an error status if compilation or loading fails.
Exceptions
- ObjectDisposedException
Thrown if this instance has been disposed.
OpenLibrary(LuauLibrary)
Opens the specified standard Luau libraries into this state.
public void OpenLibrary(LuauLibrary library)
Parameters
libraryLuauLibraryThe libraries to open.
Exceptions
- ObjectDisposedException
Thrown if this instance has been disposed.
Pop(int, LuaState)
Pops n values off the top of the stack.
public void Pop(int n, LuaState state)
Parameters
Exceptions
- ObjectDisposedException
Thrown if this instance has been disposed.
Push(LuauValue, LuaState)
Pushes a LuauValue onto the stack.
public void Push(LuauValue value, LuaState state)
Parameters
Exceptions
- ObjectDisposedException
Thrown if this instance has been disposed.
PushCallback(LuauCallback, LuaState)
Pushes a C# function onto the stack.
public void PushCallback(LuauCallback callback, LuaState state)
Parameters
callbackLuauCallbackstateLuaState
PushObject(object?, LuaState)
Pushes a C# object onto the stack, converting it to an appropriate Luau type.
public void PushObject(object? value, LuaState state)
Parameters
Exceptions
- ObjectDisposedException
Thrown if this instance has been disposed.
RegisterCallback(string, Func<Luau, LuaState, int>)
Registers a C# function as a global in the Luau state, making it callable from Luau code.
public LuauCallback RegisterCallback(string name, Func<Luau, LuaState, int> fn)
Parameters
Returns
SetFFlag(string, bool)
Sets an FFlag.
public static void SetFFlag(string name, bool enabled)