If I send a table via agent.send() to the device, the serialiser will serialise the object before sending it, reconstituting it on the other side. The serialiser doesn’t like some objects; namely functions, metas, classes, instances. Instead, it replaces them with a null and quietly prints an error message (“ERROR: skipped unserialisable data”) in the console.
I don’t agree that all these items are unserialisable. An instance can easily be serialised by iterating through its class. It would be really handy if this feature were supported by the inbuilt serialiser.
Instances are valuable in the device as they consume relatively little RAM compared to tables. Although, they are use relatively more RAM if the number of instances is small (eg <4). Consequently, I’ll use them as a container, often as part of more complex structures.
class ObjClass {
d=6
e=true
}
objInstance <- ObjClass()
agent.send("objSend",objInstance) // sends null to agent
objTable <- {
a=1
b=false
c={}
}
agent.send("objSend",objTable) // sends { "a":1, "b":false, "c":{} } to agent
objTable.c=objInstance
agent.send("objSend",objTable) // sends { "a":1, "b":false, "c":null } to agent
// ideally, it should send { "a":1, "b":false, "c": { "d":6, "e":true } }
The squirrel code for iterating through an object is:
foreach(k,v in object)
server.log("KEY="+k+" VALUE="+v)
The squirrel code for iterating through an object or instance of an object is:
foreach(k,v in (typeof(object)=="instance")?object.getclass():object)
server.log("KEY="+k+" VALUE="+object[k])
I imagine the code for extending agent.send and device.send would be only a couple of lines.