lua-users home
lua-l archive

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


Matthew Armstrong wrote:
How do I get the address of a userdata object? This is solely for debugging
purposes.

For instance, if 't' is a table, and I say:
print(t)

It will say something like:
table: 05AED8F0

But, if I try that with a user data object, I get an error saying 'No such
operator defined'.

I don't know where the message 'No such operator defined' is coming from, but the default string representation for userdata in Lua 5.1 already includes an address:

   Lua 5.1.2  Copyright (C) 1994-2007 Lua.org, PUC-Rio
   > = newproxy()
   userdata: 00329758
   > = tostring(newproxy())
   userdata: 0032A9F8
   > print(newproxy())
   userdata: 0032ABF0

(I've used newproxy() as an example because it creates a userdata without a __tostring() metamethod.)

 - Peter Odding