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

Program to create other programs

Started by PointlessSpike, 29 July 2015 - 11:38 AM
PointlessSpike #1
Posted 29 July 2015 - 01:38 PM
Hi all

I was thinking about the HTTP API and what I know (as a web developer) are a plethora of potential uses. The main one, as far as I can see, is to have a turtle send a request to a server and download a bunch of programs, then automatically save them. Getting the programs is easy, but I have no idea if you can programmatically create new programs. Theoretically, it would be easy if you knew how, and then when you join a new server you could just create a small program to get other programs.

Has anyone managed to do this or know of a way it can be done?
Cranium #2
Posted 29 July 2015 - 04:39 PM
Moved to Ask a Pro.
flaghacker #3
Posted 29 July 2015 - 04:46 PM
Do you mean creating new files? If so, then you're looking for the fs api. If not, could you explain "create new programs"?
KingofGamesYami #4
Posted 29 July 2015 - 04:59 PM
Basically I'd make a simple script that downloads a (lua) table / file. The file would look like this:


return {
  ["TheProgramName"] = "theURLtoTheProgram",
}

..with additional entries as needed. Then, I'd use loadstring to make that into a function.

Finally, I'd call the function, get the table, iterate through it and download files using http.get and the fs API (link in above post).
PointlessSpike #5
Posted 30 July 2015 - 10:20 AM
Sounds like it might be easiest to just do a get for each program, and just call each one I want. That might be best anyway for if I have a large number of them and would end up with a ton of programs, with only a small number usable by/useful for any one computer.

And yes, the fs.api looks like what I was looking for. Suffice it to say that my experience with Lua is limited, so I'm still getting to grips with how it deals with things- I've only just realised that there's no distinction between a program and any other kind of file (obvious in hindsight, I know).

It sounds like this could be pretty easy to do, and a useful program to have. Thanks guys!
biggest yikes #6
Posted 30 July 2015 - 06:04 PM
And yes, the fs.api looks like what I was looking for. Suffice it to say that my experience with Lua is limited
The FS api is ComputerCraft only, if you were looking for a pure Lua solution for some reason you'd want the IO api.
Edited on 30 July 2015 - 04:05 PM