From 3d7a3c2c3c407d3a3fe9378b8cb97c9557d2b64e Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 18 Sep 2014 22:36:22 -0300 Subject: [PATCH] Improved the error message when a misspelled filename is given to love.graphics.newShader (resolves issue #928.) --- src/modules/graphics/opengl/wrap_Graphics.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 8ae1b1b7e..90f865d2a 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -28,6 +28,7 @@ #include "scripts/graphics.lua.h" #include +#include namespace love { @@ -403,6 +404,19 @@ int w_newShader(lua_State *L) lua_call(L, 1, 1); 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);