6 posts
Posted 02 March 2013 - 09:38 PM
Title: Http.get tables creation.
Hi, i'm kinda new to the tables and http api's (even if i figured some of them out), currently i'm trying to make my program download from pastebin a series of number (example: { 1=3, 2=3, 15=2 } etc…) and put them into a dictionary, but for some reason when i try to print out the contenent of a single key (example: print( tablename[2]) the program print a blank line.
Any known solutions?
Thanks in advance.
1190 posts
Location
RHIT
Posted 03 March 2013 - 06:25 AM
If we don't have code, we can't really help you. Are you using textutils.serialize/textutils.unserialize in order to convert the table into a useable form?
6 posts
Posted 04 March 2013 - 12:00 AM
I'll explain what i need to do:
In a pastebin page i stored some data that i need for the functioning of a program, when the program runs it needs to download it from the page using the Http.get API and put it into a table that i can then use for doing stuff.
For example:
if the page contains theese numbers: 1=3, 2=3, 3=2, etc… when i download them the table that it fill will need to contains these data: tablename = { 1=3, 2=3, 3=2, etc…} in a Lua Dictionary fashion, so if i for example request the N°1 data it returns me the number 3, if i request the number 2 it return me 3, if i request 3 it returns me 2 and so on.
1190 posts
Location
RHIT
Posted 04 March 2013 - 02:38 AM
You should definitely use textutils.serialize and textutils.unserialize to do this. Here's an example:
local t = {"table", "with", "stuff", 1, 2, ["item"] = true}
local a = textutils.serialize(t)
print(a)
This will output:
{[1]="table",[2]="with",[3]="stuff",[4]=1,[5]=2,["item"]=true,}
In string form. meaning that you could easily upload it to pastebin.
To return it to a table form, all you have to do is run textutils.unserialize on it and store the result in a variable.
Here's the wiki page for http:
http://www.computercraft.info/wiki/Http.getIf you need me to walk you through either one of these I'd be willing to, but give it a shot first yourself.
6 posts
Posted 04 March 2013 - 03:39 AM
Thanks i'll get right on to it!
6 posts
Posted 04 March 2013 - 06:56 AM
I've done a couple of test on it but it dosen't seems to be working.
i tryied this code:
sdata = http.get("
http://pastebin.com/raw.php?i=qL354k08")
usdata = textutils.unserialize(sdata)
for k,v in pairs(usdata) do print(k,v) end
but it returns me an error saying: textutilis:177 attempt to concatenete string and table
8543 posts
Posted 04 March 2013 - 07:07 AM
textutils.unserialize(sdata.readAll())