[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.2.0 (beta-rc2) now available
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 22 Jun 2011 09:57:23 -0300
> On Wed, Jun 22, 2011 at 12:21 AM, Luiz Henrique de Figueiredo
> <lhf@tecgraf.puc-rio.br> wrote:
> > All feedback welcome. Thanks.
>
> Just an observation about the folly of depending on undocumented internals.
>
> Previously people could hijack the existing file objects by packing
> their own FILE* in the LUA_FILEHANDLE userdata, which was just FILE**.
> Now that userdata looks like this:
>
> typedef struct LStream {
> FILE *f; /* stream */
> lua_CFunction closef; /* to close stream (NULL for closed streams) */
> } LStream;
>
> (LuaJIT uses something similar)
>
> I mention this because I think there's a need for a standard way for
> extensions to create Lua file objects, or even on level of a
> 'io.fdopen' function that would create a file object from an existing
> file-like handle. One particular use case would be a Windows
> extension wishing to provide a UTF-8 aware io.open, or to redefine
> io.popen so it does not depend on the particular broken implementation
> of the Windows CRT.
The idea of this change is to allow that. Probably LStream should be
exported with a small documentation about how to use it; more or
less something like this:
- create a userdata with a structure that is an "extension" of LStream.
- set its metatable to "FILE*" (luaL_setmetatable)
- set field 'f'
- set field 'closef'
-- Roberto