Skip to content

Instantly share code, notes, and snippets.

@darmie
Forked from paulcuth/instanceof.lua
Created April 9, 2016 09:29
Show Gist options
  • Save darmie/7f98da2d09ac8e28fc839078ef58be30 to your computer and use it in GitHub Desktop.
Save darmie/7f98da2d09ac8e28fc839078ef58be30 to your computer and use it in GitHub Desktop.
Implementation of instanceof in Lua
function instanceOf (subject, super)
super = tostring(super)
local mt = getmetatable(subject)
while true do
if mt == nil then return false end
if tostring(mt) == super then return true end
mt = getmetatable(mt)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment