1 Star 1 Fork 0

ondaly / xLua

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

license release PRs Welcome Build status

(English Documents Available)

C#下Lua编程支持

xLua为Unity、 .Net、 Mono等C#环境增加Lua脚本编程的能力,借助xLua,这些Lua代码可以方便的和C#相互调用。

xLua的突破

xLua在功能、性能、易用性都有不少突破,这几方面分别最具代表性的是:

  • 可以运行时把C#实现(方法,操作符,属性,事件等等)替换成lua实现;
  • 出色的GC优化,自定义struct,枚举在Lua和C#间传递无C# gc alloc;
  • 编辑器下无需生成代码,开发更轻量;

更详细的特性、平台支持介绍请看这里

安装

打开zip包,你会看到一个Assets目录,这目录就对应Unity工程的Assets目录,保持这目录结构放到你的Unity工程。

如果希望安装到其它目录,请看FAQ相关介绍。

文档

快速入门

一个完整的例子仅需3行代码:

安装好xLua,建一个MonoBehaviour拖到场景,在Start加入如下代码:

XLua.LuaEnv luaenv = new XLua.LuaEnv();
luaenv.DoString("CS.UnityEngine.Debug.Log('hello world')");
luaenv.Dispose();

1、DoString参数为string,可输入任意合法的Lua代码,本示例在lua里调用C#的UnityEngine.Debug.Log打印了个日志。

2、一个LuaEnv实例对应Lua虚拟机,出于开销的考虑,建议全局唯一。

C#主动调用lua也很简单,比如要调用lua的系统函数,推荐方式是:

  • 声明
[XLua.CSharpCallLua]
public delegate double LuaMax(double a, double b);
  • 绑定
var max = luaenv.Global.GetInPath<LuaMax>("math.max");
  • 调用
Debug.Log("max:" + max(32, 12));

建议绑定一次,重复使用。生成了代码的话,调用max是不产生gc alloc的。

热补丁

  • 侵入性小,老项目原有代码不做任何调整就可使用。
  • 运行时影响小,不打补丁基本和原有程序一样。
  • 出问题了可以用Lua来打补丁,这时才会走到lua代码逻辑;

这里是使用指南。

更多示例

技术支持

一群:612705778 (已满)

二群:703073338 (已满)

三群:811246782

入群的问题:有问题该先从哪找答案

回答:FAQ

平时也要谨记这答案,90%以上问题都可以在FAQ里头找到答案。这些问题就别在群刷屏了。

Tencent is pleased to support the open source community by making xLua available. Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. If you have downloaded a copy of the xLua binary from Tencent, please note that the xLua binary is licensed under the MIT License. If you have downloaded a copy of the xLua source code from Tencent, please note that xLua source code is licensed under the MIT License, except for the third-party components listed below which are subject to different license terms. Your integration of xLua into your own projects may require compliance with the MIT License, as well as the other licenses applicable to the third-party components included within xLua. A copy of the MIT License is included in this file. Other dependencies and licenses: Open Source Software Licensed under the BSD 3-Clause License: -------------------------------------------------------------------- 1. android-cmake Copyright (c) 2010-2011, Ethan Rublee Copyright (c) 2011-2014, Andrey Kamaev All rights reserved. Copyright (c) 2014, Pavel Rojtberg All rights reserved. Terms of the BSD 3-Clause License: -------------------------------------------------------------------- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ?Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. ?Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. ?Neither the name of [copyright holder] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Open Source Software Licensed Under the MIT License: -------------------------------------------------------------------- 1. Lua 5.1.5 & 5.3.3 & 5.3.4 Copyright (C) 1994-2016 Lua.org, PUC-Rio. 2. LuaJIT 2.1.0beta2 Copyright (C) 2005-2016 Mike Pall. All rights reserved. 3. luasocket 3.0-rc1 Copyright ? 1999-2013 Diego Nehab. All rights reserved. 4. Cecil 0.9.6 Copyright (c) 2008 - 2015 Jb Evain Copyright (c) 2008 - 2011 Novell, Inc. Terms of the MIT License: -------------------------------------------------------------------- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Tencent 腾讯 xLua Unity热更新 展开 收起
C# 等 6 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C#
1
https://gitee.com/daly2077/xLua.git
git@gitee.com:daly2077/xLua.git
daly2077
xLua
xLua
master

搜索帮助