[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: My program doesn't speak Portugese!
- From: Luke Drummond <luke@...>
- Date: Tue, 23 Feb 2016 21:33:41 +0000
On 23 February 2016 at 21:11, David Given <email@example.com> wrote:
> I've just had a report that WordGrinder is failing on a system with a
> Portugese locale. This turns out to be because it's got localised errno
> strings. So, my code, which does this:
> local fp, e = io.open("somefile")
> if e and not e:find("No such file or directory") then
This is fragile and is going to bite you sooner or later; you're right
to want something more robust.
> ...gets confused, because the actual string in e is "Arquivo ou
> diretório não encontrado".
> I *could* do something really evil:
> local _, filenotfound = io.open("/this/file/is/guaranteed/missing")
> if e != filenotfound then
> ...but I can't really guarantee that the path doesn't exist.
> What I'd really prefer is an errno (and a set of errno constants). But
> Lua doesn't expose those. Any suggestions?
`io.open` returns `errno` as its 3rd return value
local fp, err, errno = io.open("somefile")
if not fp then
print(err, "ERRNO:", errno)
You don't mention the version of Lua you're using, so here are the
Hope that helps