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

Loading an API on the fly?

Started by DannySMc, 19 March 2015 - 08:39 AM
DannySMc #1
Posted 19 March 2015 - 09:39 AM
So I want to make a program, I have an API for this program,

I want to be able to download the API and then run it and be able to call it?

I do not want to download and save it though as it is a big file?

So I can use say:


local req = http.get(<url_to_api>)
req = req.readAll()
api = loadstring(req)

Then be able to call like:

api.draw.box(args, etc)

Thanks!
Edited on 19 March 2015 - 08:40 AM
Bomb Bloke #2
Posted 19 March 2015 - 10:04 AM
Normally I'd tell you to read the code for os.loadAPI() from bios.lua, and write a modified version for yourself based on its content. However, at a glance, this does exactly what you're asking already.

Though if you're thinking of using this for an OS of some sort, I suggest reconsidering. http calls on every boot? Bleh.
DannySMc #3
Posted 19 March 2015 - 10:12 AM
No not an OS, just a program, and would you be able to explain to me?
Bomb Bloke #4
Posted 19 March 2015 - 11:34 PM
Er, explain what part to you, exactly?
Geforce Fan #5
Posted 20 March 2015 - 02:11 AM
No not an OS, just a program, and would you be able to explain to me?
In my topic, I have posted code. You paste it at the top of your program.
The function you want is:
pastePI
You give it
pastePI(pasteID,API)
For example if the JSON API was at paste ID XXXXX, you'd do:
pastePI("XXXXX","json")
and the table "json" would contain all functions of the JSON API.
DannySMc #6
Posted 20 March 2015 - 09:11 AM
No not an OS, just a program, and would you be able to explain to me?
In my topic, I have posted code. You paste it at the top of your program.
The function you want is:
pastePI
You give it
pastePI(pasteID,API)
For example if the JSON API was at paste ID XXXXX, you'd do:
pastePI("XXXXX","json")
and the table "json" would contain all functions of the JSON API.

Ahh yes I have took the code apart and changed it so it works without having arguments, but you are a lifesaver for that, so thankyou!