[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How shall a Lua file handle be known?
- From: Sam Roberts <vieuxtech@...>
- Date: Wed, 11 May 2011 13:26:53 -0700
On Wed, May 11, 2011 at 12:56 PM, Reuben Thomas <email@example.com> wrote:
> I am unclear from the Lua reference manual whether I ought to expect
> this technique to work or not, that is:
I've done this before. I've also directly accessed the FILE* stored in
a filehandle opened
by io.open() (so I could make termios calls on it). I considered it a
bit fragile, but
lua is meant to be extended, and its implementation is stable, so it works fine.
It doesn't surprise me that it doesn't work with LuaJIT.
It would be handy if lua should have a pair of functions:
void luaL_newfile(lua_State* L, FILE* f, int closeongc)
FILE* luaL_tofile(lua_State* L, int index);
These are close to existing, in terms of liolib.c's newfile(),
io_noclose(), and tofile() functions, too bad those are static to the
LuaJIT implements lua's C helper API, so you'd have portable way of doing this.
Or maybe you can convince Mike to make your implementation below work!
> luaL_getmetatable(L, LUA_FILEHANDLE); /* LUA_FILEHANDLE is exported
> but undocumented */
> lua_setmetatable(L, n); /* ??? Should this work ??? */
> In LuaJIT, io.type will not return true unless the userdata's private
> udtype field is UDTYPE_IO_FILE, and the only way to get that setting
> is to use a normal Lua io library call which returns a handle