lua-users home
lua-l archive

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


What's needed is a pack/unpack pair that does the right counting.

(The following is untested.)

    function npack( ... )
        local result = { ... }
        result.n = select( '#', ... )
        return result
    end

    local nunpack( t )
        return unpack( t, 1, t.n )
    end

If you do this a lot, you probably want to create C versions because you can
decrease the number of times the parameter list is copied.

All that being said, it's too bad that xpcall doesn't take its parameters
as:

    xpcall( handler, fn, ... )

That would have resolved this problem without the need to pack up the
arguments though the code still wouldn't be pretty.

Mark