Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
SpaceBeeGaming

Debugging threads?

Question

3 answers to this question

Recommended Posts

  • 0
  • Solution

the function xpcall should give you a traceback witch will tell you what line the error is genratet

usage:

syc, e = xpcall(functionToRun, debug.traceback)
--[[ syc: true or false: where false means that there was an error
e: a full error message i.e:
line bla-bla-bla: bad argument bla-bla-bla
traceback:
at line bla-bla-bla in function bla-bla-bla
...

]]

 

Link to post
Share on other sites
  • 0

also treads doesn't create an critical error in the main scope so a great way to run a thread in terms of debuging is by printing the error on the screen and start a blocking function such as computer.beep()

 

funciton runThreadWithExelentDebuging(func)
  thread.create(function() 
    local syc, e = xpcall(func, debug.traceback)

    if syc == false then
      //syc is false this means an error was genrated in func
      require("term").clear()
      print(e)
      require("computer").beep(500,10) //calling computer.beep to avoid other threads or the main scope to redraw the screen
    end
  end)
end

--disclamer: this is not tested

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.