bLuaInstance
A bLuaInstance (also referred to as "instance") is the object responsible for communicating with Lua from C#. An instance has its own settings, features, and access to your C# code that are set during the creation of the instance. You only need one instance in many cases, but if you want to, you can have separate instances that each have their own settings, features, and/or C# access.
Methods
DoString
Loads the given string as a Lua chunk and runs it.
LoadString
Loads the given string as a Lua chunk. This function only loads the chunk; it does not run it.
GetGlobal
Returns a global value on the Lua instance.
SetGlobal
Sets a global value on the Lua instance.
Call
Calls a Lua function that is passed in as a bLuaValue. You can also pass in arguments for the Lua function in this function. Returns the result of the Lua function, if it has one.
CallAsCoroutine
Creates a coroutine for the function that is passed in as a bLuaValue, then runs the coroutine. You can also pass in arguments for the coroutine in this function. Returns the coroutine that has been run.
If the Features.Coroutines
feature is not enabled, this function will use Call
instead.
CreateCoroutine
Creates a coroutine for the function that is passed in as a bLuaValue. Returns the coroutine that has been created.
ResumeCoroutine
Resumes a coroutine that is passed in as a bLuaValue. You can also pass in arguments for the coroutine in this function. Returns true if the resume succeeded, and false if something went wrong.
ManualTick
Manually ticks this instance. This function calls the same code as the internal tick systems would. You should call this when your instance's TickBehavior
is set to Manual
, since there is no automatic ticking when using that setting.
ManualCollectGarbage
Manually collect garbage on this instance. This function calls the same code as the internal C# garbage collection system would.
GetIsFeatureEnabled
Returns true if the given Feature
flag is enabled on this instance.
UnityEvents
OnPrint
This event passes an array of bLuaValues, which represent the objects or strings passed into a print()
from Lua. This event will only fire if Features.CSharpPrintOverride
is enabled.
OnError
This event passes two strings, the first of which is the error message, and the second of which is the Lua stack trace (if one is available). This event will fire for both Lua errors and bLua errors relevant to Lua code.
OnTick
This event fires whenever the instance ticks.