xLua
xLua is a lua programming solution for C# ( Unity, .Net, Mono) , it supports android, ios, windows, linux, osx, etc.
xLua lets developers write Lua scripts inside C# Unity games and hot-patch shipped bugs at runtime without requiring users to download a full app update.
xLua is a tool from Tencent that lets developers write Lua scripts inside C# projects, particularly Unity games. Lua is a lightweight scripting language commonly used in games because scripts can be updated without recompiling the whole application. xLua bridges Lua and C# so the two can call each other's code freely.
The most notable feature is hot patching. If a shipped game has a bug in its C# code, a developer can push a Lua script that replaces the broken C# method at runtime, without requiring users to download a full app update. This is especially valuable for mobile games where app store update cycles are slow. The hot patch system is described as low-intrusion, meaning existing C# code does not need to be rewritten to use this feature.
Beyond hot patching, xLua supports using Lua to write full game logic components, handle UI events, manage coroutines, and work with async operations. The library includes optimizations that avoid unnecessary memory allocations when passing data between Lua and C#, which matters in games where memory management directly affects frame rate.
Installation is done by downloading a release, extracting it, and copying the Assets folder contents into your Unity project. A complete working example takes just three lines of C# code to create a Lua environment, run a Lua string, and clean up. The documentation is primarily in Chinese, though an English README is also available.
xLua runs on Android, iOS, Windows, Linux, and macOS, covering the main platforms Unity targets.
Where it fits
- Hot-patch a shipped mobile game's C# bugs by pushing a Lua script that replaces the broken method at runtime, skipping the app store update cycle.
- Write full Unity game logic, UI events, and coroutines in Lua scripts instead of C# for faster iteration.
- Call C# methods from Lua and Lua functions from C# freely within the same Unity project.