void LuaError(struct lua_State* L, char* format, ...) { int val; Messagebox_active = true; gr_activate(0); /* va_start(args, format); vsprintf(AssertText1,format,args); va_end(args); */ //filename = strrchr(filename, '\\')+1; //sprintf(AssertText2,"LuaError: %s\r\nFile: %s\r\nLine: %d\r\n", AssertText1, filename, line ); dumpBuffer.Clear(); //WMC - if format is set to NULL, assume this is acting as an //error handler for Lua. if (format == NULL) { dumpBuffer.Printf("LUA ERROR: %s", lua_tostring(L, -1)); lua_pop(L, -1); } else { va_list args; va_start(args, format); vsprintf(AssertText1, format, args); dumpBuffer.Printf(AssertText1); va_end(args); } dumpBuffer.Printf("\r\n"); dumpBuffer.Printf("\r\n"); //WMC - This is virtually worthless. /* dumpBuffer.Printf(Separator); dumpBuffer.Printf( "LUA Debug:" ); dumpBuffer.Printf( "\r\n" ); dumpBuffer.Printf(Separator); lua_Debug ar; if(lua_getstack(L, 0, &ar)) { lua_getinfo(L, "nSlu", &ar); LuaDebugPrint(ar); } else { dumpBuffer.Printf("(No stack debug info)\r\n"); } */ // TEST CODE dumpBuffer.Printf(Separator); dumpBuffer.Printf("ADE Debug:"); dumpBuffer.Printf("\r\n"); dumpBuffer.Printf(Separator); LuaDebugPrint(Ade_debug_info); dumpBuffer.Printf(Separator); dumpBuffer.Printf("\r\n"); dumpBuffer.Printf("\r\n"); AssertText2[0] = '\0'; dumpBuffer.Printf(Separator); dumpBuffer.Printf("LUA Stack:\r\n"); int i; for (i = 0; i < 4; i++) { if (debug_stack[i][0] != '\0') dumpBuffer.Printf("\t%s\r\n", debug_stack[i]); } dumpBuffer.Printf(Separator); ade_stackdump(L, AssertText2); dumpBuffer.Printf(AssertText2); dumpBuffer.Printf("\r\n"); dumpBuffer.Printf(Separator); dump_text_to_clipboard(dumpBuffer.buffer); dumpBuffer.Printf("\r\n[ This info is in the clipboard so you can paste it somewhere now ]\r\n"); dumpBuffer.Printf("\r\n\r\nUse Yes to break into Debugger, No to continue.\r\nand Cancel to Quit"); val = MessageBox(NULL, dumpBuffer.buffer, "Error!", flags | MB_YESNOCANCEL); if (val == IDCANCEL) { exit(1); } else if (val == IDYES) { Int3(); } gr_activate(1); Messagebox_active = false; }
void LuaError(struct lua_State *L, char *format, ...) { int val; Messagebox_active = true; gr_activate(0); dumpBuffer.Clear(); //WMC - if format is set to NULL, assume this is acting as an //error handler for Lua. if(format == NULL) { dumpBuffer.Printf("LUA ERROR: %s", lua_tostring(L, -1)); lua_pop(L, -1); } else { va_list args; memset(AssertText1, 0, sizeof(AssertText1)); memset(AssertText2, 0, sizeof(AssertText2)); va_start(args, format); vsnprintf(AssertText1, sizeof(AssertText1)-1, format,args); va_end(args); dumpBuffer.Printf(AssertText1); } dumpBuffer.Printf( "\r\n" ); dumpBuffer.Printf( "\r\n" ); //WMC - This is virtually worthless. /* dumpBuffer.Printf(Separator); dumpBuffer.Printf( "LUA Debug:" ); dumpBuffer.Printf( "\r\n" ); dumpBuffer.Printf(Separator); lua_Debug ar; if(lua_getstack(L, 0, &ar)) { lua_getinfo(L, "nSlu", &ar); LuaDebugPrint(ar); } else { dumpBuffer.Printf("(No stack debug info)\r\n"); } */ // TEST CODE dumpBuffer.Printf(Separator); dumpBuffer.Printf( "ADE Debug:" ); dumpBuffer.Printf( "\r\n" ); dumpBuffer.Printf(Separator); LuaDebugPrint(Ade_debug_info); dumpBuffer.Printf(Separator); dumpBuffer.Printf( "\r\n" ); dumpBuffer.Printf( "\r\n" ); AssertText2[0] = '\0'; dumpBuffer.Printf(Separator); // Get the stack via the debug.traceback() function lua_getglobal(L, LUA_DBLIBNAME); if (!lua_isnil(L, -1)) { dumpBuffer.Printf( "\r\n" ); lua_getfield(L, -1, "traceback"); lua_remove(L, -2); if (lua_pcall(L, 0, 1, 0) != 0) dumpBuffer.Printf("Error while retrieving stack: %s", lua_tostring(L, -1)); else dumpBuffer.Printf(lua_tostring(L, -1)); lua_pop(L, 1); } else { // If the debug library is nil then fall back to the default debug stack dumpBuffer.Printf("LUA Stack:\r\n"); int i; for (i = 0; i < 4; i++) { if (debug_stack[i][0] != '\0') dumpBuffer.Printf("\t%s\r\n", debug_stack[i]); } } dumpBuffer.Printf( "\r\n" ); dumpBuffer.Printf(Separator); ade_stackdump(L, AssertText2); dumpBuffer.Printf( AssertText2 ); dumpBuffer.Printf( "\r\n" ); dumpBuffer.Printf(Separator); dump_text_to_clipboard(dumpBuffer.buffer); // truncate text dumpBuffer.TruncateLines(Messagebox_lines); dumpBuffer.Printf( "\r\n[ This info is in the clipboard so you can paste it somewhere now ]\r\n" ); dumpBuffer.Printf( "\r\n\r\nUse Yes to break into Debugger, No to continue.\r\nand Cancel to Quit"); val = MessageBox(NULL, dumpBuffer.buffer, "Error!", flags|MB_YESNOCANCEL ); if (val == IDCANCEL ) { exit(1); } else if(val == IDYES) { Int3(); } gr_activate(1); Messagebox_active = false; }
void LuaError(lua_State * L, const char * format, ...) { SCP_stringstream msgStream; //WMC - if format is set to NULL, assume this is acting as an //error handler for Lua. if (format == NULL) { msgStream << "LUA ERROR: " << lua_tostring(L, -1); lua_pop(L, -1); } else { SCP_string formatText; va_list args; va_start(args, format); vsprintf(formatText, format, args); va_end(args); msgStream << formatText; } msgStream << "\n"; msgStream << "\n"; msgStream << Separator; msgStream << "ADE Debug:"; msgStream << "\n"; msgStream << Separator; LuaDebugPrint(msgStream, Ade_debug_info); msgStream << Separator; msgStream << "\n"; msgStream << "\n"; msgStream << Separator; // Get the stack via the debug.traceback() function lua_getglobal(L, LUA_DBLIBNAME); if (!lua_isnil(L, -1)) { msgStream << "\n"; lua_getfield(L, -1, "traceback"); lua_remove(L, -2); if (lua_pcall(L, 0, 1, 0) != 0) msgStream << "Error while retrieving stack: " << lua_tostring(L, -1); else msgStream << lua_tostring(L, -1); lua_pop(L, 1); } msgStream << "\n"; msgStream << Separator; char stackText[1024]; stackText[0] = '\0'; scripting::ade_stackdump(L, stackText); msgStream << stackText; msgStream << "\n"; msgStream << Separator; mprintf(("Lua Error: %s\n", msgStream.str().c_str())); if (Cmdline_noninteractive) { exit(1); return; } if (running_unittests) { throw LuaErrorException(msgStream.str()); } set_clipboard_text(msgStream.str().c_str()); // truncate text auto truncatedText = truncateLines(msgStream, Messagebox_lines); SCP_stringstream boxTextStream; boxTextStream << truncatedText << "\n"; boxTextStream << "\n[ This info is in the clipboard so you can paste it somewhere now ]\n"; auto boxText = boxTextStream.str(); const SDL_MessageBoxButtonData buttons[] = { { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 2, "Exit" }, { SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 1, "Continue" }, { /* .flags, .buttonid, .text */ 0, 0, "Debug" }, }; SDL_MessageBoxData boxData; memset(&boxData, 0, sizeof(boxData)); boxData.buttons = buttons; boxData.numbuttons = 3; boxData.colorScheme = nullptr; boxData.flags = SDL_MESSAGEBOX_ERROR; boxData.message = boxText.c_str(); boxData.title = "Error!"; boxData.window = os::getSDLMainWindow(); gr_activate(0); int buttonId; if (SDL_ShowMessageBox(&boxData, &buttonId) < 0) { // Call failed buttonId = 1; // No action } switch (buttonId) { case 2: exit(1); case 0: Int3(); break; default: break; } gr_activate(1); }