Skip to content

Instantly share code, notes, and snippets.

@cat-haines
Last active December 30, 2015 01:59
Show Gist options
  • Save cat-haines/7759246 to your computer and use it in GitHub Desktop.
Save cat-haines/7759246 to your computer and use it in GitHub Desktop.
Recursively traverses a Squirrel table (or object) and logs the results.
function stringify(t, i = 0) {
local indentString = "";
for(local x = 0; x < i; x++) indentString += ".";
if (typeof(t) != "table" && typeof(t) != "array") {
server.log(indentString + t)
} else {
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());
stringify(v, i+4);
server.log(indentString + par[1].tochar());
}
else {
server.log(indentString + k + ": " + v);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment