protoc-gen-lua中使用 Repeated 标签
发布时间:2020-12-14 21:57:59 所属栏目:大数据 来源:网络整理
导读:比如我这里创建一个 Student.proto --Student.proto message Info { required string name=1; } message Student { required int32 count=1; repeated Info infos=2; } 在C# 里面 Repeated 转出来是对应 List 。 在Lua 里面 Repeated 转出来是对应 Table 的
比如我这里创建一个 Student.proto --Student.proto message Info { required string name=1; } message Student { required int32 count=1; repeated Info infos=2; } 在C# 里面 Repeated 转出来是对应 List 。 编写测试脚本 StudentTest.lua --StudentTest.lua package.path = package.path .. ';./protobuf/?.lua;./protobuf/luascript/?.lua' require("Student_pb") local msg=Student_pb.Student() msg.count=2 local info=Student_pb.Info() info.name="chenpeng" table.insert(msg.infos,info) local info1=Student_pb.Info() info1.name="chenpeng1" table.insert(msg.infos,info1) print("msg.infos count=" .. table.maxn(msg.infos)) print("---------------------------") for i=1,table.maxn(msg.infos) do print(msg.infos[i]) end print("---------------------------") for key,value in pairs(msg.infos) do print(key) print(value.name) end 附件中附带了继承 protoc-gen-lua 的 jit2.0.3 。直接运行脚本即可。
name: chenpeng1
测试工程下载: http://pan.baidu.com/s/1jGnk4Rk (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |