[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Convert a string to table without changing the order of the items
- From: Dirk Laurie <dirk.laurie@...>
- Date: Fri, 6 Apr 2012 08:42:55 +0200
>
{{
["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