lua-users home
lua-l archive

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

I must note that the first approach should work faster with the first
usecase, since there's no table constructor there. In similar situation I
used different style: you can't access children through C interface, but you
can store references to them as separate Lua fields in the object. Something
like this:

-- creates button and adds it to the dialog's children list
function dialogbase:button()
    local btn = ui.createbutton()

mydialog = ui.createdialog()
mydialog.ok = mydialog:button()
mydialog.cancel = mydialog:button()

Best Regards,

----- Original Message ----- 
From: "David Given" <>
To: <>
Sent: Friday, October 29, 2004 3:47 PM
Subject: GUI interface style query

> In-house, we're using Lua as a RAD scripting engine for our embedded GUI.
> I must say, it's working pretty nicely.
> So I'm writing a set of Lua wrappers around our OO-based hierarchical
> object model. The basic primitives are: getchildren, getparent, add and
> 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.
> 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
> This means these two lines become:
>  child1, child2, child3 = unpack(object:getchildren())
> and:
>  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
> +- --+