Last active
August 12, 2021 12:40
-
-
Save paulcuth/1270733 to your computer and use it in GitHub Desktop.
Implementation of instanceof in Lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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