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

MonoBehaviour script which establishes a Lua object framework. For internal use. More...

Public Member Functions

void Expose ()
 Used to raise a flag when an object is exposed to Lua. More...
 
void InvokeLua (string FunctionName, params object[] args)
 Invokes a Lua callback function. More...
 
void Register (string FunctionName, string Code="", string args="")
 Registers a Lua callback function. This method is available in Lua. More...
 

Protected Member Functions

virtual void OnDestroy ()
 Invokes the OnExit callback and removes the object from Lua. More...
 

Properties

DynValue this[DynValue Key] [get, set]
 Returns a Lua value indexed by the DynValue Key. More...
 
DynValue this[string Key] [get, set]
 Returns a Lua value indexed by the string key. More...
 
LuaMonoBehaviour Context [get, set]
 Used to access/set the context of an object. More...
 
string Handle [get]
 Used to access the unique Handle of a Lua object. More...
 
bool IsExposed [get]
 Used to track if an object has been exposed to Lua. More...
 
string Name [get, set]
 Used to access/set the name of an object. More...
 
- Properties inherited from uLua.ILuaObject
DynValue this[DynValue Key] [get, set]
 Returns a Lua value indexed by the DynValue Key. More...
 
DynValue this[string Key] [get, set]
 Returns a Lua value indexed by the string key. More...
 
LuaMonoBehaviour Context [get, set]
 Used to access/set the context of an object. More...
 
string Handle [get]
 Used to access the unique Handle of a Lua object. More...
 
bool IsExposed [get]
 Used to track if an object has been exposed to Lua. More...
 
string Name [get]
 Used to access the name of an object. More...
 

Detailed Description

MonoBehaviour script which establishes a Lua object framework. For internal use.

Instances of this class can be exposed to Lua by calling uLua.API.Expose(). All public members of derived classes will be exposed to Lua. Prior to exposing an object of type uLua.LuaMonoBehaviour, the derived type T must be registered to Lua by calling API.RegisterIndexedType().

Member Function Documentation

◆ Expose()

void uLua.LuaMonoBehaviour.Expose ( )
inline

Used to raise a flag when an object is exposed to Lua.

The property IsExposed can be used to check if this method has been called. The IsExposed flag cannot be reset.

Implements uLua.ILuaObject.

◆ InvokeLua()

void uLua.LuaMonoBehaviour.InvokeLua ( string  FunctionName,
params object[]  args 
)
inline

Invokes a Lua callback function.

The callback function must be implemented in a Lua script as a member of this object. Alternatively, you can register a callback function by explicitly calling uLua.LuaMonoBehaviour.Register() with the relevant Lua code.

Parameters
FunctionNameThe name of the callback function to be called.
args(Optional) Parameters for the callback function.

◆ OnDestroy()

virtual void uLua.LuaMonoBehaviour.OnDestroy ( )
inlineprotectedvirtual

Invokes the OnExit callback and removes the object from Lua.

This method is called by Unity Engine when a game object is destroyed.

◆ Register()

void uLua.LuaMonoBehaviour.Register ( string  FunctionName,
string  Code = "",
string  args = "" 
)
inline

Registers a Lua callback function. This method is available in Lua.

Used to register a callback function by providing the relevant Lua code.

Parameters
FunctionNameThe name of the callback function to be registered.
Code(Optional) The body of the function to be registered in Lua. If omitted, an empty function with the specified name is defined.
args(Optional) Parameters for the callback function. Must be separated by comma as they would be in a Lua function definition, e.g. 'arg1,arg2'.

Property Documentation

◆ Context

LuaMonoBehaviour uLua.LuaMonoBehaviour.Context
getset

Used to access/set the context of an object.

The Context object represents the parent of an object in Lua. If the Context is null, the object will be global in Lua. Must be of type uLua.LuaMonoBehaviour.

Implements uLua.ILuaObject.

◆ Handle

string uLua.LuaMonoBehaviour.Handle
get

Used to access the unique Handle of a Lua object.

The unique Handle of a Lua object is defined as: Context.Name. If an object's context is null, its unique handle is simply its name.

Implements uLua.ILuaObject.

◆ IsExposed

bool uLua.LuaMonoBehaviour.IsExposed
get

Used to track if an object has been exposed to Lua.

Objects may be marked as exposed by calling the Expose() method.

Implements uLua.ILuaObject.

◆ Name

string uLua.LuaMonoBehaviour.Name
getset

Used to access/set the name of an object.

If a name is not set, the game object's name will be used by default. The name of an object cannot be changed after it has been exposed to Lua.

Implements uLua.ILuaObject.

◆ this[DynValue Key]

DynValue uLua.LuaMonoBehaviour.this[DynValue Key]
getset

Returns a Lua value indexed by the DynValue Key.

This indexer may be used in Lua or within C# to access any member of a Lua object.

Implements uLua.ILuaObject.

◆ this[string Key]

DynValue uLua.LuaMonoBehaviour.this[string Key]
getset

Returns a Lua value indexed by the string key.

This indexer may be used in Lua or within C# to access any member of a Lua object.

Implements uLua.ILuaObject.