| 5298 | } |
| 5299 | |
| 5300 | void StopLuaScript(int uid) |
| 5301 | { |
| 5302 | LuaContextInfo* infoPtr = luaContextInfo[uid]; |
| 5303 | if(!infoPtr) |
| 5304 | return; |
| 5305 | |
| 5306 | LuaContextInfo& info = *infoPtr; |
| 5307 | |
| 5308 | if(info.running) |
| 5309 | { |
| 5310 | // if it's currently running then we can't stop it now without crashing |
| 5311 | // so the best we can do is politely request for it to go kill itself |
| 5312 | RequestAbortLuaScript(uid); |
| 5313 | return; |
| 5314 | } |
| 5315 | |
| 5316 | lua_State* L = info.L; |
| 5317 | if(L) |
| 5318 | { |
| 5319 | CallExitFunction(uid); |
| 5320 | |
| 5321 | if(info.onstop) |
| 5322 | { |
| 5323 | info.stopWorrying = true, info.worryCount++, dontworry(info); // clear "busy" status |
| 5324 | info.onstop(uid, !info.crashed); // must happen before closing L and after the exit function, otherwise the final GUI state of the script won't be shown properly or at all |
| 5325 | } |
| 5326 | |
| 5327 | if(info.started) // this check is necessary |
| 5328 | { |
| 5329 | lua_close(L); |
| 5330 | #ifndef USE_INFO_STACK |
| 5331 | luaStateToContextMap.erase(L); |
| 5332 | #endif |
| 5333 | luaStateToUIDMap.erase(L); |
| 5334 | info.L = NULL; |
| 5335 | info.started = false; |
| 5336 | |
| 5337 | info.numMemHooks = 0; |
| 5338 | for(int i = 0; i < LUAMEMHOOK_COUNT; i++) |
| 5339 | CalculateMemHookRegions((LuaMemHookType)i); |
| 5340 | |
| 5341 | #if defined(WIN32) && !defined(WXPORT) |
| 5342 | // remove items |
| 5343 | map<PlatformMenuItem, PlatformMenu>::iterator it = info.menuData.menuItemMap.begin(); |
| 5344 | while(it != info.menuData.menuItemMap.end()) |
| 5345 | { |
| 5346 | HMENU menu = (*it).second; |
| 5347 | UINT menuItem = (*it).first; |
| 5348 | DeleteMenu(menu, menuItem, MF_BYCOMMAND); |
| 5349 | it++; |
| 5350 | } |
| 5351 | info.menuData.menuItemMap.clear(); |
| 5352 | |
| 5353 | // remove submenus |
| 5354 | vector<LuaSubMenuData>::reverse_iterator rit = info.menuData.subMenuData.rbegin(); |
| 5355 | while(rit != info.menuData.subMenuData.rend()) |
| 5356 | { |
| 5357 | HMENU menu = (*rit).menu; |
no test coverage detected