lua-users home
lua-l archive

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


On 2018-10-17 19:51, Dirk Laurie wrote:
For the umpteenth time I find myself copying this code from one program into another:

*snip*

For the umpteenth time I wonder whether I am the only Lua programmer that has ever wished that 'tostring' had an optional second
parameter allowing one to bypass the __tostring metametod.

The sole purpose of that is to get a textual sufficiently unique ID for
the thing?  (I'm guessing...)

You could auto-generate IDs and weaktable them. Is that good enough? That avoids tostring() altogether. (Could also be much more readable than random hex digits.)

Another fun question: If a table (or userdata?) is freed and another one is created later that has exactly the same address, will whatever you're doing break, or will it still work?

(But yeah, I've also added/used a debug.tostring() before... ^.^)

-- nobody