Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Vector
- local _prototype = {x=0, y=0, z=0}
- function _prototype:tostring()
- local pattern = "Vector: (x=%.2f, y=%.2f, z=%.2f)"
- return string.format(pattern, self.x, self.y, self.z)
- end
- function _prototype:equal(other)
- return (self.x == other.x and
- self.y == other.y and
- self.z == other.z)
- end
- function _prototype:add(other)
- return new(
- self.x + other.x,
- self.y + other.y,
- self.z + other.z)
- end
- function _prototype:sub(other)
- return new(
- self.x - other.x,
- self.y - other.y,
- self.z - other.z)
- end
- local _mt = {
- __index = _prototype,
- __tostring = _prototype.tostring,
- __eq = _prototype.equal,
- __add = _prototype.add,
- __sub = _prototype.sub
- }
- function new(x, y, z)
- local o = {x=x, y=y, z=z}
- setmetatable(o, _mt)
- return o
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement