454 posts
Location
London
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
473 posts
Location
Poland
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
724 posts
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.
411 posts
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!
473 posts
Location
Poland
Posted 04 March 2012 - 09:39 AM
how about http.get?
411 posts
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.
724 posts
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.
1604 posts
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:/>/>
454 posts
Location
London
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.
1604 posts
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.
454 posts
Location
London
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.