Currently to get the magnitude of a vector v we might code
local v = vector(1,2,3)
local m = vector.magnitude(v)
One might reasonably expect
local m = v:magnitde()
to work, and similarly for other functions that might reasonably act like methods such as
local dp = v1:dot(v2)
and so on.
It does not work because a vector instance's metatable is not set to the functions in
vector
. Seems to me that it should be, so that vectors can be treated like any other SLua object or smart table.
I was somewhat surprised to find that vector is implemented as a native type rather than as an ordinary Lua table / object, with the functions in its metatable and so on. I would suppose that this might be because Luau already did it this way, or because of some performance concern. Curious.
In any case, since, in my view, any competent Lua / SLua scripter is going to use objects and the : notation, vectors (and quaternions and any other built-in structured types) would be far better if they worked like objects with metatables.
Thank you for your consideration and I'll be happy to assist with testing or Lua code if it would be useful.