This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Pyuu's profile picture

Why FS?

Started by Pyuu, 07 February 2016 - 04:52 AM
Pyuu #1
Posted 07 February 2016 - 05:52 AM
I've never understood this piece. FS API, the Filesystem. Why not natively support IO? Why not support "wb" in IO? Why make FS, when FS causes problems like {} appearing in files that are being written to? (Note, this is me ranting after having to switch every use of FS to IO because it broke everything because it kept saving everything as "{}").

Why was FS made? And Why can't we just have the normal IO api?
Dragon53535 #2
Posted 07 February 2016 - 06:04 AM
Are you using textutils.serialize? That's the only thing I know of that adds {}
Bomb Bloke #3
Posted 07 February 2016 - 06:39 AM
I've got a vague hunch that if you pass an empty table to textModeHandle.write() these days, it'll automatically serialise it. Haven't bothered to sit down and test it, as it certainly wouldn't be backwards compatible with eg CC 1.5x.

Otherwise I've no idea what you're referring to with the {} thing. Within ComputerCraft, the io API is a wrapper for the fs API (here's the relevant source); switching fs usage within your own code to io usage isn't really changing much.
Lignum #4
Posted 07 February 2016 - 11:30 AM
This happens when you use colon notation with the fs api.


local file = fs.open("myfile", "w")
file:write("a")
file:close()

Since file:write("a") will become file.write(file, "w"), it will try to write the file handle, which for some reason becomes serialised as an empty table.

If you do this, everything will work fine:

local file = fs.open("myfile", "w")
file.write("a")
file.close()
Pyuu #5
Posted 07 February 2016 - 01:41 PM
Thing is, I don't understand the whole {} thing either. I don't pass tables through io/fs operations without serializing them with functions first. It really frustrates me when I don't understand "Why?" something does what it does. Some operations using fs.open obj:write obj:close were working, but others were just blanking out files with {}. This was done offline in Single Player (so you can be assured that there was no funny business going on with the computer.)

This happens when you use colon notation with the fs api.


local file = fs.open("myfile", "w")
file:write("a")
file:close()

Since file:write("a") will become file.write(file, "w"), it will try to write the file handle, which for some reason becomes serialised as an empty table.

If you do this, everything will work fine:

local file = fs.open("myfile", "w")
file.write("a")
file.close()

Oh, my god. Thank you.