Posted 16 December 2012 - 03:29 AM
This really should be in the builtin API. You can bodge it in like this at present:
local vmt = getmetatable(vector.new(0, 0, 0))
vmt.__eq = function(a, B)/> return a.x == b.x and a.y == b.y and a.z == b.z end
vmt.__div = function(v, k) return v * (1/k) end,
To put this in the builtin API, it's as simple as replacing
local vmetatable = {
__index = vector,
__add = vector.add,
__sub = vector.sub,
__mul = vector.mul,
__unm = function( v ) return v:mul(-1) end,
__tostring = vector.tostring,
}
with
local vmetatable = {
__index = vector,
__add = vector.add,
__sub = vector.sub,
__mul = vector.mul,
__div = function(v, k) return v:mul(1/k) end,
__unm = function(v) return v:mul(-1) end,
__eq = function(a, B)/> return a.x == b.x and a.y == b.y and a.z == b.z end
__tostring = vector.tostring,
}