Skip to content

Examples

The upstream examples demonstrate different parts of the bridge. They are configured with attributes on their types and in Assets/XLua/Examples/XLuaConfig.cs; install the xLua source generator (Configuration) before building an IL2CPP player, so that their bindings are generated. Hotfix examples additionally require instrumentation; follow the hotfix guide.

Example Demonstrates
Hello world Running Lua from C#
Unity scripting Lua implementations of Unity lifecycle callbacks
UI events Lua callbacks for Unity UI buttons
Lua objects Lua objects accessed through C# interfaces
No GC Generated conversions for value types
Coroutines Lua and Unity coroutine integration
Async calls Sequential Lua logic over asynchronous callbacks
Hotfixing Replacing instrumented C# behavior with Lua
Generic methods Supported generic method signatures
Signature loader Loading signed Lua scripts
Raw objects Choosing boxed C# types for object parameters
Lua implementations Replacing struct operations and mappings in Lua
CLI build Invoking Unity builds from the command line
Async hotfixing Hotfixing async/task behavior
Lua loaders Custom loaders for each place Lua sources can live

The tutorial source also includes C#-to-Lua and Lua-to-C# call examples. See test coverage for what has been verified on devices; an example’s presence is not proof of every platform/runtime combination. These are development examples, not a list of commercial adopters.