Browse Source

Improved the error message when a misspelled filename is given to love.graphics.newShader (resolves issue #928.)

Alex Szpakowski 11 years ago
parent
commit
3d7a3c2c3c
1 changed files with 14 additions and 0 deletions
  1. 14 0
      src/modules/graphics/opengl/wrap_Graphics.cpp

+ 14 - 0
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -28,6 +28,7 @@
 
 
 #include "scripts/graphics.lua.h"
 #include "scripts/graphics.lua.h"
 #include <cassert>
 #include <cassert>
+#include <cstring>
 
 
 namespace love
 namespace love
 {
 {
@@ -403,6 +404,19 @@ int w_newShader(lua_State *L)
 			lua_call(L, 1, 1);
 			lua_call(L, 1, 1);
 			lua_replace(L, i);
 			lua_replace(L, i);
 		}
 		}
+		else
+		{
+			// Check if the argument looks like a filepath - we want a nicer
+			// error for misspelled filepath arguments.
+			size_t slen = 0;
+			const char *str = lua_tolstring(L, i, &slen);
+			if (slen > 0 && slen < 256 && !strchr(str, '\n'))
+			{
+				const char *ext = strchr(str, '.');
+				if (ext != nullptr && !strchr(ext, ';') && !strchr(ext, ' '))
+					return luaL_error(L, "Could not open file %s. Does not exist.", str);
+			}
+		}
 	}
 	}
 
 
 	bool has_arg1 = lua_isstring(L, 1);
 	bool has_arg1 = lua_isstring(L, 1);