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

[1.3-][SSP/SMP] fs file handles don't support : operator.

Started by Advert, 04 March 2012 - 06:14 AM
Advert #1
Posted 04 March 2012 - 07:14 AM
You can't use hHandle:write() with fs objects; they will write "Table: ABCDEF" to the file instead (the hHandle's table instance).

fs file handles should ignore the first parameter if it's a table.

ComputerCraft Version: 1.3

Observed Behaviour:


local hHandle = fs.open("file", "w")
hHandle:write("thiswillnotbewritten")
hHandle:close()
local hHandle = fs.open("file", "r")
print(hHandle:read())
hHandle:close()

Output:

Table: ABCDEF

Expected Behaviour:

Same code as above;

Output:


thiswillnotbewritten
Liraal #2
Posted 04 March 2012 - 07:59 AM
Noticed that too, especially annoying when dealing with HTTP API, when i can't use io handles instead
Sebra #3
Posted 04 March 2012 - 08:16 AM
After reading lua 5.1 manual I was so many times stopped by "not implemented"…
I want at least a list of implemented file functions.
Casper7526 #4
Posted 04 March 2012 - 09:35 AM
local hHandle = io.open("file", "w")
hHandle:write("thiswillnotbewritten")
hHandle:close()
local hHandle = io.open("file", "r")
print(hHandle:read())
hHandle:close()

WIN!
Liraal #5
Posted 04 March 2012 - 09:39 AM
how about http.get?
Casper7526 #6
Posted 04 March 2012 - 09:49 AM
site = http.get("http://google.com")
print (site:readLine())
site:close()

Pretty sure that's right, havn't used http in a while.
Sebra #7
Posted 04 March 2012 - 12:04 PM
local hHandle = io.open("file", "w")
hHandle:write("thiswillnotbewritten")
hHandle:close()
local hHandle = io.open("file", "r")
print(hHandle:read())
hHandle:close()
It is example, not a full list.
But I've seen io API file already.
MysticT #8
Posted 04 March 2012 - 02:01 PM
That's because you have to use handle.function() and not handle:function() with handles you get from fs.open(). The io API just wraps a file handle to use it like that (handle:function())
It took some time to find out this when the all the files I saved just had a "Table (some number)" instead of what I wanted :unsure:/>/>
Advert #9
Posted 04 March 2012 - 06:39 PM
That's because you have to use handle.function() and not handle:function() with handles you get from fs.open(). The io API just wraps a file handle to use it like that (handle:function())
It took some time to find out this when the all the files I saved just had a "Table (some number)" instead of what I wanted :unsure:/>/>

This is exactly why I'm suggesting dropping the first argument if it's a table.
MysticT #10
Posted 04 March 2012 - 06:53 PM
That's because you have to use handle.function() and not handle:function() with handles you get from fs.open(). The io API just wraps a file handle to use it like that (handle:function())
It took some time to find out this when the all the files I saved just had a "Table (some number)" instead of what I wanted :unsure:/>/>

This is exactly why I'm suggesting dropping the first argument if it's a table.
Ok then, but this isn't a bug, it's a suggestion, and I agree to that. In normal lua you can use the table:function() notation with files, so CC should do the same.
Advert #11
Posted 04 March 2012 - 08:00 PM
That's because you have to use handle.function() and not handle:function() with handles you get from fs.open(). The io API just wraps a file handle to use it like that (handle:function())
It took some time to find out this when the all the files I saved just had a "Table (some number)" instead of what I wanted :unsure:/>/>

This is exactly why I'm suggesting dropping the first argument if it's a table.
Ok then, but this isn't a bug, it's a suggestion, and I agree to that. In normal lua you can use the table:function() notation with files, so CC should do the same.

I would call this a bug. File handles are treated as objects, and as such, they should support the : operator.