Jump to content




Program to create other programs



  • You cannot reply to this topic
5 replies to this topic

#1 PointlessSpike

  • Members
  • 3 posts

Posted 29 July 2015 - 12: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?

#2 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 29 July 2015 - 03:39 PM

Moved to Ask a Pro.

#3 flaghacker

  • Members
  • 655 posts

Posted 29 July 2015 - 03: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"?

#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 29 July 2015 - 03: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).

#5 PointlessSpike

  • Members
  • 3 posts

Posted 30 July 2015 - 09: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!

#6 biggest yikes

  • Members
  • 573 posts

Posted 30 July 2015 - 05:04 PM

View PostPointlessSpike, on 30 July 2015 - 09:20 AM, said:

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 by Atenefyr, 30 July 2015 - 05:05 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users