added api.lua to data/ as reference file

This commit is contained in:
Jack 2020-01-30 15:41:36 +01:00
parent 81ecb1c630
commit bc5d3e9d7d

74
data/api.lua Normal file
View File

@ -0,0 +1,74 @@
function all(t)
if t ~= nil then
local nt = {}
local ni = 1
for _,v in pairs(t) do
nt[ni] = v
ni = ni + 1
end
for k,v in pairs(nt) do
end
local i = 0
return function() i = i + 1; return nt[i] end
end
return function() end
end
function add(t, v)
if t ~= nil then
t[#t+1] = v
end
return t
end
function foreach(c, f)
if c ~= nil then
for key, value in ipairs(c) do
f(value)
end
end
end
function mapdraw(...)
map(table.unpack(arg))
end
function count(t)
if t ~= nil then
return #t
end
end
-- check semantics
function del(t, v)
if t ~= nil then
local found = false
for i = 1, #t do
if t[i] == v then
found = true
end
if found then
t[i] = t[i+1]
end
end
end
end
function cocreate(f)
return coroutine.create(f)
end
function yield()
coroutine.yield()
end
-- TODO: missing vararg
function coresume(f)
return coroutine.resume(f)
end
function costatus(f)
return coroutine.status(f)
end