lua-users home
lua-l archive

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



On 22/03/2005, at 6:02 PM, Wim Couwenberg wrote:

1). Whether there is any problem using user data objects in a table like this (if there is then I guess I need the spooled file list user data object of option a),

No problem at all. As long as the lifetime of your userdata (i.e. its __gc behaviour) is correct, go right ahead! I'd prefer this over a C/C++ implementation any day.


Good, didn't imagine there'd be a problem here.

2). For option b), whether I have to instantiate and manage the Lua table internally in the package library to allow the OO-style access above (SpooledFileList:getfile, etc.) or whether I could use a basic Lua table from within Lua and tack on the SpooledFileList methods to that Lua-based table? (My feeling is I don't imagine I could do this in a clean encapsulated way using just a Lua table from within Lua really, it needs to be managed in the package...)

My "style" in packaging C/C++ libs is to keep *as much* of the binding in Lua itself. It is far easier to set-up and tweak a bunch of Lua scripts than their C/C++ alternatives and just as powerful. I usually put the C/C++ part as a "private" (light) userdata member in a Lua object (i.e. a table). Then you can use plain Lua tables, metatables, functions etc. to decorate your Lua object system. Moreover, the (now considered private) userdata methods can be very low-level (just export some existing API calls more or less 1-on-1) and make them scripting friendly in the Lua object wrapper.

Yes, I get your point here. Whatever I was thinking of implementing in C table-wise, OO-wise, can be done just as easily in Lua. So keep as much as possible in the Lua scripts for ease of use. I guess coming from the C/C++ side I was tending to think I needed to keep some things on that side for overall consistency once I'd created/exposed the SpooledFIle userdata objects from C. As it is it's really just the SpooledFile userdata obects themselves that need be provided from C.


Regards,
Peter Colson.