How to convert a table formatted string to a table without using load () or loadstring ()?

Another question ( String to Table in Lua ) asked how to convert a string that is formatted as a table to a string, and this answer had to use loadstringor loadto convert the string to a piece, which is then executed.

I also have a program that downloads a file that is formatted as a lua table using http.request, like another question:

yourTable = http.request("http://www.somesite.com/table.txt")
print(yourTable)

--yourTable is a string that is formatted like a lua table, but not a table:
a={
    b = {
      c = 1,
      d = {
        e = {
        },
      },
    },
}

functionThatExpectsATable(yourTable) --throws error because yourTable is a string

load loadstring, , , URL . lua lua, .

?

+4

Source: https://habr.com/ru/post/1540079/


All Articles