lua-users home
lua-l archive

Re: sunday afternoon whishlist

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


On Wed, 2010年06月02日 at 09:22 -0700, 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:
> 
> function argchecked(f, numargs)
> return function(...)
> if select('#',...)==numargs then f(...)
> else error(string.format(
> "%i arguments expected, got %i",
> numargs,select('#',...))) end
> end
> end
> 
Great function, I like it... Just to be complete - it should include a
'return', i.e.:
function argchecked(f, numargs)
 return function(...)
 if select('#',...)==numargs then return f(...)
 else error(string.format(
 "%i arguments expected, got %i",
 numargs,select('#',...))) end
 end
 end

AltStyle によって変換されたページ (->オリジナル) /