Skip to content

Instantly share code, notes, and snippets.

@pancelor
Last active December 2, 2021 07:04
Show Gist options
  • Save pancelor/881e2919853e2286ea60525de0df8ea4 to your computer and use it in GitHub Desktop.
Save pancelor/881e2919853e2286ea60525de0df8ea4 to your computer and use it in GitHub Desktop.
small demo of pico-8's runtime drag-and-drop interface
--[[
0x800 dropped file // stat(120) returns true when data is available
0x802 dropped image // stat(121) returns true when data is available
0x804 stdin
0x805 stdout
0x806 file specifed with: pico8 -i filename
0x807 file specifed with: pico8 -o filename
]]
function readline(maxlen)
maxlen=maxlen or 1000
local s=""
for i=1,maxlen do
serial(0x800,0,1)
local ch=chr(@0)
if ch=="\n" then
return s
end
s..=ch
end
assert(nil,"line too long")
end
-- -- zep's verison, from `load #activity`:
-- -- tbh something like might be better than my
-- -- way above
-- while (stat(120)) do
-- local len=
-- serial(0x800, 0, 16000)
--
-- for i=1,len do
-- local c=chr(@(i-1))
-- assert(c, @(i-1))
-- if (c=="\n") then
-- process_line(ln)
-- ln=""
-- else
-- ln..=c
-- end
-- end
--
-- print_stats() flip()
--
-- end
-- process_line(ln) --leftovers
function _init()
lines={}
end
function _update60()
if stat(120) then
local s=readline()
add(lines,s)
end
end
function _draw()
cls(1)
if #lines==0 then
print"drag-drop a text file"
else
for l in all(lines) do
print(l)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment