Skip to main content

lua-protobuf provides a Lua interface to Google's Protocol Buffers.

Producing Code

lua-protobuf provides a plugin for the protoc protocol buffer compiler (it ships with protocol buffers). This plugin tells protoc to produce a set of C++ output files, which define the Lua interface to protocol buffers using the Lua C API.

First, obtain a copy of lua-protobuf:

$ git clone git@github.com:indygreg/lua-protobuf.git
$ cd lua-protobuf

Next, install lua-protobuf:

$ python setup.py install

Yes, lua-protobuf is written in Python (for now at least).

Finally, launch protoc and tell it to produce Lua output:

$ protoc -I/path/to/your/proto/files --lua_out=/output/path file1.proto file2.proto

You simply need to add --lua_out to the arguments to protoc to get it to produce the Lua output files.

Under the hood, protoc is looking for the program protoc-gen-lua somewhere in your $PATH. You can modify $PATH in lieux of installing the package, if you desire.

Missing plugin_pb2 Python Module

The protocol buffers Python installer does not install a file required by protoc-gen-lua at this time. The missing file is the Python interface to the compiler plugin plugin.proto. The protoc-gen-lua Python script may fail when importing the google.protobuf.compiler.plugin_pb2 module.

A thread on the protocol buffers mailing list discusses the issue.

At this time, the issue can be worked around by manually installing the missing file.

Assuming you have a working protoc compiler on your system and have the existing Python protocol buffers package installed, from the protocol buffers source code directory, run the following:

$ protoc -Isrc --python_out=/path/to/output/directory src/google/protobuf/compiler/plugin.proto

The command should produce no output if successful. Additionally, the file /path/to/output/directory/google/protobuf/compiler/plugin_pb2.py should have been created.

Next, find the location of the installed protocol buffer Python package. If you have locate, try finding it via locate descriptor_pb2.py. A common location is something like /usr/lib/python2.6/site-packages/protobuf-2.3.0-py2.6.egg/google/protobuf/. Navigate to this directory and:

$ mkdir compiler
$ touch compiler/__init__.py
$ cp /path/to/plugin_pb2.py compiler/plugin_pb2.py

In common English:

  1. Create a new directory, from the install root, google/protobuf/compiler
  2. Create an empty file, __init__.py in this directory. This tells Python that the directory contains Python modules.
  3. Copy the plugin_pb2.py file produced by protoc to this new directory.

Depending on the installed location of protocol buffers, these actions may require superuser or administrator privileges.

Compiling Produced Files

You should be able to compile the produced .h and .cc files like you would for protocol buffer output files. If you have an existing Makefile, project, etc, just add the produced .h and .cc files to it.

For linking, you'll need to include whatever library contains Lua. On *NIX toolchains, this typically corresponds to the linker flag -llua or -llua5.1.

The produced C++ code contains extern "C" { } blocks around all code that utilizes Lua API function calls to avoid C++ name mangling.

Windows

Windows requires an identifier for symbols to be exported from shared libraries. If compiling the lua-protobuf output to a shared library, you'll need to use a preprocessor define:

#define LUA_PROTOBUF_EXPORT __declspec(dllexport)

Release files for lua-protobuf 2.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lua-protobuf 2.0.3
File Size Uploaded
lua_protobuf-2.0.3.tar.gz 15.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lua-protobuf 2.0.3
File Interpreter ABI Platform
lua_protobuf-2.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 31.9 kB

Release files / lua_protobuf-2.0.3.tar.gz

Download URL lua_protobuf-2.0.3.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ce52cdef7ffc2434591885e9a38873a3bd47abe1f4bcb5dabf8f6e18e3f803f0
BLAKE2b-256 checksum
How to use checksums
44a572082eb2d60796adbf691c56994785ae349dfeae682f9be22660507eb51a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.4 Windows/10

Release files / lua_protobuf-2.0.3-py3-none-any.whl

Download URL lua_protobuf-2.0.3-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4af27e78f2f3ae1e864473d4ed86bf890ad0d19ca99a74f64d12b1f7e66b645f
BLAKE2b-256 checksum
How to use checksums
bda8feb5bb42551c61087ae737edd54ebc1cd529248bcc7ad42adecb8e7ca104
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.4 Windows/10

Release history Release notifications | RSS feed

This release

2.0.3 This release

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page