Skip to content
topameng edited this page Jul 11, 2017 · 2 revisions

tolua#

tolua# is a Unity lua static binder solution. the first solution that analyzes code by reflection and generates wrapper classes.

It is a Unity plugin that greatly simplifies the integration of C# code with Lua. which can automatically generate the binding code to access Unity from Lua and map c# constants, variables, functions, properties, classes, and enums to Lua.

tolua# grows up from cstolua. it's goal is to be a powerful development environment for Unity.

Support unity4.6.x and Unity5.x all(copy /Unity5.x/Assets to /Assets)

If you want to test in mobile, first click menu Lua/Copy lua files to Resources. then build it

如果你想在手机上测试,首先点击菜单Lua/Copy lua files to Resources, 之后再build.

有bug 可以到QQ群反馈: 286510803. 不闲聊,非bug相关不要加群, 请加讨论群:
ulua&tolua技术交流群① 341746602(已满)
ulua_tolua技术讨论群② 469941220
ulua&tolua技术交流群3 434341400(已满)
tolua#技术讨论群④ 543826216

Library

tolua_runtime
https://github.com/topameng/tolua_runtime
Debugger
https://github.com/topameng/Debugger
CString
https://github.com/topameng/CString
protoc-gen-lua
https://github.com/topameng/protoc-gen-lua

FrameWork and Demo

LuaFrameWork
https://github.com/jarjin/LuaFramework_NGUI
https://github.com/jarjin/LuaFramework_UGUI
XlsxToLua
https://github.com/zhangqi-ulua/XlsxToLua
UnityHello
https://github.com/woshihuo12/UnityHello
UWA-ToLua
http://uwa-download.oss-cn-beijing.aliyuncs.com/plugins%2FiOS%2FUWA-iOS-ToLua.zip

Debugger

EmmyLua
https://github.com/tangzx/IntelliJ-EmmyLua
unity_tolua-_zerobrane_api
https://github.com/LabOfHoward/unity_tolua-_zerobrane_api

特性

  • 自动生成绑定代码文件,非反射调用
  • 大量内建基础类型支持,如枚举,委托,事件,Type, 数组,迭代器等
  • 支持多种协同形式
  • 支持所有unity内部类导出,支持委托类型导出
  • 支持导出自定义,跳过某个空的基类,修改导出名称等
  • 支持扩展函数导出
  • 支持Lua中function转委托,可以区分需要不同委托的参数的重载函数
  • 支持c# LuaFunction对象转委托, 简化调用方式
  • 支持重载函数自动折叠, 如: Convert.ToUInt32只导出double参数的函数
  • 支持重载函数自动排序, object参数执行级最低, 不会出现错误匹配情况
  • 支持导出函数重命名, 可以分离导出某个重载函数(可以导出被折叠掉的函数)
  • 支持使用编辑器类改写导出规则
  • 支持this数组访问,索引为int可以通过[]访问,其他可使用obj.get_Item或者obj.this:get()访问数组成员
  • 支持委托(事件)+-lua function。独有的-操作支持, 支持通过函数接口的Add和Remove委托操作
  • 支持静态反射操作, 形式同c#
  • 支持peer表,可在lua端扩展导出的userdata
  • 支持自定义struct压入和读取,做到无GC,并且成员无类型限制
  • 支持preloading, 可以通过requie后绑定wrap文件
  • 支持int64, uint64
  • 大量的lua数学类型,如Quaternion, Vector3, Mathf等
  • 包含第三方lua扩展,包括luasocket, struct, lpeg, utf8, pb等库
  • 当lua出现异常,能够同时捕获c#端和lua端堆栈,便于调试
  • print信息,在编辑器点击日志, 能自动打开对应lua文件
  • 支持unity所有版本

快速入门

在CustomSetting.cs中添加需要导出的类或者委托,之后点击菜单Lua->Generate All

LuaState lua = new LuaState();
lua.Start();
lua.DoString("print('hello world')");
lua.Dispose();

这里是更多的示例。  

Performance

平台 属性读写 重载函数 Vector3构造 GameObject构造 Vector3归一化 Slerp
PC 0.0465:0.15 0.076:0.12 0.02:0.001 0.1:0.14 0.014:0.001 0.10:0.11
Android 0.26:1.03 0.39:1.15 0.2:0.0049 0.43:0.5 0.27:0.02 0.49:0.16
iOS 0.04:0.145 0.055:0.146 0.017:0.05 0.074:0.08 0.035:0.11 0.078:0.58

测试结果为C#:Lua. 环境不同会略有差异。可用数字倍率做参考
PC: Intel(R) Core(TM) i5-4590 [email protected] + 8GB + 64 位win7
Android: 中兴nubia z9 max(NX512J) + Adnroid5.0.2
iOS(il2cpp): IPhone6 Plus

About Lua

win, android ios using luajit2.1-beta3. macos using luac5.1.5(for u5.x).

Clone this wiki locally