次のようなテーブルを返すヘルパー関数があります。
function of_type(expected_type)
return {
expected = expected_type,
matches = function(value) return type(value) == expected_type end,
describe = "type " .. expected_type
}
end
これは他のマッチャーでは問題ありませんでしたが、ここでは、関数が呼び出されtype(value)
たときに同じテーブルのフィールドに保存したいと思います。matches
このようなもの:
function of_type(expected_type)
return {
expected = expected_type,
mismatch = nil, -- set it to nil on initialization
matches = function(value)
mismatch = type(value) -- how to do this?
return type(value) == expected_type
end,
describe = "type " .. expected_type
}
end
これは可能ですか?