Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ Lua ➜ New interactive debugging in version 3.80

New interactive debugging in version 3.80

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Nick Gammon   Australia  (23,070 posts)  Bio   Forum Administrator
Date Wed 06 Sep 2006 02:52 AM (UTC)
Message

Version 3.80 of MUSHclient has a cool new feature, in addition to upgrading to Lua 5.1 script engine.

This is an interactive debugging facility, implemented by replacing the debug.debug function in the Lua debug library. The original one wasn't very useful as it required reading from stdin, which isn't really relevant for GUI programs.

The replacement invokes a dialog box, like this:

The first thing the dialog box does is automatically call debug.getinfo to find various things out about the current function (eg. name, line number, type of function).

Then you can use various buttons to request extra information be dumped into the output window, like local variables, upvalues, and a stack traceback.

If you want to find out further things, or change things, you can enter Lua statements into the "Command" window and press <Enter>.

If things look hopeless for your script, you can click on "Abort script".

Or, if you want to proceed, hit <Esc> or click on "Continue execution".

The nice thing about this debugger is that it executes in the context of whoever did the debug.debug () call. Thus, you can interactively debug things like plugins.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,070 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 06 Sep 2006 03:03 AM (UTC)
Message
Here is an example of how you could add breakpoints into a script:


breakpoints = { [14] = true, [18] = true }

function hook (why)
  local line = debug.getinfo (2, "l").currentline
  if breakpoints [line] then
    debug.debug ()
  end -- breakpoint wanted
end -- hook

debug.sethook (hook, "l", 0)

print (1)
print (2)
print (3)  -- line 14
print (4)
print (5)
print (6)
print (7)  -- line 18
print (8)



When I run this, the debugger is invoked after printing 2 (that is, when line 14 is reached), and after printing 6 (when line 18 is reached).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


9,185 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.