[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: use of gettop to change functionality
- From: Axel Kittenberger <axkibe@...>
- Date: Tue, 1 Mar 2011 15:36:03 +0100
> 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
func(var)
else
func()
end.