lua-users home
lua-l archive

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


On Jan 10, 2011, at 12:15 PM, Patrick Donnelly wrote:

> On Mon, Jan 10, 2011 at 11:30 AM, Doug Currie <doug.currie@gmail.com> wrote:
>> On Jan 10, 2011, at 7:14 AM, Daniel Silverstone wrote:
>> 
>>> I suggested that in a conversation a few of us were having recently (not on
>>> list or IRC) and it was pointed out to me that pushing and then looking up a
>>> light userdata in a table, may be more expensive than a rawgeti invocation.
>> 
>> One way to avoid Lua refs, and avoid using the global registry, is to associate callbacks (and other Lua objects needed by C) with small integer keys in a related full userdata environment (known as a uservalue in 5.2). However, when a callback from C happens, there is no documented way to convert a userdata pointer (void *), AKA block address, to a Lua object. I.e., what is the inverse of lua_touserdata?
> 
> Well, the inverse operation is not documented probably because it's
> easy to do yourself. Just have a light userdata pointing to the full
> userdata block address (lua_touserdata) as keys in the registry with
> the corresponding full userdata value.

Well, sure, but the whole point was to (a) avoid the registry, and (b) reduce the execution overhead. It is a simple pointer offset to convert from the userdata block address to the userdata object. A supported lua_pushuserdata (or something like that) would save lots complexity compared with using the registry, and avoid use of ad hoc undocumented mechanisms.

e