lua-users home
lua-l archive

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

In-house, we're using Lua as a RAD scripting engine for our embedded GUI. And, 
I must say, it's working pretty nicely.

So I'm writing a set of Lua wrappers around our OO-based hierarchical visible 
object model. The basic primitives are: getchildren, getparent, add and sub.

getparent, add and sub are pretty simple; getchildren, however, gets a list of 
a particular object's children. What's the best way of returning this?

Currently what it does is to return a tuple of all the object's children. This 
means that if you know how many children there are, you can do this:

 child1, child2, child3 = object:getchildren()

OTOH, if you don't, you have to do this:

 childarray = {object:getchildren()}

...which is a bit ugly.

The other approach is to have the C code construct an array and return that. 
This means these two lines become:

 child1, child2, child3 = unpack(object:getchildren())


 childarray = object:getchildren()

*shrug* Both approaches are equally valid. Does anyone have any particular 
comments, advice, related war stories?

+- David Given --McQ-+ "Under communism, man exploits man. Under
|    | capitalism, it's just the opposite." --- John
| ( | Kenneth Galbrith
+- --+