I did not know what to name this question as I don't understand enough of what is going on.(Feel free to edit)
Consider the code below.
function object:new() o = o or { x = 0 } setmetatable(o, self) self.__index = self self.y = 0 return o end table = object:new()
What are the differences between the variables (o.x and self.y) later on?
If I print_r the variable table
, only the x is returned. However, both table.x
and table.y
can be accessed. This makes me realise that there is a difference between the two.
Could someone explain what the difference is and what reasons there are for putting variable in differant places?