This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
C_D_V's profile picture

How to save a Lua program?

Started by C_D_V, 14 March 2017 - 12:45 AM
C_D_V #1
Posted 14 March 2017 - 01:45 AM
Sorry if this is a bad title.. I'm super new to CC. I'm playing Tekkit Classic. I made a program in the Lua console and I want to save it onto a disk. How would I do this?
Lyqyd #2
Posted 14 March 2017 - 03:29 AM
Moved to Ask a Pro.
D3matt #3
Posted 14 March 2017 - 04:27 AM
In the lua console? Not in the edit program? I don't think there is a way to do that, at least not that I'm aware of. If you could figure out what variable stores the console's command history you could write that out to a file but I have no idea where to start with that.

If you mean the edit program, just save the file and then use "mv" to move it to /disk.
The Higher Realm #4
Posted 14 March 2017 - 05:51 AM
Place a disk drive next to the computer and put a floppy disk in it. Turn on the computer and type
cp [filename] /disk/
it will make a copy of it on the disk. To take it off the disk do
cp /disk/[filename] /
TheRockettek #5
Posted 14 March 2017 - 07:50 AM
the simplist way to do it is via the edit command in the shell which can be run by doing

edit <path/to/program>
However if you really want to use lua console look at the http://www.computerc...fo/wiki/Fs.open wiki page

fFile = fs.open("hello","a")
fFile.writeLine("I am writing text to this file")
fFile.close()
Edited on 14 March 2017 - 03:23 PM
Lupus590 #6
Posted 14 March 2017 - 11:06 AM
(reiterating what others have said but clearer)
The lua console doesn't have a save option as that's not its job, there is no easy way to export or save what has been written in the lua console. You should use the edit program for writing programs.
To use edit you need to give it a file name (the file doesn't have to exist yet). Example: edit exampleFile will create a file called example and open it in the edit program.
You can then write your program like with any text editor in real life. A menu can be opened with the ctrl key, you can the use the arrow keys and return to select save or exit, if you are using an advanced computer you may also have an option to run your code.
remember to save before you exit, edit will not remind you if you forget and you will lose your code.
Your new program can be run with the name you gave it (my example was exampleFile )
you can copy your code onto a disk with the copy command which has the 'nickname' cp Actiquack322 explained this quite well.
Place a disk drive next to the computer and put a floppy disk in it. Turn on the computer and type
cp [filename] /disk/
it will make a copy of it on the disk. To take it off the disk do
cp /disk/[filename] /
Lyqyd #7
Posted 14 March 2017 - 01:26 PM
If you've really written it to the lua console, just write that line out to a file. Put this in front:


handle = io.open("filename", "w"); handle:write([=[

and this behind your existing line in the lua prompt:


]=].."\n"); handle:close()
andrew65952 #8
Posted 05 April 2017 - 01:33 PM
(reiterating what others have said but clearer)
The lua console doesn't have a save option as that's not its job, there is no easy way to export or save what has been written in the lua console. You should use the edit program for writing programs.

Just pointing out what TheRockettek said earlier…

However if you really want to use lua console look at the http://www.computerc...fo/wiki/Fs.open wiki page

fFile = fs.open("hello","a")
fFile.writeLine("I am writing text to this file")
fFile.close()
Lyqyd #9
Posted 05 April 2017 - 02:31 PM
Rockettek said that later, not earlier. Notice the edit timestamp on his post. The part you quoted wasn't present in his initial post.