lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


David Manura <dm.lua <at> math2.org> writes:

> 
> On Mon, Aug 10, 2009 at 4:16 PM, Joshua Haberman wrote:
> > The idea is this: you define your structure type as a protocol buffer
> > type. .... you could write this in a .lua file:
> >
> > Alice = upb.new_type("
> >  message Alice {
> >    optional int32 x = 1;
> >    optional int32 y = 2;
> >  }
> > ")
> >...
> > - instances of Alice have a more efficient representation in memory.
> >  Since the set of all possible fields is known, it can be stored
> >  as an array with known offsets for each member instead of as a
> >  table keyed by "x" and "y".
> 
> That's interesting.  A similar type of thing might be done using one
> of the struct libs [1].
> 
> > my library is currently ~2300 sloc of C, and compiles to <30kb of object
> > code on x86.  You can check it out here (the Lua parts aren't written
> > yet):
> 
> I had tried protocol buffers before, but it seemed somewhat bulky for
> what it did (added 1 MB to the binary I think).

I had the same feeling, which is one reason I started writing upb (the "u"
is for "micro").

> It looks like they
> may now have a new "lite" version [2] that much improves this.

The lite version improves this by stripping out all of the reflection
features and the code that lets you load .proto types at runtime.  What
this means is that you have to generate and link in a C++ class for each
different .proto type you want to handle.  For Lua, you'd have to compile
and link a separate extension for each message type.  For an interpreted
language like Lua where you don't want to have a compile step, this is really
inconvenient.

upb (my project) compiles to 30kb which *includes* code to load .proto
types at runtime.  I designed it specifically to be ideal for exposing
protobufs to languages like Lua.

Josh