lua-users home
lua-l archive

create nested table from string

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


How can be a nested table created from strings/data pairs like this?
 <Strings> def. the table should be filled with <Data>
 "Colour." "black"
 "Colour.Markus." "blue"
 "Colour.Markus." "yellow"
 "Colour.Thomas" "green" -- note: without the last point
 "Colour.Group.Heinz." "red"
So the result should be a table:
 print(Colour[1]) --> "black"
 print(Colour.Markus[1]) --> "blue"
 print(Colour.Markus[2]) --> "yellow"
 print(Colour.Thomas) --> "green"
 print(Colour.Group.Heinz[1] --> "red"
Any solutions without using dostring()? I think a recursive function
call does the work and I will programm this later this day but possible
someone has an already running solution or any other good ideas.
--
Markus

AltStyle によって変換されたページ (->オリジナル) /