Class LuaContainer
- Namespace
- Cobilas.GodotEngine.GDLua
- Assembly
- com.cobilas.godot.lua.dll
Represents an in-memory Lua code builder and executor integrated with the Godot engine.
public sealed class LuaContainer : IDisposable, ILuaFile
- Inheritance
-
LuaContainer
- Implements
- Inherited Members
Remarks
This class implements ILuaFile and provides methods to dynamically create, manipulate, and execute Lua code through an internal StringBuilder buffer. It allows the construction of Lua scripts programmatically and their execution using NLua. Implements IDisposable for proper resource cleanup.
Constructors
LuaContainer(LuaContainerConfg)
Initializes a new instance of the LuaContainer class with the specified configuration.
public LuaContainer(LuaContainerConfg confg)
Parameters
confgLuaContainerConfgThe configuration used to initialize the Lua state and related options.
Exceptions
- ArgumentNullException
Thrown when a required configuration property is null.
Properties
Builder
Gets the current string content of the internal StringBuilder.
public string Builder { get; }
Property Value
Methods
ClearBuffer()
Clears the internal Lua code buffer.
public LuaContainer ClearBuffer()
Returns
- LuaContainer
The current LuaContainer instance for chaining.
Exceptions
- ObjectDisposedException
Thrown when the container has been disposed.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
DoString(string)
Appends a raw Lua code string to the buffer.
public LuaContainer DoString(string value)
Parameters
valuestringThe Lua code string to append.
Returns
- LuaContainer
The current LuaContainer instance for chaining.
Exceptions
- ObjectDisposedException
Thrown when the container has been disposed.
FlushToLua()
Executes the current Lua buffer using the NLua interpreter.
public LuaContainer FlushToLua()
Returns
- LuaContainer
The current LuaContainer instance for chaining.
Exceptions
- ObjectDisposedException
Thrown when the container has been disposed.
GetField(string)
Retrieves a field from the Lua file by its path.
public LuaField GetField(string pathField)
Parameters
pathFieldstringThe path to the field in the Lua file.
Returns
Exceptions
- ObjectDisposedException
Thrown when the container has been disposed.
InitCLRPackage(string)
Adds a CLR import statement to the Lua buffer.
public LuaContainer InitCLRPackage(string import)
Parameters
importstringThe CLR namespace or type to import.
Returns
- LuaContainer
The current LuaContainer instance for chaining.
Exceptions
- ObjectDisposedException
Thrown when the container has been disposed.
InitField(string, object)
Initializes a global Lua field with a specific value.
public LuaContainer InitField(string pathField, object value)
Parameters
Returns
- LuaContainer
The current LuaContainer instance for chaining.
Exceptions
- ObjectDisposedException
Thrown when the container has been disposed.
InitFunction(string, string, params string[])
Initializes a Lua function with the specified name, body, and arguments.
public LuaContainer InitFunction(string funcName, string funcBody, params string[] funcArgs)
Parameters
funcNamestringThe name of the function.
funcBodystringThe Lua code representing the function body.
funcArgsstring[]The arguments of the function.
Returns
- LuaContainer
The current LuaContainer instance for chaining.
Exceptions
- ObjectDisposedException
Thrown when the container has been disposed.
InitLoaclField(string, object)
Initializes a local Lua field with a specific value.
public LuaContainer InitLoaclField(string pathField, object value)
Parameters
pathFieldstringThe Lua field name to initialize locally.
valueobjectThe value to assign to the field.
Returns
- LuaContainer
The current LuaContainer instance for chaining.
Exceptions
- ObjectDisposedException
Thrown when the container has been disposed.
InitTable(LuaTableItem)
Initializes a Lua table by appending its string representation to the buffer.
public LuaContainer InitTable(LuaTableItem tables)
Parameters
tablesLuaTableItemThe Lua table object to append.
Returns
- LuaContainer
The current LuaContainer instance for chaining.
Exceptions
- ObjectDisposedException
Thrown when the container has been disposed.
InvokeFunction(string, params object[])
Invokes a function defined in the Lua file.
public object[] InvokeFunction(string methodName, params object[] args)
Parameters
methodNamestringThe name of the function to invoke.
argsobject[]The arguments to pass to the function.
Returns
- object[]
An array of objects containing the function's return values.
Exceptions
- ObjectDisposedException
Thrown when the container has been disposed.
LuaTableToObject<T>(string)
Converts a Lua table to an object of the specified type.
public LuaField LuaTableToObject<T>(string pathField)
Parameters
pathFieldstringThe path to the Lua table in the file.
Returns
Type Parameters
TThe target type to convert the Lua table to.
Exceptions
- ObjectDisposedException
Thrown when the container has been disposed.
LuaTableToObject<T>(string, ref T)
Converts a Lua table to an object and assigns it to the provided reference.
public void LuaTableToObject<T>(string pathField, ref T value)
Parameters
pathFieldstringThe path to the Lua table in the file.
valueTThe reference variable to assign the converted table data to.
Type Parameters
TThe type of the object to assign.
Exceptions
- ObjectDisposedException
Thrown when the container has been disposed.
- InvalidCastException
Thrown when no converter is defined for the specified type.
SetField(string, object)
Sets the value of a field in the Lua file.
public void SetField(string pathField, object value)
Parameters
pathFieldstringThe path to the field in the Lua file.
valueobjectThe value to assign to the field.
Exceptions
- ObjectDisposedException
Thrown when the container has been disposed.