mIRC Home    About    Download    Register    News    Help

Print Thread
$submenu double evaluate #269994 03/03/22 10:15 PM
Joined: Jul 2006
Posts: 3,931
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,931
It does not seem to be useful for the $submenu mechanism to re-evaluate the content that is returned by the alias and it does not seem to be forced like in /timer or /scid:

Code
menu menubar {
  double evaluation
  .$submenu($testsm($1))
}
alias testsm {
if ($1 == 1) return item : echo -ag > $!!me
}
Inside a script $!me means plain text "$me", so if someone is using $!me there, they would expect plain text "$me".
If there's no good reason for this behavior, could it be changed? Even if it's been in place for so long, double evaluating is not something you want, it can be exploited etc.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Re: $submenu double evaluate [Re: Wims] #270002 05/03/22 06:25 PM
Joined: Dec 2002
Posts: 5,152
Khaled Offline
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,152
Thanks for your bug report. This is intentional and is by design and cannot be changed. It is the same issue as double-evaluation in many other scripting contexts. Scripters need to be aware of situations where this can happen and need to cater for it.

Re: $submenu double evaluate [Re: Khaled] #270003 05/03/22 09:51 PM
Joined: Jul 2006
Posts: 3,931
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,931
Code
 It is the same issue as double-evaluation in many other scripting contexts

To elaborate on that, there aren't that many double-evaluating scripting context, the one known are listed on wikichip: https://en.wikichip.org/wiki/mirc/msl_injection

/timer, /dde, /scon and /scid include a command, we can understand the scripting engine will be run twice: the double evaluation is unavoidable (switches were requested to prevent that but from the engine's point of view it's normal)

/flash does not take a command, but it includes a text that will be used later, it's less intuitive but ok, there could be a lot of time before a flash occurs after /flash has been executed, so it makes sense to reevaluate if you want to display real time informations.

But the $submenu context, everything happens at the same time as far as the scripter is concerned, so it's not like your real time informations will change much during the scope of $submenu.. besides $ticks and $ticksqpc..!?
It's always possible to use % $+ global variable as a returned value and set that variable afterward to get the desired result but it seems like it's not required at all, I don't think anyone knew about this to begin with, and there don't seem to be real benefit from double evaluating here

I could be wrong but I believe that all double evaluation contexts happen because the scripting engine is being called twice on the string, it's obvious for /timer etc, it's less obvious why it occurs on $submenu, to me, or even the $calc bit.

I suppose this is too old behavior to change anyway, but since double evaluation does not occur except in specific cases, it would be nice to have a note in the help file about these contexts because it's dangerous, I don't know if anyone knew about this one to be honnest, I'll add $submenu to the wikichip page.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel