lua-users home
lua-l archive

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


Usually it has to do with named arguments processing and catching user errors, like so:

local function foo(...)
   local named_args = ...
   if not next(named_args) then
        print "no arguments, did you forget something?"
     else
         for k,v in pairs(named_args) do
            print(k,v)
        end
     end
end

foo{ oeu='bob', bycoej='cfy'}
foo{}

this would be much cleaner like so:

local function bar(...)
     for k,v in pairs(...) do
        print(k,v)
    else
        print "no arguments, did you forget something?"
    end
end




Le mer. 16 mars 2022 à 15:01, Flyer31 Test <flyer31@googlemail.com> a écrit :
Interesting. Can you say a bit more of the typical possible
applications, just for me as "also Lua newbee" to judge, whether this
REALLY happens often or not?

(I until now never was in such a situation... Usually if I do for
loop, I am always quite sure that something in my container... and if
nothing inside, then I would just be happy that "nothing happens" - so
this standard working principle of Lua has been perfectly nice for me
here ... so far...).

On Wed, Mar 16, 2022 at 9:36 AM Benoit Germain <bnt.germain@gmail.com> wrote:


--
Benoit.