Sfoglia il codice sorgente

Proper error reporting on errors in files loaded by require()

Ivan Safrin 13 anni fa
parent
commit
14634160c4

+ 1 - 1
IDE/Contents/Source/PolycodeTextEditor.cpp

@@ -38,7 +38,7 @@ PolycodeSyntaxHighlighter::PolycodeSyntaxHighlighter(String extension) {
 	separators = String("[ * [ ] { } ; . , : # ( ) \t \n = + - / \\ ' \"").split(" ");
 	separators.push_back(" ");
 	
-	keywords = String("and require true false class self break do end else elseif function if local nil not or repeat return then until while").split(" ");
+	keywords = String("for cast safe_cast and require true false class self break do end else elseif function if local nil not or repeat return then until while").split(" ");
 }
 
 PolycodeSyntaxHighlighter::~PolycodeSyntaxHighlighter() {

+ 10 - 5
Player/Contents/Source/PolycodePlayer.cpp

@@ -143,7 +143,9 @@ static void dumpstack (lua_State *L) {
 			char *buffer = (char*)malloc(progsize+1);
 			memset(buffer, 0, progsize+1);
 			OSBasics::read(buffer, progsize, 1, inFile);
-			luaL_loadbuffer(pState, (const char*)buffer, progsize, fullPath);		
+	
+			PolycodePlayer *player = (PolycodePlayer*)CoreServices::getInstance()->getCore()->getUserPointer();	
+			player->report(pState, luaL_loadbuffer(pState, (const char*)buffer, progsize, fullPath));		
 			//free(buffer);
 			OSBasics::close(inFile);	
 		} else {
@@ -166,7 +168,6 @@ static void dumpstack (lua_State *L) {
 		int depth = 0;		
 		while (lua_getstack(L, depth, &entry)) {
 			lua_getinfo(L, "Sln", &entry);
-			printf(">>>> %s(%d): %s\n", entry.short_src, entry.currentline, entry.name ? entry.name : "?");
 			std::vector<String> bits = String(entry.short_src).split("\"");
 			if(bits.size() > 1) {
 				String fileName = bits[1];
@@ -177,6 +178,7 @@ static void dumpstack (lua_State *L) {
 					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";
 				}
 			}
@@ -260,7 +262,7 @@ static void dumpstack (lua_State *L) {
 					
 			msg = lua_tostring(L, -1);
 			if (msg == NULL) msg = "(error with no message)";
-			Logger::log("status=%d, %s\n", status, msg);
+			Logger::log("status=%d, (%s)\n", status, msg);
 			lua_pop(L, 1);
 			
 			std::vector<String> info = String(msg).split(":");
@@ -271,9 +273,12 @@ static void dumpstack (lua_State *L) {
 			if(info.size() > 2) {
 				event->errorString = info[2];
 				event->lineNumber = atoi(info[1].c_str());
-				event->fileName = player->fullPath; 
+				event->fileName = info[0].replace("string ", "").replace("\"", "").replace("[", "").replace("]", "");
+				
 				trace.lineNumber = event->lineNumber;
 				trace.fileName = event->fileName;
+				
+				printf(">>>> In file: %s on line %d\n", trace.fileName.c_str(), trace.lineNumber);				
 			} else {
 				event->errorString = std::string(msg);
 				event->lineNumber = 0;
@@ -349,7 +354,7 @@ static void dumpstack (lua_State *L) {
 		lua_getfield(L, LUA_GLOBALSINDEX, "require");
 		lua_pushstring(L, "defaults");		
 		lua_call(L, 1, 0);
-		
+				
 		for(int i=0; i < loadedModules.size(); i++) {
 			String moduleName = loadedModules[i];
 #ifdef _WINDOWS