lua-users home
lua-l archive

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

On Mon, Feb 1, 2021 at 4:42 PM Roberto Ierusalimschy wrote:
The documentation says:

   These unique identifiers allow a program to check whether different
   closures share upvalues.  Lua closures that share an upvalue (that
   is, that access a same external local variable) will return identical
   ids for those upvalue indices.

This quote doesn't answer my question.

A light userdata is just an address of some internal object.
The object's addresses are subject to change during GC activity.
The quote from the manual you've posted might theoretically allow the following situation:

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

At any given moment of time identical ids are returned, as the manual claims.
But the manual promises nothing about how long the result of upvalueid() remains valid.

It is similar to determining if two clocks are synchronized
local time1 = what_time_is_it(clock1)
local time2 = what_time_is_it(clock2)
print(time1 == time2)
A "clock manual" might say:
> The returned values from what_time_is_it() allow a program to check
> whether different clocks share the time.
> Clocks that share the time will return identical values.
But "what_time_is_it(clock1)" might return another value on the next invocation.

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