[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: creating a table from a file
- From: Tim Channon <tc@...>
- Date: Tue, 28 Jan 2014 01:55:17 +0000
Suggestion, mimic a serialise data format.
Given the codas about security and all the other stuff a simple version
is http://lua-users.org/wiki/SaveTableToFile
Put that is a library file and include, adds table.loadfile and table.save
Or mimic the easy to understand data format yourself. (ie. save a table
and eyeball the file, you have the load code)
On 25/01/2014 19:01, jseb wrote:
> Hello,
>
> I'd like to create a table, which contains sub-tables, from a file.
>
> Here is my test file:
>
> $ 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"}
>
>
> And here is my Lua source file:
>
> $ cat do_table.lua
> #!/usr/bin/env lua
>
> local t={}
>
> for line in io.lines("table.txt") do
> t[#t+1]={line}
> end
>
> for _,subtable in pairs(t) do
> for k,v in pairs(subtable) do
> print(k,v)
> end
> end
>
>
> If i launch this script, i get this:
> $ ./do_table.lua
> 1 foo = { "value foo 1", "value foo 2", name="i'm foo"}
> 1 bar = { "value bar 1", "value bar 2", name="i'm bar"}
>
> but that's not what i expected.
> I want to have this, instead:
>
> 1 foo = table 0x12345689
> 2 bar = talbe 0x23456780
>
> Is this a problem of interpretation of the line i read ?
>
> Thank you.
>
>
>
>