lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>
    {{
    ["vvector"]="(0, 1, 0)",
    ["uvector"]="(1, 0, 0)",
    ["origin"]="(0, 0, 0)",
    },
    }

> I need to convert this to a table but the order of the data must stay
> the same.

I would do this in two stages:

First convert the string to this format, using gsub as in the other
suggestions:

{"vvector={0, 1, 0}", "uvector={1, 0, 0}",  "origin={0, 0, 0}", }

which can be brought in using loadstring as you do.  (Thanks to
the other replies this is an exercise for the reader.)  It evaluates
to an array of strings, preserving order.  Each entry can be
loadstringed by itself when needed.

I.e.

   t1 = [[ {"vvector={0, 1, 0}", "uvector={1, 0, 0}",  "origin={0, 0, 0}", } ]]
   loadstring("a="..t1)()
   loadstring(a[3])()
   print(origin[2])   --> 0