lua-users home
lua-l archive

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

Hi David

On 23 February 2016 at 21:11, David Given <> 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 ="somefile")
>     if e and not e:find("No such file or directory") then
>         dosomething()
>     end

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 ="/this/file/is/guaranteed/missing")
>     if e != filenotfound then
>         dosomething()
>     end
> ...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?

`` returns `errno` as its 3rd return value

    local fp, err, errno ="somefile")
    if not fp then
       print(err, "ERRNO:", errno)

You don't mention the version of Lua you're using, so here are the
relevant sources:


Hope that helps