Created
October 24, 2021 20:44
-
-
Save R0bl0x10501050/78846e4a373a61132ffc1ca4ec19592f to your computer and use it in GitHub Desktop.
Undefined value for Luau
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
-- Written by R0bl0x10501050 | |
local module = { | |
['new'] = function() | |
local self = setmetatable({}, { | |
__newindex = function() | |
error("Cannot set property of undefined") | |
end, | |
__index = function(tbl, k) | |
if k == "DEBUG_CHECK" then | |
return true | |
else | |
error("Cannot retrieve property of undefined") | |
end | |
end, | |
__call = function() | |
error("Cannot call undefined") | |
end, | |
__concat = function() | |
error("Cannot concat undefined") | |
end, | |
__unm = function() | |
error("Cannot negate undefined") | |
end, | |
__add = function() | |
error("Cannot add undefined") | |
end, | |
__sub = function() | |
error("Cannot subtract undefined") | |
end, | |
__mul = function() | |
error("Cannot multiply undefined") | |
end, | |
__div = function() | |
error("Cannot divide undefined") | |
end, | |
__mod = function() | |
error("Cannot use undefined in a modulus expression") | |
end, | |
__pow = function() | |
error("Cannot use undefined in an exponent expression") | |
end, | |
__tostring = function() | |
return "[object Undefined]" | |
end, | |
__eq = function(this, other) | |
return true -- Since this will only run if two undefined values are being compared | |
end, | |
__lt = function() | |
error("Cannot compare undefined") | |
end, | |
__le = function() | |
error("Cannot compare undefined") | |
end, | |
__mode = 'kv', | |
__len = function() | |
error("Cannot get length of undefined") | |
end, | |
}) | |
return self | |
end, | |
['test'] = function(objA, objB) | |
if objA and not objB then return false end | |
local isAUndefined, isBUndefined = false, false | |
local s, _ = pcall(function() | |
return objA['DEBUG_CHECK'] | |
end) | |
if s then | |
isAUndefined = true | |
end | |
local s2, _ = pcall(function() | |
return objB['DEBUG_CHECK'] | |
end) | |
if s2 then | |
isBUndefined = true | |
end | |
return (isAUndefined and isBUndefined) | |
end, | |
} | |
return module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment