Jump to content




fs.readAll() Doesn't work

lua computer help

  • You cannot reply to this topic
3 replies to this topic

#1 viluon

  • Members
  • 183 posts
  • LocationCzech Republic

Posted 09 April 2014 - 09: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.

#2 CometWolf

  • Members
  • 1,283 posts

Posted 09 April 2014 - 03: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.

#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 09 April 2014 - 03:05 PM

View PostCometWolf, on 09 April 2014 - 03:02 PM, said:

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.

#4 apemanzilla

  • Members
  • 1,421 posts

Posted 09 April 2014 - 03:11 PM

View Posttheoriginalbit, on 09 April 2014 - 03:05 PM, said:

View PostCometWolf, on 09 April 2014 - 03:02 PM, said:

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 by Apemanzilla, 09 April 2014 - 03:13 PM.






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users