http://blog.csdn.net/weyson/article/details/17024325
http://www.cppblog.com/colorful/archive/2015/01/17/209557.html
http://blog.csdn.net/w00w12l/article/details/39316321
protoc-gen-lua下载地址:
https://github.com/sean-lin/protoc-gen-lua1/ 先到protobuf的python目录下执行
python setup.py build
python setup.py install
2/ 在protoc-gen-lua的plugin目录中新建protoc-gen-lua.bat, 内容如下:
@python 目录\protoc-gen-lua\plugin\protoc-gen-lua
3/ 用protoc把proto文件生成lua文件
protoc --lua_out=./ --plugin=protoc-gen-lua="目录\protoc-gen-lua.bat" test.proto
4/ 将protoc-gen-lua/protobuf下的pb.c 放到工程的Classes下, 并加入到c++工程中
5/ 将protoc-gen-lua/protobuf上的所有lua文件放到工程的src目录(lua目录)下
6/ AppDelegate.cpp 添加代码
extern "C"{
int luaopen_pb(lua_State* L);
}
在applicationDidFinishLaunching()中调用 luaopen_pb(state);
---------------------------------------------------------------------------
require "src/xy/person_pb"
local msg = person_pb.Person()
msg.id = 100
msg.name = "foo"
msg.email = "bar"
local pb_data = msg:SerializeToString() -- Parse Example
print("create:", msg.id, msg.name, msg.email, pb_data)
local msg = person_pb.Person()
msg:ParseFromString(pb_data)
print("parser:", msg.id, msg.name, msg.email, pb_data)
---------------------------------------------------------------------------
移植到android 记得将pb.c添加到proj.android\jni\Android.mk中