lua-users home
lua-l archive

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


Flash of possible insight as a replacement for my previous comment about
Ruby and scoping...

Is there some way to extend the table construction syntax so that one could
write function calls within the table constructor which would receive the
table as a parameter?

    doWithTable{

        field1 = "foo",

        addLotsOfFields( $, 1, 2, 3 ),
        addMoreFields( $, "a", "b" )

    }

This depends on a couple of things:

* Functions with no results don't advance the index in the table. That's a
change from the current Lua standard. Ideally, this would be combined with
support for multiple value return in positions other than the last position
in the table.

* The $ represents the table currently under construction. This also means
that one can write:

    t = {
        recursive = $
    }

This is sort of syntactic sugar for running the functions outside the
constructor and before passing the values off as parameters, but it also
allows the functions to add values to the table via returned values as they
can right now and it simplifies the code when passing the table as a
parameter.

Mark