A Lua library full of random functions made by me for me!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
986 B

-- Turns strings sorta into tables
local string_meta = getmetatable('')
function string_meta:__index(key)
local value = string[key]
if value then
return value
elseif tonumber(key) then
return self:sub(key, key)
else
error("attempt to index a string value with bad key ('"..tostring(key).."' is not part of the string library)", 2)
end
end
-- Delay for a specified amount of seconds.
function os.sleep(n)
local time = os.clock() + n
repeat until os.clock() > time
end
-- Writes the value of each of its arguments to default output file in a slow manner.
function io.swrite(...)
if not Pause then
Pause = 0.05
end
for _, text in pairs{...} do
text = tostring(text)
for j = 1, string.len(text) do
io.write(text[j])
io.flush()
os.sleep(Pause)
end
end
end
-- Return iterator of the results after applying the given function
function map(func, array)
local newArray = {}
for i, v in ipairs(array) do
newArray[i] = func(v)
end
return newArray
end