Duplicate of What is newproxy() and what is it good for?, flag this post
I recently learned about the existence of
newproxy which creates empty userdata, useful for creating identifiers that aren’t numbers, or anything you can recreate. I see that in Lua 5.1, a userdata respects
__len and some other metamethods. I also think that a userdata costs less memory than an empty table.
However, I don’t know if using it is safe.
newproxy was removed in Lua 5.2, but it is in Luau (for compatibility?). Lua 5.2 and Luau also added
__len support for tables, which was previously supported by
newproxy. I won’t use metatables, I will be using it as an identifier object. Is it actually useful and supported? Or should I go with an empty table? Or should I try using a more OO way of doing it, by turning that into a table with values, and combine that with the functionality an “identifier object” can provide?