lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Wouldn't a better solution have been to generate the same 
> userdata for each id? Or alternatively, use a number or 
> lightuserdata instead of a character string?

On the C side the ids are not strings.  They are more of a GUID, but
they are larger than a pointer so can't be easily converted to a
lightuserdata or a number.

Also, the bookkeeping overhead required for keeping track of the
userdatas that were generated (so I could always return the same
userdata) was something I wanted to avoid.

> Lua garbage collects strings.

Forgive me, but why when a string is used as a key for a weak-keyed
table is it not GC'd?

s = "s"
t = setmetatable( {}, { __mode="k"} )
t[s] = {}
=t[s]
table: 0112A6D8
s = nil
collectgarbage()
=t["s"]
table: 0112A6D8

-Kevin