Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is method has problems when value is nil. workaround? #21

Open
Shadowblitz16 opened this issue Dec 19, 2021 · 0 comments
Open

is method has problems when value is nil. workaround? #21

Shadowblitz16 opened this issue Dec 19, 2021 · 0 comments

Comments

@Shadowblitz16
Copy link

Shadowblitz16 commented Dec 19, 2021

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 #20

@Shadowblitz16 Shadowblitz16 changed the title is method problems when value is nil. workaround? is method has problems when value is nil. workaround? Dec 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant