mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Improved the error message when nil is passed as the first argument to love.image.newImageData (resolves issue #1205).
This commit is contained in:
@@ -218,6 +218,11 @@ FileData *luax_getfiledata(lua_State *L, int idx)
|
||||
return data;
|
||||
}
|
||||
|
||||
bool luax_cangetfiledata(lua_State *L, int idx)
|
||||
{
|
||||
return lua_isstring(L, idx) || luax_istype(L, idx, FILESYSTEM_FILE_ID) || luax_istype(L, idx, FILESYSTEM_FILE_DATA_ID);
|
||||
}
|
||||
|
||||
int w_newFileData(lua_State *L)
|
||||
{
|
||||
// Single argument: treat as filepath or File.
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace filesystem
|
||||
* May trigger a Lua error.
|
||||
**/
|
||||
FileData *luax_getfiledata(lua_State *L, int idx);
|
||||
bool luax_cangetfiledata(lua_State *L, int idx);
|
||||
File *luax_getfile(lua_State *L, int idx);
|
||||
|
||||
bool hack_setupWriteDirectory();
|
||||
|
||||
@@ -68,19 +68,24 @@ int w_newImageData(lua_State *L)
|
||||
t->release();
|
||||
return 1;
|
||||
}
|
||||
else if (filesystem::luax_cangetfiledata(L, 1)) // Case 2: File(Data).
|
||||
{
|
||||
filesystem::FileData *data = love::filesystem::luax_getfiledata(L, 1);
|
||||
|
||||
// Case 2: File(Data).
|
||||
love::filesystem::FileData *data = love::filesystem::luax_getfiledata(L, 1);
|
||||
ImageData *t = nullptr;
|
||||
luax_catchexcept(L,
|
||||
[&]() { t = instance()->newImageData(data); },
|
||||
[&](bool) { data->release(); }
|
||||
);
|
||||
|
||||
ImageData *t = nullptr;
|
||||
luax_catchexcept(L,
|
||||
[&]() { t = instance()->newImageData(data); },
|
||||
[&](bool) { data->release(); }
|
||||
);
|
||||
|
||||
luax_pushtype(L, IMAGE_IMAGE_DATA_ID, t);
|
||||
t->release();
|
||||
return 1;
|
||||
luax_pushtype(L, IMAGE_IMAGE_DATA_ID, t);
|
||||
t->release();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return luax_typerror(L, 1, "value");
|
||||
}
|
||||
}
|
||||
|
||||
int w_newCompressedData(lua_State *L)
|
||||
|
||||
Reference in New Issue
Block a user