[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: cons cells for Lua
- From: "Jay Carlson" <nop@...>
- Date: Thu, 25 Mar 2004 17:27:37 -0500
"Mark Hamburg" <email@example.com> writes:
> on 3/25/04 8:45 AM, Jay Carlson at firstname.lastname@example.org wrote:
> > The reason to use  and  is they take advantage of the "small
> > keys are stored in an array" optimization in Lua 5.0. For clarity you
> > use .car and .cdr instead. Note that all strings in Lua are interned,
> > the performance penalty is not that great.
> Do you want to use 0 and 1 or 1 and 2?
Argh, yes. Use 1 and 2. I misread the C code.
> > On the other hand, it might be a fun exercise to implement this as a C
> > extension. The car would be stored as a ref, which is something the
> > reference manual doesn't emphasize enough. (Somebody might wanna write
> > tutorial for the wiki on references). If you allow improper lists,
> > have to store the cdr as a ref as well.
> Beware of what amount to reference-counting cycles when creating refs.
> actually a bit of a pain to get userdata to refer safely to other Lua data
> objects and seems to require the use of per-object metatables rather than
> sharing the metatables across a type.
The whole discussion of this made my brain hurt, so I filed it away under
"reread this thread when I'm on a trans-pacific plane" :-)
But refs are important for many bindings, especially when dealing with
callbacks specific to particular C-library objects. From the reference
manual alone, it is unclear how to bind such things at all, unless you read