lua-users home
lua-l archive

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

It was thus said that the Great Ico once stated:
> 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 ="file")
>   if errno == io.EACCESS then
>      ...
>   end
> Any thoughts on this?

  Instead of waiting for official blessing from Team Lua, I went ahead and
defined my own module [1] to handle errno values.  A sample usage:

	errno = require "org.conman.errno"

	-- some code
	if err == errno.EINVAL then
	  io.stderr:write("code returned ",errno[err])

  Since I use it on both Linux and Solaris, I have conditionally included as
many error codes as I could find on both systems.  Also, the use of the
org.conman.errno.strerror() function is not something I would use (I would
have removed it but I have plenty of code that requires it---the use of the
__index method is a relatively new development).  

  -spc (would like to see EXIT_SUCCESS and EXIT_FAILURE in the os module