MCPcopy Create free account
hub / github.com/TASEmulators/fceux / FCEU_LuaStop

Function FCEU_LuaStop

src/lua-engine.cpp:6596–6636  ·  view source on GitHub ↗

* Terminates a running Lua script by killing the whole Lua engine. * * Always safe to call, except from within a lua call itself (duh). * */

Source from the content-addressed store, hash-verified

6594 *
6595 */
6596void FCEU_LuaStop() {
6597
6598 if (!CheckLua())
6599 return;
6600
6601 //already killed
6602 if (!L) return;
6603
6604 // Since the script is exiting, we want to prevent an infinite loop.
6605 // CallExitFunction() > HandleCallbackError() > FCEU_LuaStop() > CallExitFunction() ...
6606 if (luaexiterrorcount > 0) {
6607 luaexiterrorcount = luaexiterrorcount - 1;
6608 //execute the user's shutdown callbacks
6609 CallExitFunction();
6610 }
6611
6612 luaexiterrorcount = luaexiterrorcount + 1;
6613
6614 //already killed (after multiple errors)
6615 if (!L) return;
6616
6617 /*info.*/numMemHooks = 0;
6618 for(int i = 0; i < LUAMEMHOOK_COUNT; i++)
6619 CalculateMemHookRegions((LuaMemHookType)i);
6620
6621 //sometimes iup uninitializes com
6622 //MBG TODO - test whether this is really necessary. i dont think it is
6623 #ifdef __WIN_DRIVER__
6624 CoInitialize(0);
6625 #endif
6626
6627 if (info_onstop)
6628 info_onstop(info_uid);
6629
6630 //lua_gc(L,LUA_GCCOLLECT,0);
6631
6632
6633 lua_close(L); // this invokes our garbage collectors for us
6634 L = NULL;
6635 FCEU_LuaOnStop();
6636}
6637
6638/**
6639 * Returns true if there is a Lua script running.

Callers 6

FCEUI_KillFunction · 0.85
HandleCallbackErrorFunction · 0.85
FCEU_LoadLuaCodeFunction · 0.85
DlgLuaScriptDialogFunction · 0.85
DoFCEUExitFunction · 0.85
stopLuaScriptMethod · 0.85

Calls 5

CheckLuaFunction · 0.85
CallExitFunctionFunction · 0.85
CalculateMemHookRegionsFunction · 0.85
lua_closeFunction · 0.85
FCEU_LuaOnStopFunction · 0.85

Tested by

no test coverage detected