Overview

Install

  1. Install python runtime and the protobuf 2.3 for python.

  2. Checkout the code hg clone https://code.google.com/p/protoc-gen-lua/

  3. Install the Lua module

    $ cd protobuf/ $ luarocks make #optionally with sudo

  4. Make a link to protoc-gen-lua in your $PATH:

    $cd /usr/local/bin && sudo ln -s /path/to/protoc-gen-lua/plugin/protoc-gen-lua

  5. Then you can compile the .proto like this:

    protoc --lua_out=./ foo.proto

Quick Example

You write a .proto file like this:

person.proto : message Person { required int32 id = 1; required string name = 2; optional string email = 3; }

Then you compile it using protoc --lua_out=./ person.proto. This will generate a file called person_pb.lua. You can use it in your Lua script like that:

require "person_pb"

-- Serialize Example
local msg = person_pb.Person()
msg.id = 100
msg.name = "foo"
msg.email = "bar"
local pb_data = msg:SerializeToString()

-- Parse Example
local msg = person_pb.Person()
msg:ParseFromString(pb_data)
print(msg.id, msg.name, msg.email)

The API of this library is similar the protobuf library for python. For a more complete example, read the python protobuf documentation.