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
confgLuaFileConfgThe 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
filePathstringThe path to the Lua file.
refreshBufferboolWhether 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
pathFieldstringThe path to the field in the Lua file.
Returns
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
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 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
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 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
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 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
pathFieldstringThe path to the field in the Lua file.
valueobjectThe value to assign to the field.
Exceptions
- ObjectDisposedException
Thrown when the LuaFile has been disposed.