lua-users home
lua-l archive

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


On Jun 2, 2010, at 6:22 PM, Stuart P. Bentley wrote:

> If you find you're having a lot of trouble with functions taking the wrong number of parameters, consider using this:

Hmmm... perhaps this is just a lack of imagination on my side, but... how would superfluous parameters ever matter? After all, what you don't know cannot hurt you. As far as missing argument, a simple assert would suffice, no?

local function Fussy( parameter )
    assert( parameter, 'missing parameter' )
end

local function Fastidious( parameter, ... )
    assert( parameter, 'missing parameter' )
    assert( ( function( ... ) return select( '#', ... ) == 0 end )( ... ), 'superfluous parameters' )
end