title: Deserialization of simple Lua table stored as string
body: <p>I'm transfering a lua table literal in a string from a web application in to PICO-8 that I'm trying to deserialize back in to a lua table in PICO-8.</p>
  
  <p>The string is in the form <code>'{"top", {"one", {"one a", "one b"}}, {"two", {"two a", "two b"}}}'</code></p>
  
  <p>To try and keep things simple I'm only going to include lowercase characters in the strings and only strings are allowed in the nested tables.</p>
  
  <p>I feel like I've got a grasp on parsing the characters, but I don't know how to keep track of where I am in the recreated data, both the depth of the structure and the index.</p>
  
  <p>How is this usually done?</p>
  
  <p>The catch is that as PICO-8 lua doesn't contain <code>load</code> or <code>loadstring</code> the parsing has to be done manually. The following code is using <code>table.insert</code> and <code>string.sub</code> instead of the PICO-8 equivalents because I'm using a lua REPL to help prototype this code.</p>
  
  <p>Here is what I have so far with print statements what I think I need to do where.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <pre><code>test_obj = {"top", {"one", {"one a", "one b"}}, {"two", {"two a", "two b"}}}
  data_string = '{"top", {"one", {"one a", "one b"}}, {"two", {"two a", "two b"}}}'
  data = nil
  string = ''
  level = 0
  while #data_string &gt; 0 do
   local d=string.sub(data_string,1,1)
    if stringChar(d) then
      string = string..d
    end
    if comma(d) then
      print(string)
      table.insert(data, string)
      string = ''
    end
    if openBracket(d) then
        if data == nil then
        data = {}
        print('new table')
      else
        print('insert table')
      end
      level = level + 1
      print('on level', level)
    end
    if closeBracket(d) then
      print('end of table')
      level = level - 1
      print('up to level', level)
    end
    data_string=string.sub(data_string,2)
  end
  </code></pre>