mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Improved the error message when a misspelled filename is given to love.graphics.newShader (resolves issue #928.)
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "scripts/graphics.lua.h"
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user