Skip to content

Instantly share code, notes, and snippets.

@pancelor
Last active April 7, 2024 09:16
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pancelor/0489fc0671cc566db24ee737af4f94c3 to your computer and use it in GitHub Desktop.
Save pancelor/0489fc0671cc566db24ee737af4f94c3 to your computer and use it in GitHub Desktop.
picotron API explorer
-- picotron api explorer (p64env)
-- by pancelor
-- https://pancelor.com
--[[
## how to install
1. open picotron (buy from https://www.lexaloffle.com/picotron.php)
2. press escape to open the terminal
3. run `folder`. a file explorer should open on your host OS.
you should see `appdata` and `desktop`
4. navigate to `appdata/system/util` (make the `util` folder if it doesn't exist yet)
5. download this file into the util folder as `p64env.lua`
6. done! to launch this program, run `p64env` from the terminal (inside picotron)
7. to quit the program, right click on the extra terminal workspace in the top-right and close it
## how to use
* scroll with up/down arrow keys or mouse wheel
* (arrow keys seem broken in 0.1.0b?)
* left-click on table names to expand/collapse children
* guess what the functions do, experiment with them in code; good luck!
]]
function _init()
cls(16)
-- state (all in one variable so its easy to ignore)
st={
vars={}, -- vars
ytop=0, -- scroll position
vy=0, -- speed
mb=0, -- prev mouse
}
-- note: this program explores the contents of `_G`. `_ENV` might also be interesting to look at instead?
-- I don't think there's much of a difference but I'm not 100% sure
for k,v in pairs(_G) do
if k~="st" then
add(st.vars,{
key=k,
val=v,
expand=false, -- show table entries
})
end
end
printh(#st.vars)
-- fungsort
for i=1,#st.vars do
for j=1,#st.vars do
if st.vars[i].key<st.vars[j].key then
st.vars[i].key,st.vars[j].key=st.vars[j].key,st.vars[i].key
st.vars[i].val,st.vars[j].val=st.vars[j].val,st.vars[i].val
end
end
end
end
function _draw()
local mx,my,mb,unknown,mwheel = mouse()
local click = mb&~st.mb&1>0
st.mb = mb
-- scroll
st.vy+=mwheel*2
if btn(2) then st.vy+=1 end --doesn't seem to work unless this is saved as a full .p64 cart and run normally (not a terminal command)
if btn(3) then st.vy-=1 end
st.vy=st.vy*0.94
st.ytop+=st.vy
cls(16)
local y=flr(st.ytop)
print("================================================================================================",0,y,20)
y+=9
y+=9
for i,dat in ipairs(st.vars) do
local hover = mid(y-1,y+7,my)==my
local istab = type(dat.val)=="table"
if hover then
rectfill(0,y-1,480,y+7,istab and 15 or 22)
end
if hover and click and istab then
dat.expand = not dat.expand
end
if istab then
print(dat.expand and "." or ">",4,y,14)
end
print(dat.key,12,y,14)
print(tostr(dat.val),240,y,7)
-- show table entries
if dat.expand then
for k,v in pairs(dat.val) do
y+=9
print("| "..k,12,y,15)
print(tostr(v),240,y,7)
end
end
y+=9
if y>270 then break end -- lag less by drawing less
end
print("================================================================================================",0,y,20)
y+=9
-- scroll boundary
if st.ytop>40 then st.vy-=0.3 end
if y<270-40 then st.vy+=0.3 end
end
@bikibird
Copy link

bikibird commented Feb 4, 2024

This is very cool and useful. In the code, I needed to change get_mouse() to mouse() in order for it to work, though.

@pancelor
Copy link
Author

pancelor commented Feb 5, 2024

thanks for the tip! that must have changed at some point. I've updated the gist, and added mouse wheel support as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment