lua-users home
lua-l archive

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


On Thu, Oct 05, 2006 at 06:29:59PM -0500, Rici Lake wrote:
> And for a good reason. If you remove the 'self' argument from the 
> stack, and there is no other reference to it, then it could get garbage 
> collected while your method is running, with possibly disastrous 
> consequences.

These are C++ objects, with lifetime controlled by C++.  Garbage
collecting a table that happens to reference those objects isn't
going to affect the object itself, in this binding model.

> I suppose that you are either forcing the object to stay in existence 
> by keeping a luaL_ref to it, or being very careful to never do anything 
> which might trigger a garbage collection. On the whole, it doesn't 
> strike me as a good idea, but tastes (and problem domains) vary.

If I needed to handle objects with Lua lifetimes, I might look for
a way to stash the reference somewhere else for the duration of the
call, though sticking it in the registry seems expensive for every
method dispatch.  (A quick look at the VM suggests tweaking L->base
might be able to do this more or less for free, but I don't know the
internals that well.)

-- 
Glenn Maynard