Jump to content




Is there a way to do .open("/file","rw")?


2 replies to this topic

#1 KFAFSP

  • Members
  • 42 posts
  • LocationGermany

Posted 12 June 2013 - 03:02 PM

Hello Pros,

I have tried quite a while now to make a more efficient TFileStream implementation in my class library. Compared to a regular stream in any non-Lua file-handling mechanisms, there is a major deficit: I can't seem to open a file for both reading AND writing. If you are not familiar with the idea: normally (i.e. in Windows) files are processed as streams. You open the stream, and then you can navigate using i.e. Seek(Position) to move to a specific byte. Then you use manipulating or non-manipulating methods, like Read() or Write() which affect the selected byte and then move the "cursor" on in the file. It is a very useful option to do it like that, especially if you don't want or don't need to have the whole file in your memory.

So what I of course tried was to open a file capable of reading and writing (io.open("/file", "rw")), so that I don't have to completely store it's contents in a table first. Is that even possible in the ComputerCraft lua environment? Am I missing something here, or not ;) ?

Thanks in advance,
KFAFSP

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 12 June 2013 - 04:07 PM

Nope. You'll need to create a new layer that loads the file into a table on first read and writes out changes when you call your close or flush method.

#3 KFAFSP

  • Members
  • 42 posts
  • LocationGermany

Posted 13 June 2013 - 01:28 PM

Ok, thats what I already got. Thanks anyways, quite a quick response.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users