[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: creating a table from a file
- From: Robert Raschke <rtrlists@...>
- Date: Mon, 27 Jan 2014 14:34:03 +0000
/tmp $ cat table.txt
foo = { "value foo 1", "value foo 2", name="i'm foo"}
bar = { "value bar 1", "value bar 2", name="i'm bar"}
/tmp $ lua
Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio
> l={}
> for line in io.lines("table.txt") do
>> l[#l+1] = line
>> end
> safe={}
> t = assert( loadstring("return {" .. table.concat(l, ",") .. "}", nil, nil, safe) )()
> for top, subtable in pairs(t) do
>> for k, v in pairs(subtable) do
>> print(top, k, v)
>> end
>> end
foo 1 value foo 1
foo 2 value foo 2
foo name i'm foo
bar 1 value bar 1
bar 2 value bar 2
bar name i'm bar
>