This is a fun thing that allows select Ruby code (namely loops with ranges) to execute as valid Lua code.
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
--Luby 1.0 | |
function construct_iterator(n) | |
local at = 0 | |
return function() | |
at = at + 1 | |
return n[at] | |
end, n | |
end | |
local p_meta = { | |
__concat = function(first, second) | |
local out = {} | |
for index = first[1], second[1] do | |
out[#out + 1] = index | |
end | |
return construct_iterator(out) | |
end, | |
__add = function(first, second) | |
return ((type(first) == "table") and first[1] or first) + ((type(second) == "table") and second[1] or second) | |
end, | |
__sub = function(first, second) | |
return ((type(first) == "table") and first[1] or first) - ((type(second) == "table") and second[1] or second) | |
end, | |
__div = function(first, second) | |
return ((type(first) == "table") and first[1] or first) / ((type(second) == "table") and second[1] or second) | |
end, | |
__mult = function(first, second) | |
return ((type(first) == "table") and first[1] or first) * ((type(second) == "table") and second[1] or second) | |
end, | |
} | |
setmetatable(getfenv(), { | |
__newindex = function(self, key, value) | |
if (type(value) == "number") then | |
rawset(getfenv(), "out", {value}) | |
setmetatable(out, p_meta) | |
end | |
rawset(self, key, out or value) | |
end | |
}) | |
return {} |
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
print(#require("luby") | |
) | |
a = 1 | |
b = 10 | |
for i in (a..b) do | |
print(i) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment