lua-users home
lua-l archive

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

> And this is in fact useful.
> Consider the library function io.lines(); called without any
> arguments, it iterates over standard input. Pass it a file name, it
> iterates over that file if it can.
> It would _not_ be nice if io.lines(nil) would open stdin, since an
> accidental nil variable is all too common. Instead, it gives you an
> error, as it should.

This is questionable, if there is some code before that determines
over what the io.lines should iterate, it might want to set it to
"nil", a.k.a "nothing" to have io.lines behave as it would have been
called with nothing. Given in this case it could set it to io.stdin (i
believe) but one could construct other places, where a simple function
call that sets nil values for values it does not want to provide,
changes to an if condition to call the function with differing number
of arguments.

local var
...some code that sets var or not...

if var ~= nil then