forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Reading a byte value

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
modsyn



Joined: 27 Sep 2005
Posts: 28

PostPosted: Tue Sep 27, 2005 6:26 am    Post subject: Reading a byte value Reply with quote

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
View user's profile Send private message
KawaGeo



Joined: 27 Aug 2005
Posts: 191
Location: Calif Mountains

PostPosted: Tue Sep 27, 2005 7:02 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
modsyn



Joined: 27 Sep 2005
Posts: 28

PostPosted: Tue Sep 27, 2005 7:14 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group