lua-users home
lua-l archive

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


Chris Marrin wrote:
>
> Edgar Toernig wrote:
> > 
> > errno is pointless.  Unlike C, Lua has multiple return values.
> > And I would suggest to use strings like "ENOTEMPTY" instead of
> > errno numbers.  The numbers are totally useless.
> 
> It's no more pointless than in C,

errno in C is and has always been a work-around for missing
multiple return values.  It's usage is extremly fragile - just
look at lposix.c where every single use of it is broken. [Uhh, see PS]

> If errno is a value for which I don't have a symbolic constant, I would 
> return nil for the string and still return the number. That gives us 
> fully general functionality.

I would suggest to never use numbers - always return short strings
like "EPERM" or, for unknown errors, "E42".  A function that usually
returns a string and only sporadically a number is error prone.
The same for the full text message: "unknown error E42".

Ciao, ET.

PS: Oh, I just noticed, lua-5.1-rc has the same problems with
    errno: between the syscall setting errno and the usage of
    errno there are several function calls that may destroy
    its value (i.e. lua_push* may call lockmutex, malloc,
    generate fp-errors, etc).  And ferror doesn't set errno
    at all.