README_EN.md
xLua adds Lua scripting capability to Unity, .Net, Mono, and other C# environments. With xLua, Lua code and C# code can easily call each other.
xLua has many breakthroughs in function, performance, and ease of use. The most significant features are:
Unpack the ZIP package and you will see an Assets directory, which corresponds to the Unity project's Assets directory. Keep the directory structure in your Unity project.
If you want to install it to another directory, please see the FAQs.
A complete example requires only 3 lines of code:
Install xLua, create a MonoBehaviour drag scenario, add the following code to Start:
XLua.LuaEnv luaenv = new XLua.LuaEnv();
luaenv.DoString("CS.UnityEngine.Debug.Log('hello world')");
luaenv.Dispose();
The DoString parameter is a string, and you can enter any allowable Lua code. In this example, Lua calls C#’s UnityEngine.Debug.Log to print a log.
A LuaEnv instance corresponds to a Lua virtual machine. Due to overhead, it is recommended that the Lua virtual machine be globally unique.
It is simple that C# actively calls Lua. For example, the recommended method to call Lua's system function is:
[XLua.CSharpCallLua]
public delegate double LuaMax(double a, double b);
var max = luaenv.Global.GetInPath<LuaMax>("math.max");
Debug.Log("max:" + max(32, 12));
It is recommended that you bind once and reuse it. If code is generated, no gc alloc is generated when calling max.
Here is the usage guide:
QQ Group 1: 612705778 (may be full)
QQ Group 2: 703073338
QQ Group 3: 811246782
Check answers: If you encounter a problem, please read the FAQs first.