Howto:Serializing Nasal data structures: Difference between revisions

Line 87: Line 87:
}  
}  


# create an empty vector
var myVector = [];
var myVector = [];


# populate the vector with elements with [index, index^2]
for (var i=0;i<=40;i+=1) {
for (var i=0;i<=40;i+=1) {
append(myVector,[i, i*i]);
append(myVector,[i, i*i]);
Line 97: Line 100:
# debug.dump(myVector);
# debug.dump(myVector);


# serialize the data structure to a string that is valid Nasal syntax
var serialized = serialize(myVector);
var serialized = serialize(myVector);


# debug.dump(serialized);
# debug.dump(serialized);


 
# next, compile the serialized string to a Nasal function
var compiled = compile(serialized);
var compiled = compile(serialized);
# actually call the function, and store the return value
var result = compiled();
var result = compiled();
# dump the deserialized return value to the console
debug.dump(result);
debug.dump(result);


</syntaxhighlight>
</syntaxhighlight>


== Finally ==
== Finally ==