Jump to content




Loading an API on the fly?

networking utility lua

5 replies to this topic

#1 DannySMc

  • Members
  • 1,808 posts
  • Location/home/dannysmc95

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 by DannySMc, 19 March 2015 - 09:40 AM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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.

#3 DannySMc

  • Members
  • 1,808 posts
  • Location/home/dannysmc95

Posted 19 March 2015 - 10:12 AM

No not an OS, just a program, and would you be able to explain to me?

#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 19 March 2015 - 11:34 PM

Er, explain what part to you, exactly?

#5 Geforce Fan

  • Members
  • 846 posts
  • LocationMissouri, United States, America, Earth, Solar System, Milky Way, Universe 42B, Life Street, Multiverse, 4th Dimension

Posted 20 March 2015 - 02:11 AM

View PostDannySMc, on 19 March 2015 - 10:12 AM, said:

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.

#6 DannySMc

  • Members
  • 1,808 posts
  • Location/home/dannysmc95

Posted 20 March 2015 - 09:11 AM

View PostGeforce Fan, on 20 March 2015 - 02:11 AM, said:

View PostDannySMc, on 19 March 2015 - 10:12 AM, said:

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!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users