Re: How shall a Lua file handle be known?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: How shall a Lua file handle be known?

Michael Truog
Has anything changed where it is now possible to create
io.fdopen() or something similar in a separate library?

If so, is there now a library that has an implementation?
(it still seems like luaposix does not have fdopen())

Thanks,
Michael

On 05/11/2011 23:16, Reuben Thomas <[hidden email]> wrote:

> On 11 May 2011 23:07, Mike Pall <[hidden email]> wrote:
>>
>> I'd rather add io.fdopen() and fp:fileno(), because these are
>> useful for the FFI, too. Ok, so you'll need to fetch io.fdopen
>> once at the start and put it into an upvalue. Not sure if you're
>> happy with that.
>
> I'd be delighted, but for a library I would prefer it be standard [and
> documented!]. Team?
>
> I will remove pipe, fdopen and dup from luaposix until there's a
> proper way to implement them. Is there any need for LuaJIT to
> implement fileno? The current luaposix implementation is:
>
> static int Pfileno(lua_State *L) /** fileno(filehandle) */
> {
> FILE *f = *(FILE**) luaL_checkudata(L, 1, LUA_FILEHANDLE);
> return pushresult(L, fileno(f), NULL);
> }
>
> which works fine in LuaJIT 2.0.0-beta7:
>
> LuaJIT 2.0.0-beta7 -- Copyright (C) 2005-2011 Mike Pall. http://luajit.org/
> JIT: ON CMOV SSE2 SSE3 fold cse dce fwd dse narrow loop abc fuse
>> require "posix"
>> print (posix.fileno(io.stderr))
> 2
>
> --
> http://rrt.sc3d.org


Reply | Threaded
Open this post in threaded view
|

Re: How shall a Lua file handle be known?

Reuben Thomas-5
On 13 May 2012 08:40, Michael Truog <[hidden email]> wrote:
> Has anything changed where it is now possible to create
> io.fdopen() or something similar in a separate library?
>
> If so, is there now a library that has an implementation?
> (it still seems like luaposix does not have fdopen())

I can only confirm that there's still no fdopen in luaposix; I've not
looked at recent LuaJIT (or indeed Lua 5.2) to see if things have
changed there.

--
http://rrt.sc3d.org

Reply | Threaded
Open this post in threaded view
|

Re: How shall a Lua file handle be known?

Roberto Ierusalimschy
In reply to this post by Michael Truog
> Has anything changed where it is now possible to create
> io.fdopen() or something similar in a separate library?

Yes; see  http://www.lua.org/source/5.2/lauxlib.h.html#luaL_Stream

-- Roberto