Skip to main content

ZLua DocsAlpha

Native Lua · C# interop · Optimized for Unity Il2Cpp

Mono · 已完成Il2Cpp · 已完成

Unity LTS · Tuanjie · Multiple Lua engines; see compatibility

⚡

Easier · zero-config

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

🚀

Native C++ interop

Il2Cpp uses native C++ bridges. See the performance report for measured results, test environment, and workload limits.

📦

Smaller bridge · less GC

Signature-shared C++ stubs reduce duplicated bridge code. Low-allocation Marshal paths depend on data types, call direction, and warm-up.

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,
}