[lyntin-devl] #-loops
Brought to you by:
glasssnake,
willhelm
From: Joshua M. B. <be...@no...> - 2002-07-30 03:13:14
|
In order to fix a bug with #-loops I just added to their functionality. Previously the following: #5 ! would have put "#5 !" into the history manager's history. Following this with a ! would have led to a very quick and painful infinite recursion. I'd rather have things generally not place history commands into the history buffer (and rather expand them before placing things there) in order to avoid just such recursions. engine.handleUserData does much to do this. Since #-digit loops are also implemented there, I decided to implement a fix for this there. So now if you do the following : look #5 ! you will get the following in the historymanager: look #5 {look} I altered the #-digit loops to support enclosing the looped-over command in brackets, otherwise we'd have strange behaviours if you did things like say hi;say planet #5 ! Not having brackets would lead to the following: say hi;say planet #5 say hi;say planet Which would behave differently if you tried to repeate it with a !. Insted the following goes into the history: say hi;say planet #5 {say hi;say planet} Which will loop through both say's 5 times if repeated again wiht !. The implementation of this also required adding in a return value of what was executed to the engine.handleUserData command. It had no return value previously, so this shouldn't cause any major ripples. The implementation for #digit now relies on the return value from the last executed handleUserData in the loop to produce a value to put into the history manager. The bad thing is that the #loop command is very broken if it is used with !-history commands. It will insert history commands directly into the history manager when executed, and if those commands get re-executed with another history command we'll end up with an infinite loop. To be more clear, say grumble #loop 1,5 ! will put say grumble #loop 1,5 ! into the history manager Of course, then, executing ! after this will cause ! to get executed 5 times, which will cause ! to get executed ! to get executed 25 times which will cause ! to get executed 125 times which will cause ! to get executed 625 times .... I think you get the picture here. To fix this I think we need to add on an appropriate recursion check somewhere. I don't think we wan to limit ourselves to just 1 recursion through any part of lyntin, especially since some more sophisticated scripts might rely on recursing through commands/loops/other things quite a few times. Some thought needs to be put in to how to stop this from blowing up in general. I'm about to check in fixes for the new-and-improved #-digit loops. - Josh |