Skip to content
Version 2.11.0
↓ Get the launcher

ILua interface

Bridge to the game’s live tolua# Lua state (LuaInterface.LuaState.mainState) where all Z.* game globals are registered. Lets a plugin run a Lua chunk and read simple global values back, without hand-rolling the reflection resolution in every plugin.

Main-thread only, fire-and-forget. Every member touches the game’s Lua stack, which is not thread-safe and must be driven from the Unity main thread — call from inside Update or Post, never from a chat/network callback thread. There is no way to return a value from a chunk and no C# callback may be passed into Lua (a native Lua→C# callback crashes the IL2CPP runtime); park a result in a global with rawset(_G, key, value) and read it via the typed getters below.

public interface ILua
name description
Ready { get; } True once LuaState.mainState and the DoString entry point have resolved (post-login). Chunks issued before this is true are dropped, so gate on it or simply retry each tick.
DoString(…) Runs chunk in the game’s main Lua state on the calling (main) thread. Fire-and-forget: no return value. Wrap the chunk body in pcall(function() ... end) so a Lua-side error cannot propagate back through the interop trampoline. No-op until Ready.
ReadGlobalString(…) Reads global key as a managed string via the tolua# stack API (LuaGetGlobal→LuaToString). Returns null when the global is absent or not string-convertible.
TryReadGlobalBool(…) Reads global key as a Lua boolean via the tolua# stack API. Returns false (with value = false) when the global is absent, nil, or not a boolean.
TryReadGlobalNumber(…) Reads global key as a Lua number via the tolua# stack API. Returns false (with value = 0) when the global is absent, nil, or not a number.