2014-02-02 Herbert Voss <[email protected]>:
> Am 02.02.2014 20:38, schrieb Philipp Gesang:
>>> out.close()
>> out:close()
...
> Oh no, what a shame!!! I was puzzeled 20 minutes with this problem,
> looked 10 times over the code and didn't realize the dot ...
This is one of the most common mistakes I make too.
There are two palliatives (I can't call them cures).
First:
Make it a habit to put whitespace after every `:`. It is a good habit anyway,
and the error is more visible.
Second:
~~~
require "paranoid"
~~~
where `paranoid.lua` is the attached file.
-- paranoid.lua
-- Checks that file routines are in fact called with file arguments and
-- prints a helpful message that will appear just before the error message.
local iotype, stderr = io.type, io.stderr
local file=iotype(stderr)
local M=getmetatable(stderr)
for k,v in pairs(M) do if type(k)=='string' and not k:match"^_" then
local meth=v
M[k] = function(...)
if iotype(...)~=file then stderr:write(
("Did you code file.%s instead of file:%s?\n"):
format(k,k))
end
return meth(...)
end
end end