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

fs.new

Started by Rougeminner, 20 September 2014 - 04:21 PM
Rougeminner #1
Posted 20 September 2014 - 06:21 PM
I am trying to rewrite the fs api for my operating system but i have been having problems with fs.open(). my code is obviously flawed because every time i use it the OS drops everything but itself. if you try to use any commands it says file not found. here is my code

local error1 = "fs error 1: This File is locked"
local error2 = "fs error 2: This File is read only"
local oldfs = {}
for k,v in pairs( fs ) do
oldfs[k] = v
end
function fs.move( fpath , tpath)
if fpath:sub(1,1) == ',' then
print("fs error 1: This File is locked")
else
oldfs.move(fpath,tpath)
end
end
function fs.opened( path,mode)
if path:sub(1,1) == ',' then
print(error2)
oldfs.open(path,'r')
else oldfs.open(path,mode)
end
end
function fs.delete(path)
if path:sub(1,1)==',' then
error(error1)
else
oldfs.delete(path)
end
end

can i get some help with this please.
Lyqyd #2
Posted 20 September 2014 - 07:04 PM
Don't change the name of the function and expect everything to work properly still. Change your replacement function name from opened to open.
Anavrins #3
Posted 20 September 2014 - 07:15 PM
Fixed indentation for readability…
Spoiler

local error1 = "fs error 1: This File is locked"
local error2 = "fs error 2: This File is read only"
local oldfs = {}

for k,v in pairs( fs ) do
  oldfs[k] = v
end

function fs.move( fpath , tpath)
  if fpath:sub(1,1) == ',' then
   print("fs error 1: This File is locked")
  else
   oldfs.move(fpath,tpath)
  end
end

function fs.opened( path,mode)
  if path:sub(1,1) == ',' then
   print(error2)
   oldfs.open(path,'r')
  else
   oldfs.open(path,mode)
  end
end

function fs.delete(path)
  if path:sub(1,1)==',' then
   error(error1)
  else
   oldfs.delete(path)
  end
end
You have renamed fs.open to fs.opened, which might be your problem.
Edited on 20 September 2014 - 05:16 PM
Rougeminner #4
Posted 24 September 2014 - 03:26 AM
i renamed it to see if it would fix my problem

didn't work to well forgot to replace it

EDIT: even with it replaced to fs.open it did not work


@lyqyd I didn't think it was going to work immediately. i was so doubtful that is was going to work i stopped working on it
Edited on 24 September 2014 - 01:32 AM
natedogith1 #5
Posted 25 September 2014 - 03:52 AM
Remember when you're calling old functions to do something with their value:

function fs.open(path, mode)
  oldfs.open(path, mode) --this will cause issues
end

function fs.open(path, mod)
  return oldfs.open(path, mode) --remembering to return the stuff
end
Also, you say the OS drops everything but itself, what do you mean by this?
Rougeminner #6
Posted 27 September 2014 - 05:30 AM
it says "file doesn't exist" not found something along those lines

edit: THANK YOU NATE THAT FIXED ALL MY PROBLEMS WITH FS.OPEN. to bad there is not a emoji icon for smacking myself in the forehead :)/>
Edited on 27 September 2014 - 03:30 AM