Created
August 24, 2023 04:29
-
-
Save creationix/b56de2dde4021673f24242258efdcc80 to your computer and use it in GitHub Desktop.
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
do | |
-- Polyfill for luajit without __pairs and __ipairs extensions | |
local triggered = false | |
pairs(setmetatable({}, { __pairs = function() | |
triggered = true | |
return function() end | |
end })) | |
if not triggered then | |
print "Polyfilling pairs" | |
function _G.pairs(t) | |
local mt = getmetatable(t) | |
if mt and mt.__pairs then | |
return mt.__pairs(t) | |
else | |
return next, t, nil | |
end | |
end | |
end | |
triggered = false | |
ipairs(setmetatable({}, { __ipairs = function() | |
triggered = true | |
return function() end | |
end })) | |
if not triggered then | |
print "Polyfilling ipairs" | |
function _G.ipairs(t) | |
local mt = getmetatable(t) | |
if mt and mt.__ipairs then | |
return mt.__ipairs(t) | |
else | |
return next, t, nil | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment