参考文章:cocos2dx使用lua和protobuf

首先得下载protobuf-gen-lua的插件,插件Git地址在此。

下载完之后进入到protoc-gen-lua\plugin这个目录,并在其中建立一个批处理文件:

@python E:\3rd\quick-x-protobuf\proto-gen-lua\protoc-gen-lua\plugin\protoc-gen-lua

然后进入到上一篇笔记中的addressbook.proto所在的文件夹内,运行如下命令:

protoc --lua_out=生成的lua存放地址 --plugin=protoc-gen-lua=上面新建的bat的完整地址 addressbook.proto

回车。

我们到目标地址下面就会看到一个addressbook_pb.lua文件,内容如下:

-- Generated By protoc-gen-lua Do not Edit
local protobuf = require "protobuf"
module('addressbook_pb') local PERSON = protobuf.Descriptor();
local PERSON_PHONENUMBER = protobuf.Descriptor();
local PERSON_PHONENUMBER_NUMBER_FIELD = protobuf.FieldDescriptor();
local PERSON_PHONENUMBER_TYPE_FIELD = protobuf.FieldDescriptor();
local PERSON_PHONETYPE = protobuf.EnumDescriptor();
local PERSON_PHONETYPE_MOBILE_ENUM = protobuf.EnumValueDescriptor();
local PERSON_PHONETYPE_HOME_ENUM = protobuf.EnumValueDescriptor();
local PERSON_PHONETYPE_WORK_ENUM = protobuf.EnumValueDescriptor();
local PERSON_NAME_FIELD = protobuf.FieldDescriptor();
local PERSON_ID_FIELD = protobuf.FieldDescriptor();
local PERSON_EMAIL_FIELD = protobuf.FieldDescriptor();
local PERSON_PHONE_FIELD = protobuf.FieldDescriptor();
local ADDRESSBOOK = protobuf.Descriptor();
local ADDRESSBOOK_PERSON_FIELD = protobuf.FieldDescriptor(); PERSON_PHONENUMBER_NUMBER_FIELD.name = "number"
PERSON_PHONENUMBER_NUMBER_FIELD.full_name = ".tutorial.Person.PhoneNumber.number"
PERSON_PHONENUMBER_NUMBER_FIELD.number =
PERSON_PHONENUMBER_NUMBER_FIELD.index =
PERSON_PHONENUMBER_NUMBER_FIELD.label =
PERSON_PHONENUMBER_NUMBER_FIELD.has_default_value = false
PERSON_PHONENUMBER_NUMBER_FIELD.default_value = ""
PERSON_PHONENUMBER_NUMBER_FIELD.type =
PERSON_PHONENUMBER_NUMBER_FIELD.cpp_type = PERSON_PHONENUMBER_TYPE_FIELD.name = "type"
PERSON_PHONENUMBER_TYPE_FIELD.full_name = ".tutorial.Person.PhoneNumber.type"
PERSON_PHONENUMBER_TYPE_FIELD.number =
PERSON_PHONENUMBER_TYPE_FIELD.index =
PERSON_PHONENUMBER_TYPE_FIELD.label =
PERSON_PHONENUMBER_TYPE_FIELD.has_default_value = true
PERSON_PHONENUMBER_TYPE_FIELD.default_value = HOME
PERSON_PHONENUMBER_TYPE_FIELD.enum_type = _PERSON_PHONETYPE
PERSON_PHONENUMBER_TYPE_FIELD.type =
PERSON_PHONENUMBER_TYPE_FIELD.cpp_type = PERSON_PHONENUMBER.name = "PhoneNumber"
PERSON_PHONENUMBER.full_name = ".tutorial.Person.PhoneNumber"
PERSON_PHONENUMBER.nested_types = {}
PERSON_PHONENUMBER.enum_types = {}
PERSON_PHONENUMBER.fields = {PERSON_PHONENUMBER_NUMBER_FIELD, PERSON_PHONENUMBER_TYPE_FIELD}
PERSON_PHONENUMBER.is_extendable = false
PERSON_PHONENUMBER.extensions = {}
PERSON_PHONENUMBER.containing_type = PERSON
PERSON_PHONETYPE_MOBILE_ENUM.name = "MOBILE"
PERSON_PHONETYPE_MOBILE_ENUM.index =
PERSON_PHONETYPE_MOBILE_ENUM.number =
PERSON_PHONETYPE_HOME_ENUM.name = "HOME"
PERSON_PHONETYPE_HOME_ENUM.index =
PERSON_PHONETYPE_HOME_ENUM.number =
PERSON_PHONETYPE_WORK_ENUM.name = "WORK"
PERSON_PHONETYPE_WORK_ENUM.index =
PERSON_PHONETYPE_WORK_ENUM.number =
PERSON_PHONETYPE.name = "PhoneType"
PERSON_PHONETYPE.full_name = ".tutorial.Person.PhoneType"
PERSON_PHONETYPE.values = {PERSON_PHONETYPE_MOBILE_ENUM,PERSON_PHONETYPE_HOME_ENUM,PERSON_PHONETYPE_WORK_ENUM}
PERSON_NAME_FIELD.name = "name"
PERSON_NAME_FIELD.full_name = ".tutorial.Person.name"
PERSON_NAME_FIELD.number =
PERSON_NAME_FIELD.index =
PERSON_NAME_FIELD.label =
PERSON_NAME_FIELD.has_default_value = false
PERSON_NAME_FIELD.default_value = ""
PERSON_NAME_FIELD.type =
PERSON_NAME_FIELD.cpp_type = PERSON_ID_FIELD.name = "id"
PERSON_ID_FIELD.full_name = ".tutorial.Person.id"
PERSON_ID_FIELD.number =
PERSON_ID_FIELD.index =
PERSON_ID_FIELD.label =
PERSON_ID_FIELD.has_default_value = false
PERSON_ID_FIELD.default_value =
PERSON_ID_FIELD.type =
PERSON_ID_FIELD.cpp_type = PERSON_EMAIL_FIELD.name = "email"
PERSON_EMAIL_FIELD.full_name = ".tutorial.Person.email"
PERSON_EMAIL_FIELD.number =
PERSON_EMAIL_FIELD.index =
PERSON_EMAIL_FIELD.label =
PERSON_EMAIL_FIELD.has_default_value = false
PERSON_EMAIL_FIELD.default_value = ""
PERSON_EMAIL_FIELD.type =
PERSON_EMAIL_FIELD.cpp_type = PERSON_PHONE_FIELD.name = "phone"
PERSON_PHONE_FIELD.full_name = ".tutorial.Person.phone"
PERSON_PHONE_FIELD.number =
PERSON_PHONE_FIELD.index =
PERSON_PHONE_FIELD.label =
PERSON_PHONE_FIELD.has_default_value = false
PERSON_PHONE_FIELD.default_value = {}
PERSON_PHONE_FIELD.message_type = PERSON_PHONENUMBER
PERSON_PHONE_FIELD.type =
PERSON_PHONE_FIELD.cpp_type = PERSON.name = "Person"
PERSON.full_name = ".tutorial.Person"
PERSON.nested_types = {PERSON_PHONENUMBER}
PERSON.enum_types = {PERSON_PHONETYPE}
PERSON.fields = {PERSON_NAME_FIELD, PERSON_ID_FIELD, PERSON_EMAIL_FIELD, PERSON_PHONE_FIELD}
PERSON.is_extendable = false
PERSON.extensions = {}
ADDRESSBOOK_PERSON_FIELD.name = "person"
ADDRESSBOOK_PERSON_FIELD.full_name = ".tutorial.AddressBook.person"
ADDRESSBOOK_PERSON_FIELD.number =
ADDRESSBOOK_PERSON_FIELD.index =
ADDRESSBOOK_PERSON_FIELD.label =
ADDRESSBOOK_PERSON_FIELD.has_default_value = false
ADDRESSBOOK_PERSON_FIELD.default_value = {}
ADDRESSBOOK_PERSON_FIELD.message_type = PERSON
ADDRESSBOOK_PERSON_FIELD.type =
ADDRESSBOOK_PERSON_FIELD.cpp_type = ADDRESSBOOK.name = "AddressBook"
ADDRESSBOOK.full_name = ".tutorial.AddressBook"
ADDRESSBOOK.nested_types = {}
ADDRESSBOOK.enum_types = {}
ADDRESSBOOK.fields = {ADDRESSBOOK_PERSON_FIELD}
ADDRESSBOOK.is_extendable = false
ADDRESSBOOK.extensions = {} AddressBook = protobuf.Message(ADDRESSBOOK)
Person = protobuf.Message(PERSON)
Person.PhoneNumber = protobuf.Message(PERSON_PHONENUMBER)

实验完成,打算下一步把这个整合到自己的手游demo里面去,有机会我会好好阅读protoc-gen-lua代码的,现在最要紧的是下班,呵呵。

照着例子学习 protobuf-lua的更多相关文章

  1. Redis源码学习:Lua脚本

    Redis源码学习:Lua脚本 1.Sublime Text配置 我是在Win7下,用Sublime Text + Cygwin开发的,配置方法请参考<Sublime Text 3下C/C++开 ...

  2. 数百个 HTML5 例子学习 HT 图形组件 – 3D建模篇

    http://www.hightopo.com/demo/pipeline/index.html <数百个 HTML5 例子学习 HT 图形组件 – WebGL 3D 篇>里提到 HT 很 ...

  3. 数百个 HTML5 例子学习 HT 图形组件 – 3D 建模篇

    http://www.hightopo.com/demo/pipeline/index.html <数百个 HTML5 例子学习 HT 图形组件 – WebGL 3D 篇>里提到 HT 很 ...

  4. 数百个 HTML5 例子学习 HT 图形组件 – WebGL 3D 篇

    <数百个 HTML5 例子学习 HT 图形组件 – 拓扑图篇>一文让读者了解了 HT的 2D 拓扑图组件使用,本文将对 HT 的 3D 功能做个综合性的介绍,以便初学者可快速上手使用 HT ...

  5. 数百个 HTML5 例子学习 HT 图形组件 – 拓扑图篇

    HT 是啥:Everything you need to create cutting-edge 2D and 3D visualization. 这口号是当年心目中的产品方向,接着就朝这个方向慢慢打 ...

  6. HTML5 例子学习 HT 图形组件

    HTML5 例子学习 HT 图形组件 HT 是啥:Everything you need to create cutting-edge 2D and 3D visualization. 这口号是当年心 ...

  7. pytorch例子学习-DATA LOADING AND PROCESSING TUTORIAL

    参考:https://pytorch.org/tutorials/beginner/data_loading_tutorial.html DATA LOADING AND PROCESSING TUT ...

  8. Lua学习---编译生成lua和luac

    众所周知,Lua是一种强大的脚本语言,并且这种语言是用C语言实现的.为什么要学习这门语言?因为它可以增强我看C语言代码的功底. 我下的Lua版本是Lua5.3,关于Lua5.3的简介如下: http: ...

  9. 通过例子学习C++(二)最小公倍数

    本文是通过例子学习C++的第二篇,通过这个例子可以快速入门c++相关的语法. 题目要求:输入两个整数,求其最小公倍数. 解答方法一:两个数的最小公倍数,是这两个数中的大数,或者是这2个数的倍数中的最小 ...

  10. 通过例子学习C++(三)最大公约数,并知其然

    本文是通过例子学习C++的第三篇,通过这个例子可以快速入门c++相关的语法. 题目要求:输入两个整数,求其大公约数. 解答方法一:两个数的最大公约数,是这两个数中的小数,或者是这2个数的公约数中的最大 ...

随机推荐

  1. spice-vdagent

    The spice-vdagent should be running in the guest. Have you installed the spice guest tools in your w ...

  2. ng-if 和 ng-show/ng-hide 之间的区别

    ng-if会移除dom,生成dom,而ng-show只是改变其display属性.所以你自己看着用吧.

  3. java.sql.ResultSet技术(从数据库查询出的结果集里取列值)

    里面有一个方法可以在查询的结果集里取出列值,同理,存储过程执行之后返回的结果集也是可以取到的. 如图: 然后再运用 java.util.Hashtable 技术.把取到的值放入(K,V)的V键值里,K ...

  4. C#设置默认打印机

    项目中,需要选择打印机,切换打印机.demo如下(wpf应用程序): Xaml: <Window x:Class="PrintersApp.MainWindow" xmlns ...

  5. C语言头文件

    最近在工作当中遇到了一点小问题,关于C语言头文件的应用问题,主要还是关于全局变量的定义和声明问题.学习C语言已经有好几年了,工作使用也近半年了,但是对于这部分的东西的确还没有深入的思考过.概念上还是比 ...

  6. 安卓常用 widget

    验证码 public class SpinnerImg extends ImageView { /** * 完成选择后启动另外一个spinner */ private ItemListener ite ...

  7. php 图片压缩处理

    <?php require dirname(__FILE__).'/../includes/common.inc.php'; $_clean = array(); $_info = array( ...

  8. Struts2中的验证框架

    通过注解的方式,可以让方法不用验证 @SkipValidation public String toRegView() { System.out.println("toRegView&quo ...

  9. Activity与Activity之间的传值

    //----------Activity1中的布局--------------------------------- <LinearLayout xmlns:android="http ...

  10. elasticsearch集群内部节点超时解决

    默认配置为:节点每隔1s同master发送1次心跳,超时时间为30s,测试次数为3次,超过3次,则认为该节点同master已经脱离了.以上为elasticsearch的默认配置.在实际生产环境中,每隔 ...