Table of Contents

Class LuaFile

Namespace
Cobilas.GodotEngine.GDLua
Assembly
com.cobilas.godot.lua.dll

Represents a Lua file that can be loaded, executed, and manipulated within the Godot engine.

public sealed class LuaFile : IDisposable, ILuaFile
Inheritance
LuaFile
Implements
Inherited Members

Remarks

This class provides methods to interact with Lua scripts, including reading fields, setting values, invoking functions, and converting Lua tables to C# objects. Implements IDisposable for proper resource cleanup.

Constructors

LuaFile(LuaFileConfg)

Initializes a new instance of the LuaFile class with the specified configuration.

public LuaFile(LuaFileConfg confg)

Parameters

confg LuaFileConfg

The configuration settings for the Lua file.

Exceptions

ArgumentNullException

Thrown when the file path in configuration is null.

DirectoryNotFoundException

Thrown when the directory containing the Lua file is not found.

FileNotFoundException

Thrown when the specified Lua file is not found.

LuaFile(string, bool)

Initializes a new instance of the LuaFile class with the specified file path.

public LuaFile(string filePath, bool refreshBuffer = false)

Parameters

filePath string

The path to the Lua file.

refreshBuffer bool

Whether to refresh the file buffer on each access.

Methods

Dispose()

Releases all resources used by the LuaFile instance.

public void Dispose()

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 LuaFile 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 LuaFile 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 LuaFile 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 LuaFile has been disposed.

InvalidCastException

Thrown when no converter is found 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 LuaFile has been disposed.