How / can I print out all slots / keys / values for a table?


If I’ve built or received a basic table in my squirrel code, is there any way to print out or get all the slots / keys / values in that table?

Thank you,

OK, to answer my own question partly, on the agent at least, you can run

to get a string / JSON representation of the table.

On the device you can try:

foreach(key,value in myTable)
  server.log("key="+key+" value="+value)

Note: this only works if the values in your table are (integer, float, boolean, string). If you have nested arrays or tables as values, you’ll need to either:

  • send the table to the agent to be encoded as JSON
  • include a squirrel json encoder in your device code
  • write a recursive version of the foreach statement above

It’s (probably) not complete, but: