lua-users home
lua-l archive

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


In fact, even type-checking doesn't help. 

If I have a typical boxed pointer userdata, with a metatable, and I probably want the __gc method to delete the object boxed.

Now, I can call udata:__gc() from Lua code.  The userdata still exists, but the boxed object has been deleted.  Other calls on the udata can now segfault.  

I really think __gc should not be visible to Lua code.

On Mar 30, 2007, at 2:21 AM, Graham Wakefield wrote:

Hi,

Today I discovered that a __gc method installed on a userdata metatable is visible to Lua code; when called out of context it is likely to cause crashes, so any __gc metamethod in C must typecheck the argument.

I was surprised to find this out, I thought __gc would be 'hidden' from Lua.  I'm not sure I can think of a reason why you'd want to call a userdata's __gc from lua code.

Thought others should know.

Graham

grrr waaa
www.grahamwakefield.net