Jonne Ransijn
unread,May 20, 2025, 10:19:23 AMMay 20Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to lua-l
This would have the same effect as `name = function() ... end`, just
like it does in global scope, and would allow for slightly more readable
OOP syntax:
```lua
Point = class {
function __new(self, x, y)
self.x = x or 0
self.y = y or x or 0
end,
function origin()
return Point(0, 0)
end,
function __add(self, other)
if type(other) == 'number' then
return Point(self.x + other, self.y + other)
end
return Point(self.x + other.x, self.y + other.y)
end,
function __tostring(self)
return string.format("Point(%d,%d)", self.x, self.y)
end,
}
print(Point.origin() + Point(3, 4))
```
I have attached a patch.