Skip to content

Instantly share code, notes, and snippets.

@Rayquaza01
Created January 11, 2025 23:01
Show Gist options
  • Select an option

  • Save Rayquaza01/574a21a168aa38dc4c0b8b3ec2caf69b to your computer and use it in GitHub Desktop.

Select an option

Save Rayquaza01/574a21a168aa38dc4c0b8b3ec2caf69b to your computer and use it in GitHub Desktop.
Picotron External Loader
--[[
extload
load an external folder
]]
cd(env().path)
local argv = env().argv
if (#argv < 1) then
print("\f6usage: load filename -- can be file or directory")
exit(1)
end
filename = "/appdata/system/util/extrunner"
extdir = fullpath(argv[1])
attrib = fstat(filename)
if (attrib ~= "folder") then
-- doesn't exist or a file --> try with .p64 extension
filename = filename..".p64"
if (fstat(filename) ~= "folder") then
print("could not load")
exit(1)
end
end
-- remove currently loaded cartridge
rm("/ram/cart")
-- create new one
local result = cp(filename, "/ram/cart")
if (result) then
print(result)
exit(1)
end
store("/ram/extcart.pod", extdir)
-- set current project filename
store("/ram/system/pwc.pod", fullpath(filename))
-- tell window manager to clear out all workspaces
send_message(3, {event="clear_project_workspaces"})
--meta = fetch_metadata("/ram/cart")
meta = fetch_metadata(extdir)
if (meta and type(meta.runtime) == "number" and meta.runtime > stat(5)) then
print("** warning: this cart was created using a future version of picotron.")
print("** some functionality might be broken or behave differently.")
print("** please upgrade to the latest version of picotron.")
end
if (meta) dat = meta.workspaces
--[[ deleteme
dat = fetch("/ram/cart".."/.workspaces.pod")
if (not dat) printh("*** could not find\n")
]]
-- legacy location; to do: deleteme
if (not dat) then
dat = fetch("/ram/cart/_meta/workspaces.pod")
if (dat) printh("** fixme: using legacy _meta/workspaces.pod")
end
-- legacy location; to do: deleteme
if (not dat) then
dat = fetch("/ram/cart/workspaces.pod")
if (dat) printh("** fixme: found /workspaces.pod")
end
-- at the very least, open main.lua if it exists
if ((type(dat) ~= "table" or #dat == 0) and fstat("/ram/cart/main.lua")) then
--dat = {{location="main.lua"}} -- relative to /ram/cart/
dat = {{location=extdir.."/main.lua"}}
end
if (type(dat) == "table") then
-- open in background (don't show in workspace)
local edit_argv = {"-b"}
for i=1,#dat do
local ti = dat[i]
local location = ti.location or ti.cproj_file -- cproj_file is dev legacy
if (location) then
--add(edit_argv, "/ram/cart/"..location)
add(edit_argv, extdir.."/"..location)
end
end
-- open all at once
create_process("/system/util/open.lua",
{
argv = edit_argv,
pwd = extdir
}
)
end
print("\f6loaded "..filename.." into /ram/cart")
print("\f6loaded external cart " .. extdir)
-- main.lua for extrunner cart
if fstat("/ram/extcart.pod") == "file" then
cd(fetch("/ram/extcart.pod"))
include("/system/lib/resources.lua")
include("main.lua")
else
print("Couldn't load external cart!")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment