Writing to file with Offset. How?

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
SeeD
Posts: 2
Joined: Mon Sep 03, 2007 4:52 pm

Writing to file with Offset. How?

Post by SeeD »

Is there any way to write files with offset?
For example, I need to write value 01 in #2C5C

All I found was fileSeek function, but it`s not what I am looking for.

Sorry for my bad English and thanks in advance!
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

http://luanet.net/lua/function/seek
function file:seek ( whence, offset )
Looks to me like you can do:

Code: Select all

file:seek("set", 0x2C5C)
file:write(0x01)
That doesn't work for you?
SeeD
Posts: 2
Joined: Mon Sep 03, 2007 4:52 pm

Post by SeeD »

thank you for helping =)

here is my code

Code: Select all


file = io.open("test", "wb")
file:seek("set", 0x03) 
file:write(0x01)

file:close()
test file before writing (HEX):

00 00 00 00 00 00 00

test file after LUA (HEX):
00 00 00 31

what should I use as an instance of file:write?
thanks again!
romero126
Posts: 200
Joined: Sat Dec 24, 2005 2:42 pm

Post by romero126 »

Use options "+r"
PeterM
Posts: 125
Joined: Sat Dec 31, 2005 7:25 pm
Location: Edinburgh, UK
Contact:

Post by PeterM »

Just to clarify, you're using "wb" which opens a new file (deletes the old one) in binary mode.
http://aaiiee.wordpress.com/

I can no longer do any homebrew PSP development nor discuss PSP specific topics.
Post Reply