{"id":14960306,"url":"https://github.com/tencent/xlua","last_synced_at":"2025-05-15T01:03:36.546Z","repository":{"id":37335016,"uuid":"75811015","full_name":"Tencent/xLua","owner":"Tencent","description":"xLua is a lua programming solution for  C# ( Unity, .Net, Mono) , it supports android, ios, windows, linux, osx, etc.","archived":false,"fork":false,"pushed_at":"2025-03-12T03:43:16.000Z","size":25506,"stargazers_count":9618,"open_issues_count":280,"forks_count":2486,"subscribers_count":515,"default_branch":"master","last_synced_at":"2025-04-22T20:13:12.229Z","etag":null,"topics":["csharp","lua","unity","unity3d","xlua"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tencent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.TXT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-12-07T07:29:07.000Z","updated_at":"2025-04-21T03:01:24.000Z","dependencies_parsed_at":"2023-02-09T15:02:01.884Z","dependency_job_id":"87d954e2-06bb-410e-927c-0c65d1541a38","html_url":"https://github.com/Tencent/xLua","commit_stats":{"total_commits":888,"total_committers":67,"mean_commits":"13.253731343283581","dds":"0.15878378378378377","last_synced_commit":"8723158b9e31d9bc315aebb47e050d96e5658111"},"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tencent%2FxLua","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tencent%2FxLua/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tencent%2FxLua/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tencent%2FxLua/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tencent","download_url":"https://codeload.github.com/Tencent/xLua/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252882766,"owners_count":21819152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","lua","unity","unity3d","xlua"],"created_at":"2024-09-24T13:22:00.953Z","updated_at":"2025-05-07T12:48:36.012Z","avatar_url":"https://github.com/Tencent.png","language":"C","readme":"![](Assets/XLua/Doc/xLua.png)\r\n\r\n[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Tencent/xLua/blob/master/LICENSE.TXT)\r\n[![release](https://img.shields.io/badge/release-v2.1.15-blue.svg)](https://github.com/Tencent/xLua/releases)\r\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-blue.svg)](https://github.com/Tencent/xLua/pulls)\r\n[![Build status](https://github.com/Tencent/xLua/actions/workflows/build.yml/badge.svg)](https://github.com/Tencent/xLua/actions/workflows/build.yml)\r\n\r\n[(English Documents Available)](README_EN.md)\r\n\r\n## C# 下 Lua 编程支持\r\n\r\nxLua 为 Unity、.Net、Mono 等 C# 环境增加 Lua 脚本编程的能力，借助 xLua，这些 Lua 代码可以方便的和 C# 相互调用。\r\n\r\n\u003cbr/\u003e\r\n\r\n## xLua 的突破\r\n\r\nxLua 在功能、性能、易用性都有不少突破，这几方面分别最具代表性的是：\r\n\r\n* 可以运行时把 C# 实现（方法，操作符，属性，事件等等）替换成 Lua 实现；\r\n* 出色的 GC 优化，自定义 struct，枚举在 Lua 和 C# 间传递无 C# GC Alloc；\r\n* 编辑器下无需生成代码，开发更轻量；\r\n\r\n更详细的特性、平台支持介绍请参考 [xLua 文档: 功能特性](Assets/XLua/Doc/features.md)。\r\n\r\n\u003cbr/\u003e\r\n\r\n## 安装\r\n\r\nxLua 可以直接简单的安装在 Unity 项目中.\r\n\r\n1. 从 [Releases](https://github.com/Tencent/xLua/releases) 中下载发行版, 或直接下载本仓库代码.\r\n2. 打开下载下来的源码压缩包, 你会看到一个 Assets 目录, 这目录就对应 Unity 工程的 Assets 目录，保持这目录结构, 将其内容置入 Unity 项目即可.\r\n\r\n\u003e 注意, Assets/Examples 目录下为示例代码, 你应该在生产环境下删去他们.\r\n\r\n如果希望安装到其它目录，请看 [FAQ](Assets/XLua/Doc/faq.md) 相关介绍。\r\n\r\n\u003cbr/\u003e\r\n\r\n## 文档\r\n\r\n* (必看) [XLua 教程](Assets/XLua/Doc/XLua教程.md)：教程，其配套代码[这里](Assets/XLua/Tutorial/)。\r\n* (必看) [XLua 的配置](Assets/XLua/Doc/configure.md)：介绍如何配置xLua。\r\n* [常见问题解答](Assets/XLua/Doc/faq.md)：常见问题都总结在这里，初使用大多数问题都可以在这里找到答案。\r\n* [热补丁操作指南](Assets/XLua/Doc/hotfix.md)：介绍如何使用热补丁特性。\r\n* [XLua增加删除第三方lua库](Assets/XLua/Doc/XLua增加删除第三方lua库.md)：如何增删第三方lua扩展库。\r\n* [XLua API](Assets/XLua/Doc/XLua_API.md)：API文档。\r\n* [生成引擎二次开发指南](Assets/XLua/Doc/custom_generate.md)：介绍如何做生成引擎的二次开发。\r\n\r\n\u003cbr/\u003e\r\n\r\n## 快速入门\r\n\r\n一个完整的例子仅需3行代码：\r\n\r\n安装好xLua，建一个MonoBehaviour拖到场景，在Start加入如下代码：\r\n\r\n```csharp\r\nXLua.LuaEnv luaEnv = new XLua.LuaEnv();\r\nluaEnv.DoString(\"CS.UnityEngine.Debug.Log('hello world')\");\r\nluaEnv.Dispose();\r\n```\r\n\r\n1. DoString 参数为 string，可输入任意合法的 Lua 代码，本示例在 Lua 里调用 C# 的 UnityEngine.Debug.Log 打印了个日志。\r\n2. 一个 LuaEnv 实例对应 Lua 虚拟机，出于开销的考虑，建议全局唯一。\r\n\r\nC#主动调用 Lua 也很简单，比如要调用 Lua 的系统函数，推荐方式是：\r\n\r\n* 声明\r\n\r\n  ```csharp\r\n  [XLua.CSharpCallLua]\r\n  public delegate double LuaMax(double a, double b);\r\n  ```\r\n\r\n* 绑定\r\n\r\n  ```csharp\r\n  var max = luaEnv.Global.GetInPath\u003cLuaMax\u003e(\"math.max\");\r\n  ```\r\n\r\n* 调用\r\n\r\n  ```csharp\r\n  Debug.Log(\"max:\" + max(32, 12));\r\n  ```\r\n\r\n注意, 请不要重复调用 `luaEnv.Global.GetInPath\u003cLuaMax\u003e`, 这没有任何必要.\r\n\r\n\u003cbr/\u003e\r\n\r\n## 热补丁\r\n\r\n除了使用 Lua 在 Unity 进行脚本编写, 你也可以使用 Lua 实现 \"热补丁\". xLua 提供了使用 Lua 逻辑替换 C# 方法逻辑的方案.\r\n\r\n* 侵入性小，老项目原有代码不做任何调整就可使用。\r\n* 运行时影响小，不打补丁基本和原有程序一样。\r\n* 出问题了可以用 Lua 来打补丁，这时才会走到 Lua 代码逻辑；\r\n\r\n参考使用指南: [xLua 文档: 热补丁](Assets/XLua/Doc/hotfix.md)\r\n\r\n\u003cbr/\u003e\r\n\r\n## 更多示例\r\n\r\n* [01_Helloworld](Assets/XLua/Examples/01_Helloworld/): 快速入门的例子。\r\n* [02_U3DScripting](Assets/XLua/Examples/02_U3DScripting/): 展示怎么用 Lua 来写 MonoBehaviour。\r\n* [03_UIEvent](Assets/XLua/Examples/03_UIEvent/): 展示怎么用 Lua 来写 UI 逻辑。\r\n* [04_LuaObjectOrented](Assets/XLua/Examples/04_LuaObjectOrented/): 展示 Lua 面向对象和 C# 的配合。\r\n* [05_NoGc](Assets/XLua/Examples/05_NoGc/): 展示怎么去避免值类型的GC。\r\n* [06_Coroutine](Assets/XLua/Examples/06_Coroutine/): 展示 Lua 协程怎么和 Unity 协程相配合。\r\n* [07_AsyncTest](Assets/XLua/Examples/07_AsyncTest/): 展示怎么用 Lua 协程来把异步逻辑同步化。\r\n* [08_Hotfix](Assets/XLua/Examples/08_Hotfix/): 热补丁的示例（需要开启热补丁特性，如何开启请参考 [xLua 文档: 热补丁](Assets/XLua/Doc/hotfix.md)）。\r\n* [09_GenericMethod](Assets/XLua/Examples/09_GenericMethod/): 泛化函数支持的演示。\r\n* [10_SignatureLoader](Assets/XLua/Examples/10_SignatureLoader/): 展示如何读取经数字签名的lua脚本，参见[数字签名](Assets/XLua/Doc/signature.md)的文档介绍。\r\n* [11_RawObject](Assets/XLua/Examples/11_RawObject/): 当 C# 参数是object时，如何把一个lua number指定以boxing后的int传递过去。\r\n* [12_ReImplementInLua](Assets/XLua/Examples/12_ReImplementInLua/): 展示如何将复杂值类型改为 Lua 实现。\r\n* [14_HotfixAsyncAwait](Assets/XLua/Examples/14_HotfixAsyncAwait/): 展示如何将异步函数和await关键字改为 Lua 实现。\r\n\r\n\u003cbr/\u003e\r\n\r\n## 技术支持\r\n\r\n一群：612705778 (已满)\r\n\r\n二群：703073338 (已满)\r\n\r\n三群：811246782\r\n\r\n入群的问题：有问题该先从哪找答案\r\n\r\n回答：FAQ\r\n\r\n平时也要谨记这答案，90%以上问题都可以在[FAQ](Assets/XLua/Doc/faq.md)里头找到答案。这些问题就别在群刷屏了。\r\n\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftencent%2Fxlua","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftencent%2Fxlua","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftencent%2Fxlua/lists"}