lua-users home
lua-l archive

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

> Before GC activity:
> > debug.upvalueid(f1, 1)
>   --> userdata: 0x1111111100
> > debug.upvalueid(f2, 1)
>   --> userdata: 0x1111111100
> After GC activity (upvaluejoin was NOT invoked):
> > debug.upvalueid(f1, 1)
>   --> userdata: 0x2222222200
> > debug.upvalueid(f2, 1)
>   --> userdata: 0x2222222200

Lua does not have this notion of "Before GC activity" or "After GC
activity". The GC is active all the time. Lots of things you do in Lua
can create GC activity.  In your particular example, compiling each
line in iteractive mode generates a lot of GC activity. Function calls
can generate GC activity. If you are debugging your code, each hook can
incur GC activity. Printing the identifier also incur in GC activity
(as it creates a string).

The analogy with a clock is apt. You cannot compare two clocks the way
you did, as they can tick together between the two calls. Similarly, it
is very easy for the GC to tick between the calls to 'upvalueid'.  If
any GC activity could change the identifier, it would be really hard to
use 'debug.upvalueid'. (Someone may whine that Lua has other equally
hard-to-use features; that is not the case here.)

> In other words, my question is:
> Are those hexadecimal digits after "userdata:" permanent?

"Permanent" seems a strong word, given that the whole program is
transient; but yes. I hope that a less picky reader can infer that
simply by the use of the word "identifier".

-- Roberto