lua-users home
lua-l archive

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


> In the meantime, you can try using strings to define the functions to 
> be passed. 

For what it's worth, I've been using a function something like this
for a while:

    function lambda(body)
        return dostring(
            "function _" .. body .. "; return _"
        )
    end

You can add whatever checks for errors you feel are appropriate. The
example being discussed would become:

    myCollection:do(
        lambda("(a) if a > 24 then a = a + 1 end end")
    )

The advantages are that myCollection:do doesn't have to know whether
it is being passed a named or anonymous function and it will be easy
to convert to real anonymous functions in 3.1. The disadvantage is
that errors can be a little tricky to locate.

Alan