Log In  


Typically, when using an external editor, I do cp -f cart.p64 src and then work on src externally. Every time I make a change, I need to load src before running. Then, I can put it back in the cart by doing cp -f src cart.p64.

The suggested way of using external editors in the docs is to have the code externally, and simply include it from inside the cart. This will automatically use the latest external change, but it makes it harder to switch back to editing inside Picotron, as you need to change parts of your code to put everything back in the cart.

I made a quick utility to make loading an external folders easier.

extload is a modified version of /system/util/load.lua that loads a folder for external editing. It saves the path of the folder in /ram/extcart.pod and loads extrunner instead of the actual folder. (It also loads the workspaces from the folder, though this is a little janky.)

extrunner is a dummy cart that cds into the external folder (from /ram/extcart.pod), loads the graphics and sfx (by including /system/lib/resources.lua), and runs it (by including main.lua).


So, to set up an external project:

  1. Create a cart for the project (cart.p64)
  2. Extract the cart (cp -f cart.p64 src)
  3. Load the extracted cart (extload src)
  4. Make any changes with an external editor, test those changes with Ctrl+R
  5. When done, rebuild the cart (cp -f src cart.p64)

This lets you work on any cart externally without having to load src every time you make an external change and without needing to make any code changes!


extload.lua

--[[
	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)

extrunner main.lua

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

https://gist.github.com/Rayquaza01/574a21a168aa38dc4c0b8b3ec2caf69b




[Please log in to post a comment]