mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Add debug.id RFC
This commit is contained in:
parent
ce9f4e23ae
commit
eb6ce66195
1 changed files with 27 additions and 0 deletions
27
rfcs/function-debug-id.md
Normal file
27
rfcs/function-debug-id.md
Normal file
|
@ -0,0 +1,27 @@
|
|||
# `debug.id`
|
||||
|
||||
## Summary
|
||||
|
||||
Add `debug.id` which accepts a value and always returns the identifier unique to that value.
|
||||
|
||||
## Motivation
|
||||
|
||||
When debugging, it is often useful to compare identity. Usually `print` will print the memory address of the table or userdata, but when `__tostring` is overriden, the address becomes unobtainable.
|
||||
|
||||
`rawequal` can compare equality between two arguments, but is not suitable for a human comparing output between two `print` calls or between keys or values in a table.
|
||||
|
||||
## Design
|
||||
|
||||
`debug.id(value: any)` always returns the identifier unique to that value, and is not possible to override.
|
||||
|
||||
While tables and userdata have individualized metatables, also allowing functions and threads to be passed to `debug.id` would let their type-level `__tostring` be redefined. Strings are useful to accept because of long, similar strings.
|
||||
|
||||
## Drawbacks
|
||||
|
||||
None known.
|
||||
|
||||
## Alternatives
|
||||
|
||||
Lua has `string.format("%p", {})`, but this is an invalid format option in Luau and less obvious.
|
||||
|
||||
If not implemented, it remains annoying to compare identity when dealing with tables or userdata that override `__tostring`.
|
Loading…
Add table
Reference in a new issue