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

Variable Blocks

Started by H4X0RZ, 20 May 2013 - 04:04 PM
H4X0RZ #1
Posted 20 May 2013 - 06:04 PM
Hello everybody,
I have started programing PHP.

Now here is my question:
Can I have a lua function to read the content of an webpage. The content looks like this:


<first item>
Name = test
ID = 1
</first item>

<second item>
Name = test two
ID = 2
</second item>


And save it like this table:

local content = {
["first item"] = {Name = "test", ID = "1"},
["second item"] = {Name = "test two", ID = "2"}
}

Is this possible?
Engineer #2
Posted 20 May 2013 - 06:22 PM
That is definitely possible. I would say leave the name and ID, wich looks like this:

<block>
thenameofchoice
654
</block>

first of all we want to put all the contents of the site in a table:

local response = http.get('http://www.server.de') -- see what I did here?;p
local lines = {}
if response then
     for l in response.readLine do
          table.insert(lines, l)
     end
end
When you find a <block> you know you are getting first a name and then an ID.
You can probably do the rest yourself ^^

Edit: you want to search for an opening tag of course ( < )
H4X0RZ #3
Posted 20 May 2013 - 06:34 PM
That is definitely possible. I would say leave the name and ID, wich looks like this:

<block>
thenameofchoice
654
</block>

first of all we want to put all the contents of the site in a table:

local response = http.get('http://www.server.de') -- see what I did here?;p
local lines = {}
if response then
     for l in response.readLine do
          table.insert(lines, l)
     end
end
When you find a <block> you know you are getting first a name and then an ID.
You can probably do the rest yourself ^^

Edit: you want to search for an opening tag of course ( < )
Thx!

Only one question:
Is it possible to remove the "<" and the ">" after reading it in lua ?
BigSHinyToys #4
Posted 20 May 2013 - 07:21 PM
there is probably a better way but
string.sub(sText,2,#sText-1)