cocos2dx 3.x以上版本 lua中使用protobuf
2015-06-18 16:30
465 查看
参考 :
http://my.oschina.net/ffs/blog/393574
1. 复制文件 protoc-gen-lua/protobuf/pb.c 到 frameworks\cocos2d-x\external\lua\protobuf\pb.c
2. 修改 frameworks\cocos2d-x\cocos\scripting\lua-bindings\manual\network\lua_extensions.c 文件
这样在lua文件中 require "pb" 即可使用protobuf了
如何根据proto文件生成对应lua文件
1,安装Mercurial-2.9.1.exe,即可使用hg指令
2,打开cmd
3,输入指令hg version,检查安装是否成功
4,输入hg help init,查看帮助
5,输入hg clone https://code.google.com/p/protoc-gen-lua/下载protoc-gen-lua至C:\Users\Administrator目录(将它拷贝到需要存放的位置即可)
6,下载protobuf-2.5.0.tar.gz并解压protobuf-2.5.0
7,cmd进入protobuf-2.5.0\python目录
8,输入python setup.py build编译
9,输入python setup.py install安装
10,进入protobuf-2.5.0\vsprojects,用vs2010打开protobuf.sln,选择protoc为启动项,编译生成protoc.exe
11,将protoc.exe拷贝到protoc-gen-lua\example
12,在protoc-gen-lua\plugin目录下新建protoc-gen-lua.bat文件并输入内容@python "%~dp0protoc-gen-lua"
13,在protoc-gen-lua\example目录下新建build.bat并输入内容如下:
E:\protoc-gen-lua\protoc-gen-lua\example\protoc.exe --lua_out=./ --plugin=protoc-gen-lua="E:\protoc-gen-lua\protoc-gen-lua\plugin\protoc-gen-lua.bat" person.proto
(protoc.exe路径 --lua_out=./ --plugin=protoc-gen-lua.bat路径 proto文件)
14,将proto文件拷贝到protoc-gen-lua\example目录下,运行cmd,进入protoc-gen-lua\example目录,执行build.bat即可生成对应的lua文件(双击也行)
http://my.oschina.net/ffs/blog/393574
1. 复制文件 protoc-gen-lua/protobuf/pb.c 到 frameworks\cocos2d-x\external\lua\protobuf\pb.c
2. 修改 frameworks\cocos2d-x\cocos\scripting\lua-bindings\manual\network\lua_extensions.c 文件
#include "lua_extensions.h" #if __cplusplus extern "C" { #endif // socket #include "protobuf/pb.c" #include "luasocket/luasocket.h" #include "luasocket/luasocket_scripts.h" #include "luasocket/mime.h" static luaL_Reg luax_exts[] = { {"socket.core", luaopen_socket_core}, {"mime.core", luaopen_mime_core}, {NULL, NULL} }; void luaopen_lua_extensions(lua_State *L) { // load extensions luaL_Reg* lib = luax_exts; lua_getglobal(L, "package"); lua_getfield(L, -1, "preload"); for (; lib->func; lib++) { lua_pushcfunction(L, lib->func); lua_setfield(L, -2, lib->name); } lua_pop(L, 2); luaopen_luasocket_scripts(L); luaopen_pb(L); } #if __cplusplus } // extern "C" #endif
这样在lua文件中 require "pb" 即可使用protobuf了
如何根据proto文件生成对应lua文件
1,安装Mercurial-2.9.1.exe,即可使用hg指令
2,打开cmd
3,输入指令hg version,检查安装是否成功
4,输入hg help init,查看帮助
5,输入hg clone https://code.google.com/p/protoc-gen-lua/下载protoc-gen-lua至C:\Users\Administrator目录(将它拷贝到需要存放的位置即可)
6,下载protobuf-2.5.0.tar.gz并解压protobuf-2.5.0
7,cmd进入protobuf-2.5.0\python目录
8,输入python setup.py build编译
9,输入python setup.py install安装
10,进入protobuf-2.5.0\vsprojects,用vs2010打开protobuf.sln,选择protoc为启动项,编译生成protoc.exe
11,将protoc.exe拷贝到protoc-gen-lua\example
12,在protoc-gen-lua\plugin目录下新建protoc-gen-lua.bat文件并输入内容@python "%~dp0protoc-gen-lua"
13,在protoc-gen-lua\example目录下新建build.bat并输入内容如下:
E:\protoc-gen-lua\protoc-gen-lua\example\protoc.exe --lua_out=./ --plugin=protoc-gen-lua="E:\protoc-gen-lua\protoc-gen-lua\plugin\protoc-gen-lua.bat" person.proto
(protoc.exe路径 --lua_out=./ --plugin=protoc-gen-lua.bat路径 proto文件)
14,将proto文件拷贝到protoc-gen-lua\example目录下,运行cmd,进入protoc-gen-lua\example目录,执行build.bat即可生成对应的lua文件(双击也行)
相关文章推荐
- Cocos2d-x实现Android的Toast功能
- cocos2d-x获取系统日期或时间
- quick-cocos2dx中AssetsManagerEx的理解
- cocos2d-x3.x屏蔽下层触摸(制作透明图层暂停界面)
- cocos2d-x 屏幕适配
- cocos2dx android移植,打包生成apk
- cocos2d-x 3.2 在window平台vs2012下解决中文乱码问题
- cocosStudio中如何获取每个部件对象
- Win7+Eclipse搭建Cocos2d-x 3.5开发环境
- sublime_text 2.0.2 绑定cocos2dx lua 开发游戏
- cocos2dx 注册lua回调到c++
- cocos2dx 中如何实现安卓返回按键的反馈
- cocos2d-X 手机游戏《雷电游戏》完整源码下载
- cocos2d-x 体积优化
- cocos2d-x学习笔记——Csv文件读取工具
- cocos2d-x 速度变化
- cocos2dx3.2 win7 的android版本编译及调试
- cocospod 之bug
- cocostudio使用plist创建序列帧动画图片名称序列错乱的问题
- Cocos2dx切换场景和资源崩溃的那些事