[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Simple write to files-request for help
- From: Michal Kottman <k0mpjut0r@...>
- Date: Thu, 29 Dec 2011 19:30:10 +0100
On 29 December 2011 18:41, chuck@allthehowards.com
<chuck@allthehowards.com> wrote:
> My result?
>
> c:\cwh1>lua glist2.lua
> lua: glist2.lua:10: attempt to index global 'IP2file' (a nil value)
> stack traceback:
> glist2.lua:10: in main chunk
> [C]: ?
>
> =========================
>
> --The code
>
> MACfile=io.open ("MAC.dat" , w)
> IP1file=io.open ("IP1.dat" , w)
> IP2file=io.open ("IP2.dat" , w)
Because you use w, which is an undefined variable, therefore it's
value is nil. If the second parameter of io.open() is nil, it defaults
to 'r'. Because the file does not exist, it returns nil, therefore
IP2file is nil also.
Use the following:
MACfile=io.open ("MAC.dat" , 'w')
IP1file=io.open ("IP1.dat" , 'w')
IP2file=io.open ("IP2.dat" , 'w')
Reading the manual of io.open() would help:
http://www.lua.org/manual/5.1/manual.html#pdf-io.open