pico8-0hh1/utils.lua

63 lines
1.1 KiB
Lua
Raw Normal View History

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
2022-07-12 21:47:10 +02:00
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
2022-06-03 23:31:26 +02:00
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
2022-07-01 19:50:08 +02:00
function contains(tbl, o)
for v in all(tbl) do
if v == o then return true end
end
return false
end
2022-06-03 23:31:26 +02:00
--
-- 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