| View previous topic :: View next topic |
| Author |
Message |
modsyn
Joined: 27 Sep 2005 Posts: 28
|
Posted: Tue Sep 27, 2005 6:26 am Post subject: Reading a byte value |
|
|
Hi, I'm trying to read a value from a file and treat that value as the
number of characters to read next. I'm probably overlooking something
so simple, but I can't seem to figure out what it is. Here is my code
| Code: |
sfile = io.open(infile,"r")
numchar = sfile:read(1)
dataout = sfile:read(tonumber(numchar))
|
and the error message I get is "bad argument #1 to 'read' (invalid option)"
the first value is (for my testing purposes) a byte value of 9 followed by
9 characters that represent a file name.
I'm stuck until I can figure this out, so any help is greatly appreciated.
EDIT*
It was something obvious and I got it fixed.
| Code: |
sfile = io.open(infile,"r")
numchar = string.byte(sfile:read(1))
dataout = sfile:read(numchar)
|
Sorry to have mucked up the forum unnecessarily. |
|
| Back to top |
|
 |
KawaGeo
Joined: 27 Aug 2005 Posts: 191 Location: Calif Mountains
|
Posted: Tue Sep 27, 2005 7:02 am Post subject: |
|
|
Which read() that generated the error in your code?
Suggest to add print statement(s) for debugging purpose. Eg: print(numchar) after it is been read from the file. This should lead you to the finding.
Happy hunting. :) _________________ Geo Massar
Retired Engineer |
|
| Back to top |
|
 |
modsyn
Joined: 27 Sep 2005 Posts: 28
|
Posted: Tue Sep 27, 2005 7:14 am Post subject: |
|
|
it was the first code. i had many debug prints, but i left them out for ease
of reading. i finally got it fixed, as i edited the original post to say.
i finally found a decent source of general lua documentation. from
lua.org (ha, go figure). |
|
| Back to top |
|
 |
|