Table of Contents

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

confg LuaContainerConfg

The 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

string

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

value string

The 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

pathField string

The path to the field in the Lua file.

Returns

LuaField

A LuaField containing the field data.

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

import string

The 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

pathField string

The Lua field path to initialize.

value object

The value to assign to the field.

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

funcName string

The name of the function.

funcBody string

The Lua code representing the function body.

funcArgs string[]

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

pathField string

The Lua field name to initialize locally.

value object

The 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

tables LuaTableItem

The 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

methodName string

The name of the function to invoke.

args object[]

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

pathField string

The path to the Lua table in the file.

Returns

LuaField

A LuaField containing the converted table data.

Type Parameters

T

The 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

pathField string

The path to the Lua table in the file.

value T

The reference variable to assign the converted table data to.

Type Parameters

T

The 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

pathField string

The path to the field in the Lua file.

value object

The value to assign to the field.

Exceptions

ObjectDisposedException

Thrown when the container has been disposed.