This cart is a simple routine to deserialize a string into a table value. I know that there are other routines out there but this routine is simple and small. No serialization routine is give as it is assumed that the text is entered manually. If a list of items is added then remember that a final ',' is needed to actually add the item to the table.
Let's start collecting alternatives:
How does this compare with the native split()
?
https://www.lexaloffle.com/dl/docs/pico-8_manual.html#SPLIT
Split will not handle key/value pairs and nested tables, it can only split a string into elements. This function can, so using deser("a=25,b=value,c={x=-1,y=4})"
gives you an object which is identical to the following table:
{ a=25, b="value", c={ x=-1, y=-4 } } |
Please be aware that string quoting is not needed/implemented, any value will be converted to a number if possible.
Another approach can be found in
which implements a Forth-like programming language. Probably this could be extended to initialize data as well...
[Please log in to post a comment]