I'm going a little bit off topic, but...
This is what the Vector3 metatable looks like (though the real Vector3 has an __add metamethod, I haven't the time to make it right now):
local Vector3 = {
new = function(x, y, z)
local X, Y, Z = type(x) == "number" and x or 0, type(y) == "number" and y or 0, type(z) == "number" and z or 0
local Vec = { x = X, y = Y, z = Z, magnitude = (x^2+y^2+z^2)^0.5}
return setmetatable({ }, {__index = Vec, __newindex = function(t, i, v) error(i.." cannot be assigned to.") end, __metatable = "This metatable is locked"})
end
}
local Vector = Vector3.new(1, 1, 0)
print(Vector.magnitude)
--Will be approx. 1.414 |