lua-users home
lua-l archive

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


Hello:
On 8/3/2014 7:23 PM, Sean Conner wrote:
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?

If there are other solutions, I'd appreciate them; My solution was more out of what made sense for me than the "right" way to do anything. I have game objects (player, Entity, etc) that need to be wrapped so that they can be accessed through scripting. Rather than providing functional bindings (entity.GetName, entity.setName) etc, I decided to just wrap up individual classes. This gives me more flexability: I don't have to add all of the GetName and SetName to other objects that might inherit Entity, for example. My goal was to figure out exactly how to do this OO-like in C, then write Lua scripts to generate all of the code for me.

 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.



--
Take care,
Ty
http://tds-solutions.net
He that will not reason is a bigot; he that cannot reason is a fool; he that dares not reason is a slave.