cocos2d-x中集成protoc-gen-lua
发布时间:2020-12-14 17:12:45 所属栏目:百科 来源:网络整理
导读:【版本说明】 python:2.7.5 protobuf:2.5.0 lua:5.1.5 protoc-gen-lua:latest cocos2d-x:3.2 【安装步骤】 1. python/lua/cocos2d-x环境默认已安装 安装protobuf 进入protobuf-2.5.0python,执行: 1 2 3 python setup.py build python setup.py test
【版本说明】
python:2.7.5
protobuf:2.5.0
lua:5.1.5
protoc-gen-lua:latest
cocos2d-x:3.2
【安装步骤】
1. python/lua/cocos2d-x环境默认已安装
安装protobuf
进入protobuf-2.5.0python,执行:
1
2
3
|
python setup.py build
python setup.py test
python setup.py install
|
2.protoc-gen-lua解压放置到某个目录下,假定为c:
protoc-gen-luaplugin下创建protoc-gen-lua.bat,文件内容为:
|
python c:protoc
-
gen
luapluginprotoc
lua
|
3. 通过proto生成lua,命令为:
|
1
|
protoc
-
-
lua_out
=
.
/
plugin
gen
lua
=
"c:protoc-gen-luapluginprotoc-gen-lua.bat"
person.proto
|
|
【集成步骤】
1. 加入pb.c文件,在frameworkscocos2d-xexternallua下创建protobuf目录,copy pb.c文件至此
win32下编译出错,修改pb.c文件如下:
#ifndef _WIN32 //添加
#include <endian.h>
#endif //添加
14
15
16
17
18
#if __cplusplus
{
#endif
/
/
socket
#include "luasocket/luasocket.h"
#include "lpack/lpack.h"
#include "protobuf/pb.h" //添加
static luaL_Reg luax_exts[]
=
{
{
"cjson"
,luaopen_cjson_safe},
"pack"
"pb"
添加
"socket.core"
"mime.core"
{NULL,NULL}
};
|
6
import
"Base.proto"
message PlayerMsg {
optional pb.BaseMsg msg
=
1
;
...
3.修改protoc-gen-luapluginprotoc-gen-lua文件:
if
field_desc.HasField(
'type_name'
):
type_name
env.get_ref_name(field_desc.type_name).upper()
这一行
field_desc.
type
=
FDP.TYPE_MESSAGE:
|
7
def
code_gen_message(message_descriptor,env,containing_type
=
None
env.enter(message_descriptor.name)
full_name
env.get_local_name()
obj_name
full_name.upper().replace(
'.'
'_'
)
env.descriptor.append(
"%s = protobuf.Descriptor();n"
%
这一行去掉local
)
|
is_gen:
lua
Writer()
write_header(lua)
lua(
'local protobuf = require "protobuf"n'
for
i
in
includes:
'local %s_PB = require("%s_pb")n'
(i.upper(),i))
这一行PB大写
"module('%s_pb')n"
env.filename)