explaingit

tencent/xlua

10,084CAudience · developerComplexity · 3/5Setup · easy

TLDR

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.

Mindmap

mindmap
  root((xLua))
    What it does
      Lua inside Unity
      Hot patch bugs
      Bidirectional calls
    Tech Stack
      C and C#
      Lua scripting
      Unity engine
    Use Cases
      Mobile hotfix
      Game logic in Lua
      UI event handling
    Platforms
      Android and iOS
      Windows Linux macOS
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

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.

USE CASE 2

Write full Unity game logic, UI events, and coroutines in Lua scripts instead of C# for faster iteration.

USE CASE 3

Call C# methods from Lua and Lua functions from C# freely within the same Unity project.

Tech stack

CC#LuaUnity

Getting it running

Difficulty · easy Time to first run · 30min

Drop the Assets folder into your Unity project, primary documentation is in Chinese, though an English README is available.

In plain English

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.

Copy-paste prompts

Prompt 1
Using xLua in my Unity project, write a Lua hot patch that replaces a C# method called 'CalculateDamage' to fix a balance bug without recompiling the game.
Prompt 2
Show me the minimal three-line C# setup to create an xLua Lua environment, execute a Lua string, and dispose the environment safely.
Prompt 3
Write a Lua script using xLua that listens for a Unity button click event and updates a UI Text field with a score value stored in C#.
Prompt 4
How do I implement a coroutine in xLua Lua that waits two seconds then triggers a C# callback in a Unity game?
Open on GitHub → Explain another repo

← tencent on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.