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

fs.readAll() Doesn't work

Started by viluon, 09 April 2014 - 08:11 AM
viluon #1
Posted 09 April 2014 - 10:11 AM
Hello,
I've got a problem. When trying to read a table from file and unserialize it, the program stops at fs.readAll() without any response. It doesn't even collapse nor it returns any kind of error. This is my code:


args={...}
print("[Debug] Started")

function load(name)
  print("[Debug] CMD-open")
  local file = fs.open(name,"r")
  print("[Debug] CMD-read")
  local data = file.readAll()
  print("[Debug] CMD-close")
  file.close()
  print("[Debug] Loaded")
  return textutils.unserialize(data)
end

function DoWork()
  print("[Debug] Loading File...")
  Settings=load("../registry/HW/MouseClick/Subscribers","r")

  for index,value in pairs(Settings) do
	shell.run(value,"MouseClick",args)
	print("[Debug] Called "..value)
  end

  print("[Debug] Finished")
end

if pcall(DoWork) then
else
  error()
end

The cmd arguments are given by an event listener and always contain arguments gained from mouse_click event.
Output of this code stops at [Debug] CMD-read.
Does anyone know how to solve this? :?

thanx 4 any response

Oh, I forgot, the subscribers file contains a table which serialized looks like this

{
  "ls",
  "cd",
}
and (as u can see) contains list of programs called when the mouse_click event fires.
CometWolf #2
Posted 09 April 2014 - 04:02 PM
What on earth is the point of this?

if pcall(DoWork) then
else
  error()
end
pcall prevents errors from crashing your program, but when it errors you go ahead and call an emtpy error, thus crashing your program anyways?

My best guess would be that your file dosen't exist, and it's actually returning an attempt to index nil error, which you are missing because of the way you're using pcall.
theoriginalbit #3
Posted 09 April 2014 - 04:05 PM
What on earth is the point of this?
-code snip-
pcall prevents errors from crashing your program, but when it errors you go ahead and call an emtpy error, thus crashing your program anyways?
why it ends the program without outputting an error message of course.
apemanzilla #4
Posted 09 April 2014 - 04:11 PM
What on earth is the point of this?
-code snip-
pcall prevents errors from crashing your program, but when it errors you go ahead and call an emtpy error, thus crashing your program anyways?
why it ends the program without outputting an error message of course.
So, you're essentially stabbing yourself in the foot here.

Also, when you call the "load" function you pass it two arguments where it only takes one - the file name.
Edited on 09 April 2014 - 02:13 PM