@@ -163,6 +163,7 @@ public LuaConsole()
163163 }
164164
165165 private LuaLibraries LuaImp ;
166+ private List < LuaFile > _scriptsToRestart = new ( ) ;
166167
167168 private ConsoleLuaLibrary _consoleLib ;
168169
@@ -198,10 +199,22 @@ private void BranchesMarkersSplit_SplitterMoved(object sender, SplitterEventArgs
198199 Settings . SplitDistance = splitContainer1 . SplitterDistance ;
199200 }
200201
201- public override void Restart ( )
202+ public override void Stop ( )
202203 {
203- List < LuaFile > runningScripts = new ( ) ;
204+ if ( LuaImp is not null && ! LuaImp . IsRebootingCore )
205+ {
206+ _scriptsToRestart = LuaImp . ScriptList . Where ( lf => lf . Enabled ) . ToList ( ) ;
204207
208+ // we don't use _scriptsToRestart here, in case something is somehow partially active
209+ foreach ( var file in LuaImp . ScriptList )
210+ {
211+ file . Stop ( ) ;
212+ }
213+ }
214+ }
215+
216+ public override void Restart ( )
217+ {
205218 ApiContainer apiContainer = ApiManager . RestartLua (
206219 Emulator . ServiceProvider ,
207220 WriteToOutputWindow ,
@@ -215,23 +228,11 @@ public override void Restart()
215228 Game ,
216229 DialogController ) ;
217230
218- // Things we need to do with the existing LuaImp before we can make a new one
219- if ( LuaImp is not null )
231+ if ( LuaImp is not null && LuaImp . IsRebootingCore )
220232 {
221- if ( LuaImp . IsRebootingCore )
222- {
223- // Even if the lua console is self-rebooting from client.reboot_core() we still want to re-inject dependencies
224- LuaImp . Restart ( Emulator . ServiceProvider , Config , apiContainer ) ;
225- return ;
226- }
227-
228- runningScripts = LuaImp . ScriptList . Where ( lf => lf . Enabled ) . ToList ( ) ;
229-
230- // we don't use runningScripts here as the other scripts need to be stopped too
231- foreach ( var file in LuaImp . ScriptList )
232- {
233- file . Stop ( ) ;
234- }
233+ // Even if the lua console is self-rebooting from client.reboot_core() we still want to re-inject dependencies
234+ LuaImp . Restart ( Emulator . ServiceProvider , Config , apiContainer ) ;
235+ return ;
235236 }
236237
237238 _openedFiles = new ( _openedFiles , onChanged : SessionChangedCallback ) ;
@@ -255,7 +256,7 @@ public override void Restart()
255256 . Select ( static f => $ "{ f . Library } .{ f . Name } ")
256257 . ToArray ( ) ) ;
257258
258- foreach ( var file in runningScripts )
259+ foreach ( var file in _scriptsToRestart )
259260 {
260261 EnableLuaFile ( file ) ;
261262 }
0 commit comments