lua-users home
lua-l archive

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


It was thus said that the Great Russell Haley once stated:
> On Tue, Oct 3, 2017 at 8:39 PM, Sean Conner <sean@conman.org> wrote:
> >
> >   If I understand what you want, what about?
> >
> >         io,input('d1dat.txt')
> >         io.output('d1dat.out')
> >
> >         data = {}
> >
> >         for l in io.lines() do
> >           a,b,c = string.match(l,"(%w+)|(%d+)|(%w+)")
> >           table.insert(data, { a , b, c })
> >         end
> >
> >         for k,v in ipairs(data) do
> >           io.write(k,'-',data[1],'-',data[2],'-',data[3],'\n')
> >         end
> >
> >   -spc
> 
> Sorry, Seans answer works too. I got confused when the io.write threw an error:

  Oops, that's what I get for untested code.

> lua_: test.lua:18: bad argument #3 to 'write' (string expected, got table)
> stack traceback:
>     [C]: in function 'io.write'
>     test.lua:18: in main chunk
>     [C]: in ?
> 
> This is correct though:
> for k,v in ipairs(data) do
>   --print(k, data[k][1],data[k][2],data[k][3])
>   io.write(k,'-',data[k][1],'-',data[k][2],'-',data[k][3],'\n')
> end

  -spc