Esempio n. 1
0
	static int debugPrint(lua_State *L)
	{
		const char *msg = lua_tostring(L, 1);
		PolycodeDebugEvent *event = new PolycodeDebugEvent();			
		if(msg)
			event->errorString = string(msg);
		else
			event->errorString = string("<invalid string>");
		
		Logger::log(">> %s\n", event->errorString.c_str());
		PolycodePlayer *player = (PolycodePlayer*)CoreServices::getInstance()->getCore()->getUserPointer();
		player->dispatchEvent(event, PolycodeDebugEvent::EVENT_PRINT);
		return 0;
	}	
Esempio n. 2
0
	static int customError(lua_State *L) {
		
		
		PolycodePlayer *player = (PolycodePlayer*)CoreServices::getInstance()->getCore()->getUserPointer();		
		player->crashed = true;
		
		std::vector<BackTraceEntry> backTrace;
		lua_Debug entry;
		int depth = 0;		
		while (lua_getstack(L, depth, &entry)) {
			lua_getinfo(L, "Sln", &entry);
			std::vector<String> bits = String(entry.short_src).split("\"");
			if(bits.size() > 1) {
				String fileName = bits[1];
				if(fileName != "class.lua") {
					
					BackTraceEntry trace;
					trace.lineNumber = entry.currentline;
					trace.fileName = fileName;
					backTrace.push_back(trace);
					
					printf(">>>> In file: %s on line %d\n", fileName.c_str(), trace.lineNumber);
					//backTrace += "In file: " + fileName + " on line " + String::IntToString(entry.currentline)+"\n";
				}
			}
			depth++;
		}

		// horrible hack to determine the filenames of things
		bool stringThatIsTheMainFileSet = false;
		String stringThatIsTheMainFile;
		
		if(backTrace.size() == 0) {
					
					BackTraceEntry trace;
					trace.lineNumber = 0;
					trace.fileName = player->fullPath;
					backTrace.push_back(trace);
		
		} else {
			stringThatIsTheMainFileSet = true;
			stringThatIsTheMainFile = backTrace[backTrace.size()-1].fileName;
			backTrace[backTrace.size()-1].fileName = player->fullPath;
		}
		
		if(stringThatIsTheMainFileSet) {
			for(int i=0; i < backTrace.size(); i++) {
				if(backTrace[i].fileName == stringThatIsTheMainFile) {
					backTrace[i].fileName = player->fullPath;
				}
			}
		}
		
		const char *msg = lua_tostring(L, -1);		
		if (msg == NULL) msg = "(error with no message)";
		lua_pop(L, 1);
		
		String errorString;
		std::vector<String> info = String(msg).split(":");
			
		if(info.size() > 2) {
			errorString = info[2];
		} else {
			errorString = msg;
		}
						
		PolycodeDebugEvent *event = new PolycodeDebugEvent();			
		event->errorString = errorString;
		event->backTrace = backTrace;		
		event->fileName = backTrace[0].fileName;
		event->lineNumber = backTrace[0].lineNumber;

		player->dispatchEvent(event, PolycodeDebugEvent::EVENT_ERROR);
				
		return 0;
	}