Skip to content

Instantly share code, notes, and snippets.

@paulcuth
Last active August 12, 2021 12:40
Show Gist options
  • Save paulcuth/1270733 to your computer and use it in GitHub Desktop.
Save paulcuth/1270733 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