Bugs in table documentation page and request for more info

In the table documentation page:

https://electricimp.com/docs/squirrel/table/

table.rawget(value) – gets a value from a table without employing delegation table.rawin(value) – gets a value from a table without employing delegation table.rawset(value, value) – gets a value from a table without employing delegation
I suspect that at least some of those are cut&paste errors.

Also, can you please add a section to that page on how to iterate through this table? I’m trying to log my httprequest.query table and I don’t quite understand this documentation:

http://electricimp.com/docs/squirrel/squirrelcrib/

foreach (i, item in table) { if (i_dont_like(item)) delete table[i] }
Can you explain what i versus item is? Maybe i should be key and item should be value?

Thanks.

We’ll make sure that gets looked at @dig090.

Here’s some code from an old forum post that recursively logs everything in table. In the below example it’s setup to log everything in the HTTPRequest object (including the query object):

`function logTable(t, i = 0) {
local indentString = “”;
for(local x = 0; x < i; x++) indentString += " ";

foreach(k, v in t) {
    if (typeof(v) == "table" || typeof(v) == "array") {
        local par = "[]";
        if (typeof(v) == "table") par = "{}";
        
        server.log(indentString + k + ": " + par[0].tochar());
        logTable(v, i+4);
        server.log(par[1].tochar());
    } 
    else { 
        server.log(indentString + k + ": " + v);
    }
}

}

http.onrequest(function(req, resp) {
try {
logTable(req);
resp.send(200, “OK”);
} catch (ex) {
resp.send(500, "Error: " + ex);
}
});`

Thanks for that @beardedinventor. I’ve refactored the code to a toString function:

/* return a string version of a table or array */ function collectionToString(table) { local result = ""; local prefix = ""; foreach(key, value in table) { if (typeof(value) == "table") { value = "{" + collectionToString(value) + "}"; } else if (typeof(value) == "array") { value = "[" + collectionToString(value) + "]"; } result = result + prefix + key + "=" + value; prefix = ", "; } return result; }

This allows me to do something like:

server.log("HTTP Request Query:" + collectionToString(request.query));

Your collectionToString function is now not very different from the built-in (on agents at least) http.jsonencode().

Peter