Lua - 用向量索引的数组

似乎用向量作为索引的数组不是根据向量的值而是根据向量的地址进行索引的。例如:

local a = vmath.vector3(1,2,3)
    local b = vmath.vector3(1,2,3)
    test = {}
    test[a] = 1
    print(a==b, test[a], test[b])

输出结果为 "true, 1, nil"

这个行为正常吗?如何用值而不是地址作为数组索引?

点赞
用户5252811
用户5252811

如 Egor Skriptunoff 在评论中提到的那样,解决方案是使用 tostring() 将向量转换为字符串。

2019-06-21 13:50:27