diff --git a/src/app/script/api_version.h b/src/app/script/api_version.h index 528b761bb..4f1b451f5 100644 --- a/src/app/script/api_version.h +++ b/src/app/script/api_version.h @@ -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 diff --git a/src/app/script/sprite_class.cpp b/src/app/script/sprite_class.cpp index eeff075ce..e51d45921 100644 --- a/src/app/script/sprite_class.cpp +++ b/src/app/script/sprite_class.cpp @@ -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(L, 1); + Doc* doc = static_cast(sprite->document()); + try { + DocDestroyer destroyer(static_cast(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(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