update_hooks = {} -- https://pico-8.fandom.com/wiki/Qsort function qsort(a, c, l, r) c, l, r = c or function(a, b) return a < b end, l or 1, r or #a if l < r then if c(a[r], a[l]) then a[l], a[r] = a[r], a[l] end local lp, k, rp, p, q = l + 1, l + 1, r - 1, a[l], a[r] while k <= rp do local swaplp = c(a[k], p) -- "if a or b then else" -- saves a token versus -- "if not (a or b) then" if swaplp or c(a[k], q) then else while c(q, a[rp]) and k < rp do rp -= 1 end a[k], a[rp], swaplp = a[rp], a[k], c(a[rp], p) rp -= 1 end if swaplp then a[k], a[lp] = a[lp], a[k] lp += 1 end k += 1 end lp -= 1 rp += 1 -- sometimes lp==rp, so -- these two lines *must* -- occur in sequence; -- don't combine them to -- save a token! a[l], a[lp] = a[lp], a[l] a[r], a[rp] = a[rp], a[r] qsort(a, c, l, lp - 1) qsort(a, c, lp + 1, rp - 1) qsort(a, c, rp + 1, r) end return a end function filter(a, pred) filtered = {} for k, v in pairs(a) do if pred(v) then filtered[k] = v end end return filtered end function fmt(x, depth) depth = depth or 1 if (depth > 4) then return "STACK_OVERFLOW" end if x == nil then return "nil" end t = type(x) if t == "number" then return "" .. x elseif t == "string" then return x elseif t == "table" then s = "{" i = 0 for k, v in pairs(x) do if i ~= 0 then s = s .. ", " end i += 1 s = s .. fmt(k, depth + 1) .. "=" .. fmt(v, depth + 1) end return s .. "}" elseif t == "function" then return "F()" elseif t == "boolean" and x then return "true" elseif t == "boolean" and not x then return "false" end return "_unknown_" end _button_states = {} function _update_button_states(_dt) for button = 0, 20 do if btn(button) then if _button_states[button] == "up" then _button_states[button] = "just_pressed" else _button_states[button] = "held" end else _button_states[button] = "up" end end end update_hooks[1] = _update_button_states function button_just_pressed(id) return _button_states[id] == "just_pressed" end