[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: creating inheritance with the lua API
- From: Sean Conner <sean@...>
- Date: Sun, 3 Aug 2014 19:23:14 -0400
It was thus said that the Great Littlefield, Tyler once stated:
>
> Hello:
> I've followed the lua OO tutorials and have kind of gotten it working. My
> issues seem to come in when trying to translate this to c, however. I'm not
> sure why it's such a hard problem for me. I'm mainly looking for examples
> of how to do this in c-side API, as there are tons of lua OO ideas floating
> around out there.
Why do you need to do it with the C API?
At work, I had implemented a Lua wrapper for one of our proprietary protocols
using the C API. A recent extention (backwards comptable as both servers
and clients are set to ignore anything they don't understand) to the
protocol was added. On a lark, I decided to change gears and write as much
of the protocol handler in Lua [1].
The C API weighed in at 2,800 lines of C code (including comments and
blank lines---it's a rough count). The new almost-exclusively Lua API
weights in at 828 lines (again, comments, blank lines, etc.). Of that, 642
are in Lua and 186 in C (some data conversion routines [2] that are just
plain easier to do in C).
-spc
[1] The rewrite also makes it easier to test old clients/servers vs. new
clients/servers.
[2] Although the new Lua 5.3 string.dumpint() and string.undumpint()
routines would cut that C code right down.