uLua v2.2.0
A Lua Modding Framework for Unity.
uLua.Lua Class Reference

Wrapper class which streamlines use of the MoonSharp Lua context. More...

Static Public Member Functions

static void Call (DynValue Function, params object[] args)
 Calls a Lua function with optional parameters. More...
 
static void Clear ()
 Resets and initialises the Lua context
 
static void ExecuteScript (string Code, string codeFriendlyName="", bool overwriteExisting=false)
 Executes the specified code within the Lua context. More...
 
static void Log (string String)
 Logs a message to the console. More...
 
static void LogError (string String)
 Logs an error to the console. More...
 
static void LogWarning (string String)
 Logs a warning to the console. More...
 
static T Get< T > (string Name)
 Finds and returns the Lua global with the specified name. More...
 
static void ObjectCall< T > (T Object, string FunctionName, params object[] args)
 Calls a Lua object's function. More...
 
static void Remove (string Name)
 Removes a global from the Lua context. More...
 
static void Set (string Index, object Value)
 Exposes an object as a global with the specified index in Lua. More...
 
static DynValue ValueToLuaValue (object Value)
 Converts an object to a DynValue. More...
 

Properties

static DynValue NewFunction [get]
 Returns a new Lua function. More...
 
static Table NewTable [get]
 Returns a new Lua table. More...
 
static ScriptLoaderBase ScriptLoader [get, set]
 Gets or sets the Lua script loader. More...
 

Detailed Description

Wrapper class which streamlines use of the MoonSharp Lua context.

Implemented as a static class to ensure the Lua context is available application-wide.

Member Function Documentation

◆ Call()

static void uLua.Lua.Call ( DynValue  Function,
params object[]  args 
)
inlinestatic

Calls a Lua function with optional parameters.

Parameters
FunctionThe DynValue of a Lua function.
args(Optional) Parameters for the Lua function.

◆ ExecuteScript()

static void uLua.Lua.ExecuteScript ( string  Code,
string  codeFriendlyName = "",
bool  overwriteExisting = false 
)
inlinestatic

Executes the specified code within the Lua context.

Parameters
CodeThe Lua code to execute.
codeFriendlyName(Optional) A unique identifier for this script. Not recommended to leave blank, especially if the same script is likely to be executed more than once.
overwriteExisting(Optional) If true, the method will overwrite any previous script with the same filename. Otherwise, any previous script will be called from a hash table.

◆ Get< T >()

static T uLua.Lua.Get< T > ( string  Name)
inlinestatic

Finds and returns the Lua global with the specified name.

The returned object is converted to the type specified by the generic type parameter T.

◆ Log()

static void uLua.Lua.Log ( string  String)
inlinestatic

Logs a message to the console.

Invokes the event 'LuaMessageLogged' which may be handled in Lua. This method is exposed to Lua as a global and may be called from a Lua script or within C#.

◆ LogError()

static void uLua.Lua.LogError ( string  String)
inlinestatic

Logs an error to the console.

Invokes the event 'LuaErrorLogged' which may be handled in Lua. This method is exposed to Lua as a global and may be called from a Lua script or within C#.

◆ LogWarning()

static void uLua.Lua.LogWarning ( string  String)
inlinestatic

Logs a warning to the console.

Invokes the event 'LuaWarningLogged' which may be handled in Lua. This method is exposed to Lua as a global and may be called from a Lua script or within C#.

◆ ObjectCall< T >()

static void uLua.Lua.ObjectCall< T > ( Object,
string  FunctionName,
params object[]  args 
)
inlinestatic

Calls a Lua object's function.

Parameters
ObjectThe object whose function will be called. The generic type T must implement the ILuaObject interface.
FunctionNameThe name of the callback function to be called.
args(Optional) Parameters for the callback function.
Type Constraints
T :ILuaObject 

◆ Remove()

static void uLua.Lua.Remove ( string  Name)
inlinestatic

Removes a global from the Lua context.

Any Lua objects defined as members of the global are invalidated.

◆ Set()

static void uLua.Lua.Set ( string  Index,
object  Value 
)
inlinestatic

Exposes an object as a global with the specified index in Lua.

For object types that implement the ILuaObject interface, use uLua.API.Expose() instead.

Parameters
IndexThe index, or name, of the value within Lua.
ValueThe value to be defined as a global within Lua.

◆ ValueToLuaValue()

static DynValue uLua.Lua.ValueToLuaValue ( object  Value)
inlinestatic

Converts an object to a DynValue.

May be used with any C# object type.

Property Documentation

◆ NewFunction

DynValue uLua.Lua.NewFunction
staticget

Returns a new Lua function.

Used as a placeholder for empty callback functions.

◆ NewTable

Table uLua.Lua.NewTable
staticget

Returns a new Lua table.

Creates a new Table type Lua value.

◆ ScriptLoader

ScriptLoaderBase uLua.Lua.ScriptLoader
staticgetset

Gets or sets the Lua script loader.

The script loader is set on awake in the API script.