Lua Protocol Buffers

Since I've been posting about Protocol Buffers lately, I thought I'd post a quick note about a small project of mine over on Google Code.

lua-pb-reflect provides access to protocol buffers in the Lua scripting language without having to generate Lua specific protocol buffer code.  If you're already embedding Lua in your games, it's probably the simplest binding out there. It has no C++ dependencies other than Lua and Google's standard protocol buffer library.

If you use Google's protoc.exe to generate the normal C++ protocol buffer code, you just need to register the generated C++ classes with lua-pb-reflect. From that point on, Lua can see the protocol buffer definitions and act on them more-or-less just as you'd expect.

This message definition:
message Person {
  required int32 id = 1;
  required string name = 2;
  optional string email = 3;
}
is accessible in Lua as:
local person= QPB.new('Person')
person:set_id(123)
person:set_name("Bob");
person:set_email("bob@example.com");
Big note: Serialization is not currently supported from the lua side, but you could write your own C++ function to do so, and expose that function to lua if you wanted. If you find the lib cool, and want this feature, just let me know, and I can see what I can do.

Compiling from source is the only current supported method of using it.


2 comments:

DLed said...

very nice! A handy tool, indeed. If I ever need it, I'll use it.

Chan-Ho Song said...

very good. thank you.