lua-users home
lua-l archive

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


I'm trying to do portable error handling on the os.xxx() and io.xxx() functions
that depend on operating system calls. This is tricky because the descriptive
string returned as the second return value by the io.() functions contains
prose from the local C library, which is OS dependend and might be localized,
defying any attempts to do string matching.

Today I noticed that these functions also return errno as third return value.
This seems to be mentioned in PIL, but is omitted in the reference manual. Is
this officialy part of the Lua API, and is it safe to depend on this behaviour?

This still leaves the problem of handling the actual errno values. ANSI C does
not define any of the real world cases like ENOENT or EACCESS, although the
POSIX errno list is pretty much standard on a lot of platforms supporting the
ANSI C stream functions. It is trivial to add a list of constants to any
program, but it might be handy if the io library offers constants available on
the current platform (since there's already LUA_USE_POSIX). 

I'd love to be able to write something poratble like

  local fd, _, errno = io.open("file")
  if errno == io.EACCESS then
     ...
  end
  
Any thoughts on this?


-- 
:wq
^X^Cy^K^X^C^C^C^C