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

1


1

Oh, that's pretty handy!
I was using a build system, but I also had to systematically execute a command, which slowed down the iteration speed.

First util to join my workstation :)
Thanks a lot!

For neophytes like me who have skipped a step, extrunner is indeed a .p64 cart and not a .lua file (like extload.lua).


Hello,
I am a novice and French (Google translation).
What to do with "extload.lua" and "extrunner.lua"?
I do not understand what this method brings.
Personally, I use Visual Studio Code for the ".lua" editor.
For this I rename the card to edit in picotron with 2 . "my game..p64".
I can then open this folder with VSC, main.lua editor or any other
.lua, save (ctrl-s) on VSC and test by running on picotron by double-clicking "mygame..p64".
You have to keep picotron and vsc open to repeat quickly.
once finished, we must rename the card(folder) "mygame.p64" to edit on picotron.
(game..p64) for vsc
(game.p64) for picotron


@heliuse Huh, I didn't realize that you can name a folder to .p64 and double click it to run it.

When you load a cart, it makes that cart the present working cart (so you can run it with Ctrl+R). If you load a folder, it won't use the external changes when you press Ctrl+R. Extload is a workaround to make it so that Ctrl+R works when loading a folder and making external changes.

If you don't care about using Ctrl+R, then your method works fine! :)


It's only been a few days, and I've already changed my workflow at least 5 times!?
I realize I know nothing about Picotron or Lua. It's fun, exciting and ... confusing all at the same time :)

@heliuse this workflow seems pretty handy as I just drag the “.vscode\settings.json” from @arnaught into the special folder (“cart..p64”) and boom! Edit in vscode, test in picotron. The file can even be loaded into RAM with load cart..p64

It's a too bad that the load cartridge right-click function isn't available on folders, out of the box.
I hope the method will somehow survive, as it's an easy to remember solution.
Thanks


yes, my method also allows to "load s..p64" on the desktop in my case. Ctrl-r also works in addition to the double click.
I can thus edit with picotron and vsc.
the saves from picotons are directly updated in vsc.
on the other hand, you have to restart "load s..p64" in the picotron console to update the picotron editor after a save in vsc.
luckily the console keeps in memory with the up arrow
it would just be necessary for the save from vsc to update the picotron editor to avoid "load s..p64" with the console at each test with ctr-r
The double click does not have this problem


1

I succeeded thanks, you had to launch the commands in the console then use the src drawer
GG thanks :)


By combining renaming the card ..p64 your extload command is enough. we thus gain the double click.
the only remaining problem is the picotron editor which does not update when we save with vsc. we must close and reopen the tab.
the reverse is ok as well as ctrl-r and double-click.
We should modify code.p64 for an automatic refresh.



[Please log in to post a comment]