toLua使用protobuf协议转Lua表

原贴:http://blog.csdn.net/wuming0108/article/details/70161886

根据原贴会有一点点小坑,这里我将其重新整理一下。

我使用的环境:

1、unity5.3.3

2、使用的LuaFramwWork_NGUI插件:https://github.com/jarjin/LuaFramework_NGUI

3、protobuf:https://github.com/google/protobuf

4、protoc-gen-lua:https://github.com/sean-lin/protoc-gen-lua

5、protoc:https://github.com/google/protobuf/releases

6、python:我用的py27,自己下载,程序猿不要这么懒。

以上内容到位后开始以下操作:

1、把上面5解压后的Protoc放到3的protobuf/src下,5解压后的目录下有个bin,把bin下的protoc.exe也复制到3的protobuf/src下。

2. cmd进入到上面3的protobuf/python 执行以下命令

  python setup.py build
  python setup.py install

3、执行2如果有下图的错误,说明1操作不正确,也就是protoc.exe没有按1说的复制过去。

4、进入protoc-gen-lua/plugin 下面 新建一个protoc-gen-lua.bat 把以下内容填写进去,星号为protoc-gen-lua的路径

@python ****protoc-gen-luapluginprotoc-gen-lua

注:

在每个protoc-gen-lua生成的lua文件里, 都有一行

local protobuf = require "protobuf"

本身按照官方出的没问题, 但是在ulua的目录里, 总是报protobuf找不到的错误. 前后对比了下我生成的lua和ulua官方生成的代码里

发现居然他修改了地址改为了

local protobuf = require "protobuf/protobuf"

好吧, 只有修改生成器代码protoc-gen-luapluginprotoc-gen-lua中第412行改为

lua('local protobuf = require "protobuf/protobuf"
')
 如果有需要,自己去protoc-gen-lua/plugin的目录下对plugin_pb2.py这个脚本进行调整。

5. 进入Unity Packager.cs BuildProtobufFile函数

dir 修改为proto文件路径

protoc修改为 protobuf/src/protoc.exe

protoc_gen_dir 修改为protoc-gen-lua.bat的路径

6、 unity 菜单LuaFramework/Build Protobuf-lua-gen File 点击生成

有问题的小伙伴可以加我QQ或者发QQ邮件,我在博客签名里留下了我的QQ号。

原文地址:https://www.cnblogs.com/vsirWaiter/p/7553688.html