[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Finding the mode of an open file
- From: Dirk Laurie <dirk.laurie@...>
- Date: Tue, 4 Sep 2018 12:21:59 +0200
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 :-)