C++服务器搭建之(protoc-gen-lua将pb生成lua)

所需文件安装包:

python-2.7.2.msi

python安装程序                            Download Python | Python.org

LuaForWindows_v5.1.4-45.exe

lfw安装程序                                  http://code.google.com/p/luaforwindows/downloads/list

protobuf-2.4.1.zip

PB源代码包                                  http://code.google.com/p/protobuf/downloads/list

protoc-gen-lua.rar

lua protocol buffers 生成工具       http://code.google.com/p/protoc-gen-lua/

安装步骤:

1.假设你的.proto文件和要使用PB的lua程序代码文件都在d:\bin目录下(当然你愿意放哪儿随你便)

2.安装python (python-2.7.2.msi),安装完成后 手动在系统的环境变量path中添加python27的安装路径

3.安装lua (LuaForWindows_v5.1.4-45.exe)最好安装在d:或c:的根目录 如d:\lua

4.解压缩protobuf-2.4.1.zip到硬盘 如d:\protobuf-2.4.1

5.进入d:\protobuf-2.4.1目录中的python目录安装python包 python setup.py install

6.把protoc-gen-lua解压到d:或c:根目录 如: d:\protoc-gen-lua 进入目录

7.在plugin目录里建一个protoc-gen-lua.bat(如果没有)写一句@python d:\protoc-gen-lua\plugin\protoc-gen-lua 保存退出

8.进入d:\protoc-gen-lua\protobuf目录,把里面的文件全都拷到d:\bin\目录(9个lua文件,一个pd.dll)

9.在d:\bin里编写一个build.bat并写上:d:\protobuf-2.4.1\src\protoc.exe --lua_out=./ --plugin=protoc-gen-lua="d:\protoc-gen-lua\plugin\protoc-gen-lua.bat" xxxxxx.proto

10. 在管理员的cmd命令行里运行build.bat,如果成功会生成一个 xxxxxx_pb.lua文件

11.在lua程序代码中require " xxxxxx_pb"即可使用

注意:

注意:版本匹配,2.x python 匹配 2.x protobuf 匹配 2.x protoc-gen-lua, x是未知数,版本不匹配将出现严重问题,例如选用3.x python安装 2.x protobuf 和 2.x protoc-gen-lua 将会出现各种问题

repeated string 类型的字段会有问题,尽量使用bytes类型,这个问题新版已解决

在写proto文件时如果有repeated别的message结构时,请把引用的message结构定义在前面

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值