Check if a value is a vec2 or other codea type?

Hi. Is there any function to check if a value is a vec2 or vec3 or some other codea type?

Currently I’m doing ’type(value) == ”userdata” and value.angleBetween ~= nil’ to check for a vec2.

I’m using it to modify msgpack to encode data. GitHub - kieselsteini/msgpack: A MessagePack implementation for Lua 5.3/5.4 - msgpack.org[Lua]

Here’s something I just threw together. It might work.


function setup()
    a=vec4(5,6,7,3)
    print(vecType(a))
    
    a=vec3(5,9,3)
    print(vecType(a))
    
    a=vec2(5,9)
    print(vecType(a))
end

function vecType(v)
    if v.w ~= nil then
        return 4
    elseif v.z ~= nil then
        return 3
    elseif v.y ~= nil then
        return 2
    end    
end

Yes, I guess you have to find some unique properties to find out what type it is. You have to check for the type userdata as well, otherwise you will misplace tables as vectors.