[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 11:10:05 -0300
> > On Wed, Jun 22, 2011 at 3:20 PM, Mike Pall <mikelu-1106@mike.de> wrote:
> > > not, if it's allocated externally. You cannot add an element or
> > > increase the struct size without breaking the ABI.
> >
> > To be fair, Lua does not make guarantees about the ABI with new versions.
> >
> > But it is true that an API function would isolate the programmer from
> > the actual mechanism; LuaJIT could provide it as well without having
> > to expose internal details.
>
> The advantage of exporting the structure is that the user may add her
> own extra fields, if needed. (Are there real cases for this need?)
There seems to be another problem with the function approach (assuming
an opaque structure). A subtle detail when creating files in Lua is
that the creation of the userdata may fail (memory error). So, if the
user opens a file and then calls this new function, Lua may raise an
error and the open file is lost forever. The natural order is to first
create the userdata and then open the file. (Once the file is stored in
the userdata, the garbage collector will ensure it will be eventually
closed.) With an opaque structure, that would demand two functions
(one to create the userdata and another to store the FILE*).
-- Roberto