[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: lua_setfield vs lua_rawset
- From: Mike Pall <mikelu-0510@...>
- Date: Wed, 19 Oct 2005 14:52:35 +0200
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
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'