From eb6ce66195686ba26783c93205100559dacb8f46 Mon Sep 17 00:00:00 2001 From: Qualadore Date: Sat, 1 Jul 2023 17:24:18 +0000 Subject: [PATCH] Add debug.id RFC --- rfcs/function-debug-id.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 rfcs/function-debug-id.md diff --git a/rfcs/function-debug-id.md b/rfcs/function-debug-id.md new file mode 100644 index 00000000..a70c3319 --- /dev/null +++ b/rfcs/function-debug-id.md @@ -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`. \ No newline at end of file