classic
classic copied to clipboard
is method has problems when value is nil. workaround?
There seems to be a problem with the design of the is method.
You can't do things like nil:is(SomeType)
This makes it pretty much useless for type checking as you have to guarantee that class variables are never nil.
I tried implementing it as a helper function with a little change...
function is(self, T)
if self == T then
return true
else
local mt = getmetatable(self)
while mt do
if mt == T then
return true
end
mt = getmetatable(mt)
end
end
return false
end
but it has the same problem.
Maybe there is a way to get around it? This would also effect https://github.com/rxi/classic/issues/20