classic icon indicating copy to clipboard operation
classic copied to clipboard

is method has problems when value is nil. workaround?

Open Shadowblitz16 opened this issue 4 years ago • 0 comments

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

Shadowblitz16 avatar Dec 19 '21 20:12 Shadowblitz16