pico8-0hh1/utils.lua
2023-10-07 19:15:47 +02:00

62 lines
1.1 KiB
Lua

local oldprint = print
function print(t, x, y, col1, col2)
if col2 then
for i = -1, 1 do
for j = -1, 1 do
oldprint(t, x + i, y + j, col2)
end
end
end
return oldprint(t, x, y, col1)
end
function str_width(str)
return print(str, 0, -8)
end
function print_shade(t, x, y, col1, col2)
print(t, x, y + 1, col2)
print(t, x + 1, y + 1, col2)
print(t, x, y, col1)
end
function set_state(state, ...)
local args = { ... }
if gs and gs._leave then gs._leave() end
gs = state
if gs and gs._enter then gs._enter(unpack(args)) end
end
--
-- Returns the indices of found occurences of `o` within `tbl`
--
function find(tbl, o)
local indices = {}
for k, v in ipairs(tbl) do
if v == o then add(indices, k) end
end
return indices
end
function contains(tbl, o)
for v in all(tbl) do
if v == o then return true end
end
return false
end
--
-- Makes a shallow table copy
--
function copy(tbl)
return map(tbl, function(o) return o end)
end
--
-- Table equality - shallow comparison
--
function equal(tbl1, tbl2)
for k, _ in ipairs(tbl1) do
if tbl1[k] ~= tbl2[k] then return false end
end
return true
end