base.lua
local ext_base = {}
local function increaseLevel(level)
if level == 0 then
return 0
else
return (level or 1) + 1
end
end
function ext_base.printf(message, ...)
print(string.format(message, ...))
end
function ext_base.errorf(message, level, ...)
return error(string.format(message, ...), increaseLevel(level))
end
function ext_base.assertf(cond, message, level, ...)
if not cond then
return error(string.format(message, ...), increaseLevel(level))
else
return cond, message, level, ...
end
end
function ext_base.enumerate(iterator, ...)
local tbl = {}
for k in iterator, ... do
tbl[#tbl + 1] = k
end
return tbl
end
function ext_base.enumerateall(iterator, ...)
local tbl = {}
local last = { ... }
local state = table.remove(last, 1)
while true do
local ret = { iterator(state, unpack(last)) }
if ret[1] == nil then
break
end
last = ret
tbl[#tbl + 1] = ret
end
return tbl
end
return ext_base