lua: Add Sprite:close() function

This commit is contained in:
David Capello 2018-12-20 09:25:41 -03:00
parent afe843756c
commit 8966f7846f
2 changed files with 17 additions and 1 deletions

View File

@ -10,6 +10,6 @@
// Increment this value if the scripting API is modified between two
// released Aseprite versions.
#define API_VERSION 2
#define API_VERSION 3
#endif

View File

@ -22,6 +22,7 @@
#include "app/commands/params.h"
#include "app/context.h"
#include "app/doc.h"
#include "app/doc_access.h"
#include "app/doc_api.h"
#include "app/file/palette_file.h"
#include "app/script/docobj.h"
@ -174,6 +175,20 @@ int Sprite_saveCopyAs(lua_State* L)
return Sprite_saveAs_base(L, fn);
}
int Sprite_close(lua_State* L)
{
auto sprite = get_docobj<Sprite>(L, 1);
Doc* doc = static_cast<Doc*>(sprite->document());
try {
DocDestroyer destroyer(static_cast<app::Context*>(doc->context()), doc, 500);
destroyer.destroyDocument();
return 0;
}
catch (const LockedDocException& ex) {
return luaL_error(L, "cannot lock document to close it\n%s", ex.what());
}
}
int Sprite_loadPalette(lua_State* L)
{
auto sprite = get_docobj<Sprite>(L, 1);
@ -594,6 +609,7 @@ const luaL_Reg Sprite_methods[] = {
{ "crop", Sprite_crop },
{ "saveAs", Sprite_saveAs },
{ "saveCopyAs", Sprite_saveCopyAs },
{ "close", Sprite_close },
{ "loadPalette", Sprite_loadPalette },
{ "setPalette", Sprite_setPalette },
// Layers