CC: Tweaked

CC: Tweaked

42M Downloads

Edit launches scripts in the wrong directory

SquidDev opened this issue ยท 3 comments

commented

When using the "Run" option from edit, we save to a file called /.temp and run it:

https://github.com/SquidDev-CC/CC-Tweaked/blob/30d35883b83831900b34040f0131c7e06f5c3e52/src/main/resources/data/computercraft/lua/rom/programs/edit.lua#L392-L397

Historically this was fine, but is more problematic now that require exists. As the package path relies on the directory the program is stored in, packages may not be found.

There's a couple of possible solutions to this:

  • Save the file in the script's directory iff the directory isn't read only.
  • Write a bootstrap script which then loads the program and uses cc.require to bootstrap a new package environment.

Neither are going to be perfect - ideally we'd even be able to fake getRunningProgram, but they might work. Ideas welcome!

commented

In L.47f it modifies the shell in the environment to return the correct value for shell.getRunningProgram I imagine something similar would work for this as well.

OK, that's horrific.

commented

Neither are going to be perfect - ideally we'd even be able to fake getRunningProgram, but they might work. Ideas welcome!

It might be worth taking a look at how trace deals with this stuff, in L.47f it modifies the shell in the environment to return the correct value for shell.getRunningProgram I imagine something similar would work for this as well.

Although, since multishell is unable to launch a function directly, we'd still need to write to a .temp file with some sort of wrapper around it.

commented

I think the above commit fixes this as much as is really possible for now.