mirror of
https://github.com/kanaka/mal.git
synced 2024-09-19 09:38:28 +03:00
8a19f60386
- Reorder README to have implementation list after "learning tool" bullet. - This also moves tests/ and libs/ into impls. It would be preferrable to have these directories at the top level. However, this causes difficulties with the wasm implementations which need pre-open directories and have trouble with paths starting with "../../". So in lieu of that, symlink those directories to the top-level. - Move the run_argv_test.sh script into the tests directory for general hygiene.
54 lines
1006 B
Lua
54 lines
1006 B
Lua
local M = {}
|
|
|
|
function M.try(f, catch_f)
|
|
local status, exception = pcall(f)
|
|
if not status then
|
|
catch_f(exception)
|
|
end
|
|
end
|
|
|
|
function M.instanceOf(subject, super)
|
|
super = tostring(super)
|
|
local mt = getmetatable(subject)
|
|
|
|
while true do
|
|
if mt == nil then return false end
|
|
if tostring(mt) == super then return true end
|
|
mt = getmetatable(mt)
|
|
end
|
|
end
|
|
|
|
--[[
|
|
function M.isArray(o)
|
|
local i = 0
|
|
for _ in pairs(o) do
|
|
i = i + 1
|
|
if o[i] == nil then return false end
|
|
end
|
|
return true
|
|
end
|
|
]]--
|
|
|
|
function M.map(func, obj)
|
|
local new_obj = {}
|
|
for i,v in ipairs(obj) do
|
|
new_obj[i] = func(v)
|
|
end
|
|
return new_obj
|
|
end
|
|
|
|
function M.dump(o)
|
|
if type(o) == 'table' then
|
|
local s = '{ '
|
|
for k,v in pairs(o) do
|
|
if type(k) ~= 'number' then k = '"'..k..'"' end
|
|
s = s .. '['..k..'] = ' .. M.dump(v) .. ','
|
|
end
|
|
return s .. '} '
|
|
else
|
|
return tostring(o)
|
|
end
|
|
end
|
|
|
|
return M
|