⚡
更易用 · 零配置
声明式 GetFunction / [LuaMarshalAs],CSharp 懒加载;无需 per-type C# Wrap 白名单,屏蔽底层 Lua C API。
🚀
更快 · 约 2.62×
Il2Cpp 实测:约 98% 对齐用例快于 xLua;Lua→C# 平均约 2.62×;常见字段 / 属性与调用约 4×。
📦
更小桥接 · 更少 GC
同签名合并的 C++ stub,体积可小一个数量级;引用类型与 struct 默认 0 GC,并提供 OpaqueValue 等策略。
双向调用一览
- C# → Lua
- Lua → C#
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,
}CSharp['AC'] = CSharp['Assembly-CSharp']
local function main()
local demo = CSharp.AC.Demo()
demo.x = 10
print("Demo.Add:", CSharp.AC.Demo.Add(3, 5))
end
return { main = main }