mIRC Homepage
Posted By: poiuy_qwert Signal callback support. - 23/06/06 09:51 PM
I think the /signal command should have callback support. This would make it a lot easier to make modules for scripts. What I think should be added is:

Add the /sreturn command, which only works in a signal.
Code:
/sreturn <text>
- <text> is the line of text to be added to the list.

This command could be called multiple times, each being added to a list. You can then use the $signal identifier to retrieve the lines by their number.
Also, when the /signal command is given, the list would be reset for that signal name.

Add the $signal identifier. This would be used to get the data returned by the /sreturn command.
Code:
$signal(<name>,<N>)
- <name> is the name of the signal that had the /sreturn.
- <N> is which line to get.

Also, if the -r switch is used on the /signal command and no /sreturn is used in the on SIGNAL event, the list of returns would be to parameters of the /signal.

Add the -r switch to /signal.
Code:
/signal -r <name> <parameters>[code]

Here is a small example:
[code]on ^*:TEXT:*:?:{
  ;The -r switch is used, so if there is no signal, $nick and $1- will be added to the list as line 1 and 2.
  signal -r ontext $nick $1-
  ;$signal is used to get the lines returned by the ontext signal.
  echo -a $signal(ontext,1) $signal(ontext,2)
  halt
}
on *:SIGNAL:ontext:{
  ;Add $+(<,$1,>) to the list as the first line, because its the first /sreturn used.
  sreturn $+(<,$1,>)
  ;Add $2- to the list as the second line.
  sreturn $2-
}


Sorry if this is a bad explanation, if it is i'll try and explain better.
Posted By: genius_at_work Re: Signal callback support. - 24/06/06 12:48 AM
I don't think that this could work. Unless I'm mistaken, signals are asynchronous, as opposed to /commands which are synchronous. When a script is running and you call a command (other than /signal) the exectution of the script stops until that specific command is finished. However, when you use signals, the script sends out a "start" message to the onSIGNAL event handlers, and the original script continues executing to its end. So by the time the signal is able to return its value, the calling script has already completed (or continued executing long past the signal call).

If I'm wrong about this, someone plz correct me.

-genius_at_work
Posted By: DaveC Re: Signal callback support. - 24/06/06 01:21 AM
It would work, but only for /signal -n commands, these are essentially like calling an alias so the callig script halts untill there done, of course being ON SIGNAL event(s) there can be more than one, thus allowing moduals to be loaded.

Your also a slight bit confused on how a /signal with out the -n switch works, if that is done then the signal event is queued up for processing like every other event, it wont run untill the currently executing script be it an alias or event completes.

IMO since signals are user developed code, i would really expect it should be up to the coder to build in this returnback info. I doubt it would take much code honestly, I might give it a go.

edit Ok here it is

Code:
alias signal {
  if (-* !iswm $1) { var %tablename = $+(sreturn.,$1) } | else { var %tablename = $+(sreturn.,$2) }
  hfree -sw %tablename
  signal $1-
  if ((-*r* iswmcs $1) && (!$hget(%tablename,0).item)) { hadd -sm %tablename 1 $3- }
}
alias sreturn {
  if (!$isid) {
    if (!$signal) { echo -a NO $!SIGNAL | return }
    var %tablename = $+(sreturn.,$signal)
    hadd -sm %tablename $calc($hget(%tablename,0).item + 1) $1-
  }
  else {
    var %tablename = $gettok($+(sreturn.,$1),1,32)
    if ($2 isnum 0) { return $hget(%tablename,0).item }
    return $hget(%tablename,$2)
  }
}

Notes:
I custom override the the signal command, this to some people is bad, (im one of them lol) but changing it to _signal would work just as well.
Also becuase i cant override the $signal identifier i instead used $sreturn(<signal>,<N>) as the identifier for drawing out the return values

so its
Code:
on ^*:TEXT:*:?:{
  ;The -r switch is used, so if there is no signal, $nick and $1- will be added to the list as [color:blue]line 1[/color] 
  signal -nr ontext $nick $1-
  ;$sreturn is used to get the lines returned by the ontext signal.
  echo -a $sreturn(ontext,1) $sreturn(ontext,2)
  halt
}
on *:SIGNAL:ontext:{
  ;Add $+(&lt;,$1,&gt;) to the list as the first line, because its the first /sreturn used.
  sreturn $+(&lt;,$1,&gt;)
  ;Add $2- to the list as the second line.
  sreturn $2-
}


correction : line1 only not line1 and 2 becuase there is no logical reason that it would know to place the first parameter to the signal on line 1 and the 2nd and onwards on line2
© mIRC Discussion Forums