cocos2dx android protobuf,cocos2dx 3.x以上版本 lua中使用protobuf

参考 :

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文件(双击也行)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值