lua-users home
lua-l archive

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


True, and I actually do tend to worry about such things in my code. There
are two alternatives.

One is, as was suggested, to use the light userdata as an index to look up
the table. That keeps the existing semantics but doesn't deal with the
inheritance case where you want to tag a metatable as supporting multiple
classes.

The second is to protect the metatable.

Mark

on 8/27/04 5:34 AM, Roberto Ierusalimschy at roberto@inf.puc-rio.br wrote:

>>       if( !lua_getmetatable( L, index ) )
>>           return NULL;
>>       lua_pushlightuserdata( L, udkey );      /* ( ... mt udkey )
>>       lua_rawget( L, -2 );                    /* ( ... mt mt[ udkey ] )
> 
> This technique is not safe. A Lua program may get udkey (traversing the
> metatable of a userdata) and then add it as a key in the metatable of a
> userdata from a different kind, fooling checkudata.
> 
> -- Roberto