I'd like to extend that idea for even more simple debugging.
; $callstack(N).prop - returns information about the call stack of the script.
;
; $callstack(0) - returns the size of the call stack
; $callstack(1).file - returns the file name of the current script (like $script if N=1)
; $callstack(1).line - returns the line number of the current script
; (NOT like $scriptline if N=1 - should be the line where the error occured)
; $callstack(2).type - returns the type of the calling script (event, alias, identifier)
; $callstack(2).name - returns the name of the calling script
; ("join" for on JOIN events, "bleh" for an alias or identifier called "bleh", ...)
; $callstack(2).params - returns the parameters given to the alias (like $1- if N=1)
;
; $cerror - returns the error without file/line info (yes, you can script that by yourself)
on *:JOIN:#:{
addnick $nick
}
alias addnick {
; Note that i "forgot" to give the control number
did -a joindialog $1
}
alias did {
!did $1-
:error
if ($2 == joindialog) {
echo -a error: $cerror
var %i 1
while ($callstack(%i).type) {
echo -a $iif(%i == 1,in:,called by:) $callstack(%i).type $callstack(%i).name $&
file: $callstack(%i).file line $callstack(%i).line params: $callstack(%i).params
inc %i
}
}
}
; Example output:
;
; error: /did: 'joindialog' invalid id '0'
; in: alias did file: something.mrc line 24 params: -a joindialog somenick
; called by: alias addnick file: something.mrc line 20 params: somenick
; called by: event join file: something.mrc line 15 params:
An alternative for the last line could be that there's a different $callstack().type for normal events ("on"), "ctcp" and "raw". In my opinion, "called by: on join" looks better than "event join".
Another idea would be not having to script this by yourself, but a built-in command called /callstack or something that puts this information into a file, a dialog box or a custom @window.
Feel free to comment or extend this idea.