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:
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?
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);
}
}
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; }