lua-users home
lua-l archive

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


I can't work out how to diagnose whether an open file was opened
read-only, write-only or read-write. Not even from the API.

Apparently this is hard even from C, and the solution is
system-dependent, so it is ten times as hard to do it in a portable
way.

There is an easy fix, which one could implement as a pure-Lua module
that monkey-patches the io library.

1. Replace io.open(filename, mode) by a function that also does
debug.setuservalue(file,mode).
2. Add file.mode(file), which returns debug.getuservalue(file).

Since monkey-patching a system library is frowned upon by many, this
amounts to a feature request :-)