lua-users home
lua-l archive

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


When using Lua for more or less data description tasks, I'm frequently
finding myself wishing for a splice operator that would allow one to use all
of the results of a function when building a table. My particular example
comes up when building view descriptions. For example, the following works
in that makeChildren can return all of the items that it wants to:

    column{
        spacing = 10,
        makeChildren()
    }

But the following does not work:

    column{
        spacing = 10,
        makeChildren(),
        view{
            title = "footer",
        }
    }

Now I only get the first child. Coding around this requires using temporary
variables:

    local t = makeChildren()
    t.spacing = 10
    t[ #t + 1 ] = view{ title = "footer" }
    column( t )

That approach doesn't work well when nested down within the description
because I have to move the work with t out of the structural description
which then makes the construction process harder to follow.

I'm thinking that something along the following lines would be useful:

    column{
        spacing = 10,
        $makeChildren(),
        view{
            title = "footer",
        }
    }

Where the $ means that we take all of the results from the function rather
than just the first. (And if it has no results, we also reflect that.) I
would also be quite open to other syntaxes.

Mark