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

Function FCEU_LuaFrameBoundary

src/lua-engine.cpp:6311–6379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6309}
6310
6311void FCEU_LuaFrameBoundary()
6312{
6313 //printf("Lua Frame\n");
6314
6315 // HA!
6316 if (!L || !luaRunning)
6317 return;
6318
6319 // Our function needs calling
6320 lua_settop(L,0);
6321 lua_getfield(L, LUA_REGISTRYINDEX, frameAdvanceThread);
6322 lua_State *thread = lua_tothread(L,1);
6323
6324 // Lua calling C must know that we're busy inside a frame boundary
6325 frameBoundary = TRUE;
6326 frameAdvanceWaiting = FALSE;
6327
6328 numTries = 1000;
6329 int result = lua_resume(thread, 0);
6330
6331 if (result == LUA_YIELD) {
6332 // Okay, we're fine with that.
6333 } else if (result != 0) {
6334 // Done execution by bad causes
6335 FCEU_LuaOnStop();
6336 const char *trace = CallLuaTraceback(L);
6337
6338 lua_pushnil(L);
6339 lua_setfield(L, LUA_REGISTRYINDEX, guiCallbackTable);
6340
6341 char errmsg [1024];
6342 sprintf(errmsg, "%s\n%s", lua_tostring(thread,-1), trace);
6343
6344 // Error?
6345#ifdef __WIN_DRIVER__
6346 //StopSound();//StopSound(); //mbg merge 7/23/08
6347 MessageBox( hAppWnd, errmsg, "Lua run error", MB_OK | MB_ICONSTOP);
6348#else
6349 LuaPrintfToWindowConsole("Lua thread bombed out: %s\n", errmsg);
6350 fprintf(stderr, "Lua thread bombed out: %s\n", errmsg);
6351#endif
6352 } else {
6353 FCEU_LuaOnStop();
6354 //FCEU_DispMessage("Script died of natural causes.\n",0);
6355 // weird sequence of functions calls the above message each time the script starts or stops,
6356 // then this message is overrided by "emu speed" within the same frame, which hides this bug
6357 // uncomment onse solution is found
6358 }
6359
6360 // Past here, the nes actually runs, so any Lua code is called mid-frame. We must
6361 // not do anything too stupid, so let ourselves know.
6362 frameBoundary = FALSE;
6363
6364 if (!frameAdvanceWaiting) {
6365 FCEU_LuaOnStop();
6366 }
6367
6368#ifndef __WIN_DRIVER__

Callers 3

FCEUI_EmulateFunction · 0.85
FCEU_LoadLuaCodeFunction · 0.85

Calls 11

lua_settopFunction · 0.85
lua_getfieldFunction · 0.85
lua_tothreadFunction · 0.85
lua_resumeFunction · 0.85
FCEU_LuaOnStopFunction · 0.85
CallLuaTracebackFunction · 0.85
lua_pushnilFunction · 0.85
lua_setfieldFunction · 0.85
DoFCEUExitFunction · 0.85
LuaPrintfToWindowConsoleFunction · 0.50

Tested by

no test coverage detected