Log In  

Cart #deserialization_v1-0 | 2024-02-10 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
1

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.

P#141365 2024-02-10 15:09

Let's start collecting alternatives:

P#141367 2024-02-10 15:21

How does this compare with the native split()?
https://www.lexaloffle.com/dl/docs/pico-8_manual.html#SPLIT

P#141370 2024-02-10 16:32
1

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.

P#141373 2024-02-10 17:47

Another approach can be found in

Cart #34207 | 2016-12-26 | Code ▽ | Embed ▽ | No License
7

which implements a Forth-like programming language. Probably this could be extended to initialize data as well...

P#141376 2024-02-10 18:46

[Please log in to post a comment]