lua-users home
lua-l archive

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

> If you're happy with that, then tostring() will provide you with the
> identity of tables and userdata (although be careful of metatables
> overriding that).  I don't think there's a way of obtaining the hash (or
> address) of a string from plain Lua, but the remaining data types can
> all be hashed using algorithms written in Lua.

Since version 5.4, we can use the option "%p" in 'string.format' to
get the address of anything in Lua that has an address, including

  Lua 5.4.2  Copyright (C) 1994-2020, PUC-Rio
  > string.format("%p", "hi")
  > string.format("%p", "hello")
  > string.format("%p", print)
  > print(print)
  function: 0x5626ad9b2709

However, long strings can have multiple copies inside Lua, so equal
strings can have different addresses.

-- Roberto