Registry and references

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

Registry and references

Thomas Lauer-3
Quoted from section "3.5 - Registry" of you-know-what:-)

"Any C library can store data into this table, but it should take care
to choose keys different from those used by other libraries, to avoid
collisions. Typically, you should use as key a string containing your
library name or a light userdata with the address of a C object in your
code. 

The integer keys in the registry are used by the reference mechanism,
implemented by the auxiliary library, and therefore should not be used
for other purposes."

<mood current="nitpicking">
I wonder and ask myself whether the address of a C object isn't, in the
end, exactly that: an integer key?!

The use of the registry for the reference system seems to rely on two
premises: 1. that not many references are used simultaneously in an
application and 2. that any address coming from C is above a certain,
not clearly defined numerical threshold (which may well be true for most
(perhaps all?) architectures supported by Lua).

Still, these two statements somehow irritate me. But perhaps I'm
completely lost in the woods as to how these things hang together...?
</mood>

-- 
cheers  thomasl

web : http://thomaslauer.com/start


Reply | Threaded
Open this post in threaded view
|

Re: Registry and references

Tony Finch
On Mon, 25 Jun 2007, Thomas Lauer wrote:

> I wonder and ask myself whether the address of a C object isn't, in the
> end, exactly that: an integer key?!

The idea is you would use a lightuserdata not a number to hold the
address.

Tony.
-- 
f.a.n.finch  <[hidden email]>  http://dotat.at/
SOUTHEAST ICELAND: VARIABLE 3 OR 4 BECOMING CYCLONIC 5 TO 7. SLIGHT OR
MODERATE. OCCASIONAL RAIN. MODERATE OR GOOD.

Reply | Threaded
Open this post in threaded view
|

Re: Registry and references

Romulo Bahiense
In reply to this post by Thomas Lauer-3
I wonder and ask myself whether the address of a C object isn't, in the
end, exactly that: an integer key?!

Yes, a pointer is a integer value, in C. In Lua, numbers and lightuserdata are different things. A number is (usually) a double floating point value, while a lightuserdata is an opaque pointer. The struct describing both have different tags (LUA_TNUMBER / LUA_TLIGHTUSERDATA).

In the same sense, an string containing four bytes could be an (32bit) integer as well.

In other words: there will be no collision between a numeric key and a lightuserdata key.


--rb