ToLua

Skip to content

 

Sign out

topameng/tolua

 Code Issues 3 Pull requests 1 Projects 0 Wiki Insights

The fastest unity lua binding solution

unityluabindluajittolua

  1.  C# 60.6%
  2.  Lua 39.3%
  3.  Batchfile 0.1%

C#LuaBatchfile

Branch: master 

New pull request

Create new file

Upload filesFind file

Clone or download 

@topameng

topameng 更新下群信息

Latest commit 7a4fe1c 5 days ago

TypeNameLatest commit messageCommit time
 Assets1.0.8.536 dofile 加载文件出错。返回异常7 days ago
 Luajit1.0.7.328 加入luajit64在pc64位和ios上编译64位bytecode2 years ago
 Luajit641.0.7.328 加入luajit64在pc64位和ios上编译64位bytecode2 years ago
 ProjectSettings1.0.5.173 LuaLooper update略早于默认时序3 years ago
 Unity5.x/Assets/Plugins1.0.6.235 去掉5.x分支,增加unity5.x目录3 years ago
 .gitignore1.03 years ago
 LICENSEInitial commit3 years ago
 README.md更新下群信息5 days ago

 README.md

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 examples(example 1 is excluded)in mobile, first click menu Lua/Copy lua files to Resources. then build it 
如果你想在手机上测试例子(例子1除外),首先点击菜单Lua/Copy lua files to Resources, 之后再build. 

欢迎大家点星支持,谢谢^_^
有bug 可以到QQ群286510803反馈。 可以加讨论群: 
ulua&tolua技术交流群① 341746602(已满) 
ulua&tolua技术讨论群② 469941220(已满) 
tolua#技术讨论群④ 543826216(已满)
tolua#技术群 286510803

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

Packages

 Basics        Math      Data Structures
 luabitop       Quaternion       list
  struct         Vector3        event
  int64          Vector4        slot
  Time          Vector2
Networking        Ray
 luasocket         Color
 Parsing        Bounds
 lpeg             Mathf
 Protol           Touch
 pblua          RaycastHit

特性

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

快速入门

在CustomSetting.cs中添加需要导出的类或者委托,类加入到customTypeList列表,委托加入到customDelegateList列表 
通过设置saveDir变量更改导出目录,默认生成在Assets/Source/Generate/下,点击菜单Lua->Generate All,生成绑定文件 
在LuaConst.cs中配置开发lua文件目录luaDir以及tolua lua文件目录toluaDir 

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

//例子2
LuaState luaState = null;

void Awake()
{
    luaState = LuaClient.GetMainState();

    try
    {            
        luaState.Call("UIShop.Awake", false);
    }
    catch (Exception e)
    {
        //Awake中必须这样特殊处理异常
        luaState.ThrowLuaException(e);
    }
}

void Start()
{
    luaState.Call("UIShop.Start", false);
}
local go = GameObject('go')
go:AddComponent(typeof(UnityEngine.ParticleSystem))
go.transform.position = Vector3.zero
go.transform:Rotate(Vector3(0,90,0), UnityEngine.Space.World)
go.transform:Rotate(Vector3(0, 1, 0), 0)

--DoTween 需要在CustomSetting导出前定义USING_DOTWEENING宏,或者取消相关注释
go.transform:DORotate(Vector3(0,0,360), 2, DG.Tweening.RotateMode.FastBeyond360)

Shop = {}

function Shop:Awake()
    self.OnUpdate = UpdateBeat:CreateListener(Shop.Update, self)
    UpdateBeat:AddListener(self.OnUpdate)
end

function Shop:OnDestroy()
    UpdateBeat:RemoveListener(self.OnUpdate)
end

function Shop:OnClick()
    print("OnClick")
end

function Shop:OnToggle()
    print("OnToggle")
end

function Shop:Update()
end

--委托
local listener = UIEventListener.Get(go)
listener.onClick = function() print("OnClick") end
listener.onClick = nil
listener.onClick = UIEventListener.VoidDelegate(Shop.OnClick, Shop)
listener.onClick = listener.onClick + UIEventListener.VoidDelegate(Shop.OnClick, Shop)
listener.onClick = listener.onClick - UIEventListener.VoidDelegate(Shop.OnClick, Shop)

local toggle = go:GetComponent(typeof(UIToggle))
EventDelegate.Add(toggle.onChange, EventDelegate.Callback(Shop.OnToggle, Shop))
EventDelegate.Remove(toggle.onChange, EventDelegate.Callback(Shop.OnToggle, Shop))

--事件
local Client = {}

function Client:Log(str)
end

Application.logMessageReceived = Application.logMessageReceived + Application.LogCallback(Clent.Log, Client)
Application.logMessageReceived = Application.logMessageReceived - Application.LogCallback(Clent.Log, Client)

--out参数
local _layer = 2 ^ LayerMask.NameToLayer('Default')
local flag, hit = UnityEngine.Physics.Raycast(ray, nil, 5000, _layer)

if flag then
    print('pick from lua, point: '..tostring(hit.point))
end

这里是更多的示例。

关于反射

tolua# 不支持动态反射。动态反射对于重载函数有参数匹配问题,函数排序问题,ref,out 参数问题等等。
tolua#提供的替换方法是:

  1. preloading, 把你未来可能需要的类型添加到导出列表customTypeList,同时也添加到dynamicList列表中,这样导出后该类型并不会随binder注册到lua中,你可以通过 require "namespace.classname" 动态注册到lua中,对于非枚举类型tolua#系统也可以在第一次push该类型时动态载入,当然也可在过场动画、资源下载、登录、场景加载或者某个的函数中require这个类型。
  2. 静态反射,参考例子22。通过静态反射支持精确的函数参数匹配和类型检查。不会存在重载函数参数混乱匹配错误问题, 注意iOS必须配置好link.xml

Performance

平台属性读写重载函数Vector3构造GameObject构造Vector3归一化Slerp
PC0.0465:0.150.076:0.120.02:0.0010.1:0.140.014:0.0010.10:0.11
Android0.16:1.10.28:0.760.17:0.000350.43:0.50.21:0.020.3:0.06
iOS0.04:0.1450.055:0.110.017:0.050.074:0.080.035:0.110.078:0.5

测试结果为C#:Lua. 环境不同会略有差异。可用数字倍率做参考
PC: Intel(R) Core(TM) i5-4590 CPU@3.3GHz + 8GB + 64 位win7 + Unity5.4.5p4
Android: 中兴nubia z9 max(NX512J) + Adnroid5.0.2
iOS(il2cpp): IPhone6 Plus
按照1.0.7.355版本更新了测试数据, u5相对u4, 安卓上c#有了不小的提升

Examples

参考包内1-24例子

About Lua

win, android ios using luajit2.1-beta3. macos using luac5.1.5(for u5.x). 注意iOS未编译模拟器库,请用真机测试

 

Press h to open a hovercard with more details.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园整体解决方案是响应国家教育信息化政策,结合教育改革和技术创新的产物。该方案以物联网、大数据、人工智能和移动互联技术为基础,旨在打造一个安全、高效、互动且环保的教育环境。方案强调从数字化校园向智慧校园的转变,通过自动数据采集、智能分析和按需服务,实现校园业务的智能化管理。 方案的总体设计原则包括应用至上、分层设计和互联互通,确保系统能够满足不同用户角色的需求,并实现数据和资源的整合与共享。框架设计涵盖了校园安全、管理、教学、环境等多个方面,构建了一个全面的校园应用生态系统。这包括智慧安全系统、校园身份识别、智能排课及选课系统、智慧学习系统、精品录播教室方案等,以支持个性化学习和教学评估。 建设内容突出了智慧安全和智慧管理的重要性。智慧安全管理通过分布式录播系统和紧急预案一键启动功能,增强校园安全预警和事件响应能力。智慧管理系统则利用物联网技术,实现人员和设备的智能管理,提高校园运营效率。 智慧教学部分,方案提供了智慧学习系统和精品录播教室方案,支持专业级学习硬件和智能化网络管理,促进个性化学习和教学资源的高效利用。同时,教学质量评估中心和资源应用平台的建设,旨在提升教学评估的科学性和教育资源的共享性。 智慧环境建设则侧重于基于物联网的设备管理,通过智慧教室管理系统实现教室环境的智能控制和能效管理,打造绿色、节能的校园环境。电子班牌和校园信息发布系统的建设,将作为智慧校园的核心和入口,提供教务、一卡通、图书馆等系统的集成信息。 总体而言,智慧校园整体解决方案通过集成先进技术,不仅提升了校园的信息化水平,而且优化了教学和管理流程,为学生、教师和家长提供了更加便捷、个性化的教育体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值