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

Openperipheral returning proxy

Started by agowa338, 16 July 2016 - 01:28 PM
agowa338 #1
Posted 16 July 2016 - 03:28 PM
Hello, I noticed, that the code

local p = peripheral.wrap("bottom")
s = p.getAllStacks()
print(s)
isn't working, because I receive a very strange table…
So after a view hours of googling, I came across this site: http://kd8lvt.altervista.org/openperipheral_docs.xhtml where the "getAllStacks" funktion is listed with a parameter.
After specifying the parameter it works as expected:

local p = peripheral.wrap("bottom")
s = p.getAllStacks(false)
print(s)

So can anyone explain, what this proxy is and what it is used for?
InDieTasten #2
Posted 16 July 2016 - 06:01 PM
getAllStacks(proxy?)

Get a table with all the items of the chest

Source: inventory

Arguments:


proxy (optional boolean) : If false, method will compute whole table, instead of returning proxy

Returns: table

Ok, so lets assume you don't use a proxy. You get the contents as expected, at raw format, saying they are static and have been retrieved at the point of calling getAllStacks

When you do get the proxy however, no data is going to be retrieved just yet. Only accessing the specific data entries will trigger the proxy (at time of querying the proxy object) to retrieve the data.

Without testing, i don't know if it will repeat retrieving "live" data, once you've called it once, but I would assume so, meaning, that you can read the data from the proxy, and it will do the whole retrieval live on that "p"

This is all assumptions, but maybe you can try and validate :)/>