lua-users home
lua-l archive

Re: [5.1.4/newbie] "attempt to index ... 'file' (a nil value)"?

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


On 02/18/2011 06:53 AM, Gilles Ganault wrote:
Hello
	I'm trying to create a text file, and google for samples on how to
do this, but regardless of using a global or local variable to hold
the file descriptor, I get the following error:
"attempt to index global 'file' (a nil value)"
"attempt to index local 'file' (a nil value)"
Here's the script:
=============
#!/var/tmp/lua
--file = io.open ('/var/tmp/myfile.txt',w)
local file = io.open ('/var/tmp/myfile.txt',w)
file:write(Blah")
file:close()
=============
What am I doing wrong?
I'll piggy-back on this question to ask what the difference is between
"io.stdin:read()" and "io.read()".
Thank you.
You probably meant file:write("Blah") with two double quotes right?-Patrick

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