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

fs.open returns nil

Started by Awe2K, 25 November 2015 - 06:33 PM
Awe2K #1
Posted 25 November 2015 - 07:33 PM
Hello.
I've just started writing new cool thing and suddenly fs.open stopped working:

local h=fs.open("h.txt","w")
local lin=lines("hello\nworld")

print(h==nil)
-- And here, I get "true", so file handle is actually nil

if h then
for _,l in ipairs(lin) do
h.write(l)
end
h.close()
end
Are there any ways to make it work?
Edited on 25 November 2015 - 07:01 PM
KingofGamesYami #2
Posted 25 November 2015 - 07:57 PM
1) Is h.txt an existing file?
2) Why are you opening with fs in read mode & using it as if it's io in write mode?
Edited on 25 November 2015 - 06:57 PM
Awe2K #3
Posted 25 November 2015 - 07:59 PM
Whoops, forgot to change some code left after trying "w" mode.
Write mode did not help too.

H.txt doesn't exist when I call fs.open(…)
KingofGamesYami #4
Posted 25 November 2015 - 08:01 PM
Opening a file in write mode should always work, unless one of the following is happening:

1) Something has edited fs.open (delete / move any startup files, reboot computer to fix)
2) You are using an emulator (stop using an emulator to fix)
3) You're opening something that is read-only (eg rom/programs/edit) (Try running edit h.txt from the shell to see if this is the problem)
Awe2K #5
Posted 25 November 2015 - 08:05 PM
Well, my "startup" doesn't override fs.open (it replaces only things related to os.loadAPI)
I'm working in MC, so it's not an emulator. Tried to open it using shell: still no luck
Bomb Bloke #6
Posted 26 November 2015 - 12:11 AM
4) The computer's drive is full.
Awe2K #7
Posted 26 November 2015 - 07:19 AM
Okay, I'll try to increase limit
Edit: Well, that didn't help too
Edited on 26 November 2015 - 06:39 AM
Bomb Bloke #8
Posted 26 November 2015 - 01:16 PM
Time to show us the rest of the code, in that case.
Awe2K #9
Posted 26 November 2015 - 03:10 PM
Well, if dropbox links are allowed here…
(If not, I'll remove this). Just I have too many files to post here.
The most important code is in /lib/libfstream, /bin/luash and /boot/postInitHooks
https://www.dropbox....200/13.zip?dl=0
Awe2K #10
Posted 26 November 2015 - 06:03 PM
Alright, somehow this started working.
(Maybe with _G.fs.open = fs.open, but I don't know if it solved this)
Edited on 26 November 2015 - 05:32 PM