When you print specific types in lua (e.g. functions and tables), you get the type name and address, as shown below:
> tab = {} > print(tab) table: 0xaddress
I created a simple class as shown below, and I would like to override the __tostring method __tostring same way. How to get the address of the object I want to print?
Here is my class. I would like to print(pair) print Pair: 0xaddress . Obviously, this is a trivial example, but the concept is useful:
Pair = {} Pair.__index = Pair function Pair.create() local p = {} setmetatable(p, Pair) px = 0 py = 0 return p end function Pair:getx() return self.x end function Pair:gety() return self.y end function Pair:sety(iny) self.y=iny end function Pair:setx(inx) self.x=inx end
source share