lua-users home
lua-l archive

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


Hi,

Chris Marrin wrote:
> But there is not an equivalent 
> lua_rawsetfield(). Is there something I have overlooked, or is this just 
> an oversight? The same is true for lua_getfield().

It was probably not deemed necessary. But I would use it, too.
In fact I've found a compelling point why this should be added:

A lot of the library functions have been converted over to use
lua_getfield(), loosing their 'raw' behaviour. This isn't much of
a problem for most functions: it's only slightly slower and
adding metamethods to the registry isn't a good idea anyway.

But there is one bad exception: getmetatable() internally calls
luaL_getmetafield() to check the existence of the __metatable
field. Unfortunately luaL_getmetafield() is now using
lua_getfield(), i.e. it might call the __index metamethod of the
metatable itself.

This can be used to trick sandboxing wrappers that use
getmetatable() on user-defined objects in calling a sandboxed
function in an unprotected context.

I have one instance of this in LuaJIT's optimizer: it simulates a
table lookup to get inlining hints by going through the metatable
chain. Of course it must not ever call a user-defined function in
the process (it could do bad things or just hang).

Right now I've resorted to use debug.getmetatable() (if the debug
library is there ...), but I'd rather like to have a 'safe'
getmetatable() again.

Bye,
     Mike