Skip to main content

ZLua DocsAlpha

Zero-config · Full C# interop · ~2.62× faster than xLua on Il2Cpp

Mono · 已完成Il2Cpp · 已完成

Unity 2021+ · Tuanjie · Lua 5.1–5.5 / LuaJIT (Il2Cpp: Android · iOS)

Easier · zero-config

Declarative GetFunction / [LuaMarshalAs], lazy CSharp loading; no per-type C# Wrap allowlist, no raw Lua C API.

🚀

Faster · ~2.62×

Il2Cpp benchmarks: ~98% of aligned cases beat xLua; Lua→C# ~2.62× on average; common field / property access ~4×.

📦

Smaller bridge · less GC

Signature-merged C++ stubs can be an order of magnitude smaller; reference types and structs default to 0 GC, with OpaqueValue and related strategies.

Bidirectional calls at a glance

C# · GetFunction

// Bootstrap.cs
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
private static void InitZLuaOnStartup()
{
    LuaAppDomain.Initialize(LoadLuaModule);
}

Action AppMain;
Func<int, int, int> AppAdd;

void Awake()
{
    AppMain = LuaAppDomain.GetFunction<Action>("app", "main");
    AppAdd = LuaAppDomain.GetFunction<Func<int, int, int>>("app", "add");
}

Lua · app.lua

-- app.lua
local function main()
    print("lua main start")
end

local function add(a, b)
    return a + b
end

return {
    main = main,
    add = add,
}