[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C API question
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 7 Jan 2011 14:07:00 -0200
> > That is a good question. Since userdata got "environments" in 5.1
> > (called uservalues, in 5.2), the need for luaL_ref diminished a lot.
> >
> > -- Roberto
> >
> Not so much that it is going to be removed I hope, how else would C code
> keep a reference to Lua data without generating its own id mechanism?
For a fixed number of references there are several ways (e.g., unique
strings or addresses of C static variables). For dynamic creation of new
references there are several ways, too. One is to use a lightuserdata
as a key, as Mark suggested. (If the refered object is a userdata, its
address is a perfect key.) Another is to use your own table inside
the registry to keep only your references. (This table may be weak,
solving the GC problem.)
-- Roberto