lua-users home
lua-l archive

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


On Sunday 19 January 2003 06:36 pm, "jimmyp_gr wrote:

> Yes but what happens if "string" isn't actually assigned to the global
> s.That is, s is a global but of nil value.So each time s gets assigned
> to, the __newindex metamethod gets called.This metamethod calls an
> internal C routine wich assigns "string" (the pointer to it that is)
> to an internal C var.The point of all of this is to allow exported C
> vars which can be assigned to from lua as if they were norma lua
> vars.But the string ("string").Doesn't actually get assinged to any
> lua vars although the statement looks like it.s still has a nil value
> so that the next time it is assigned to the metamethod and internal C
> routine is called again to do the actual job.Will the string still not
> be garbage collected?

Nope, that won't work. What matters to the garbage collector is not whether 
the assignment happens, but whether a reference exists. The next time the 
garbage collector runs, it will notice that no Lua variable points to 
"string", and collect it.