| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  | // Aseprite
 | 
					
						
							| 
									
										
										
										
											2019-01-04 04:17:10 +08:00
										 |  |  | // Copyright (C) 2018-2019  Igara Studio S.A.
 | 
					
						
							| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  | // Copyright (C) 2001-2018  David Capello
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // This program is distributed under the terms of
 | 
					
						
							|  |  |  | // the End-User License Agreement for Aseprite.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef APP_SCRIPTING_H_INCLUDED
 | 
					
						
							|  |  |  | #define APP_SCRIPTING_H_INCLUDED
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef ENABLE_SCRIPTING
 | 
					
						
							|  |  |  |   #error ENABLE_SCRIPTING must be defined
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 03:10:32 +08:00
										 |  |  | #include "app/color.h"
 | 
					
						
							| 
									
										
										
										
											2018-12-11 03:44:49 +08:00
										 |  |  | #include "app/commands/params.h"
 | 
					
						
							| 
									
										
										
										
											2019-04-19 09:23:33 +08:00
										 |  |  | #include "doc/brush.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-05 03:10:32 +08:00
										 |  |  | #include "doc/frame.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-23 23:56:30 +08:00
										 |  |  | #include "doc/object_ids.h"
 | 
					
						
							| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  | #include "gfx/fwd.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <cstdio>
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							|  |  |  | #include <map>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct lua_State; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-21 11:04:49 +08:00
										 |  |  | namespace base { | 
					
						
							|  |  |  |   class Version; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-04 04:17:10 +08:00
										 |  |  | namespace gfx { | 
					
						
							|  |  |  |   class ColorSpace; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  | namespace doc { | 
					
						
							| 
									
										
										
										
											2018-08-31 07:47:11 +08:00
										 |  |  |   class Cel; | 
					
						
							| 
									
										
										
										
											2018-09-05 03:10:32 +08:00
										 |  |  |   class FrameTag; | 
					
						
							| 
									
										
										
										
											2018-11-21 05:12:43 +08:00
										 |  |  |   class Image; | 
					
						
							| 
									
										
										
										
											2018-09-05 03:10:32 +08:00
										 |  |  |   class Layer; | 
					
						
							| 
									
										
										
										
											2019-02-16 04:19:23 +08:00
										 |  |  |   class Mask; | 
					
						
							| 
									
										
										
										
											2018-09-05 03:10:32 +08:00
										 |  |  |   class Palette; | 
					
						
							| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  |   class Sprite; | 
					
						
							| 
									
										
										
										
											2018-09-05 03:10:32 +08:00
										 |  |  |   class WithUserData; | 
					
						
							| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-23 20:18:59 +08:00
										 |  |  | namespace tools { | 
					
						
							|  |  |  |   class Tool; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  | namespace app { | 
					
						
							| 
									
										
										
										
											2018-11-23 23:56:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  |   class Site; | 
					
						
							| 
									
										
										
										
											2018-11-23 23:56:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-01 01:30:32 +08:00
										 |  |  |   namespace script { | 
					
						
							| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-18 00:14:56 +08:00
										 |  |  |   enum class FileAccessMode { | 
					
						
							|  |  |  |     Execute = 1, | 
					
						
							|  |  |  |     Write = 2, | 
					
						
							|  |  |  |     Read = 4, | 
					
						
							|  |  |  |     Full = 7 | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  |   class EngineDelegate { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     virtual ~EngineDelegate() { } | 
					
						
							|  |  |  |     virtual void onConsolePrint(const char* text) = 0; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   class Engine { | 
					
						
							|  |  |  |   public: | 
					
						
							| 
									
										
										
										
											2018-09-01 01:30:32 +08:00
										 |  |  |     Engine(); | 
					
						
							| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  |     ~Engine(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 02:12:48 +08:00
										 |  |  |     EngineDelegate* delegate() { return m_delegate; } | 
					
						
							| 
									
										
										
										
											2018-09-01 01:30:32 +08:00
										 |  |  |     void setDelegate(EngineDelegate* delegate) { | 
					
						
							|  |  |  |       m_delegate = delegate; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  |     void printLastResult(); | 
					
						
							|  |  |  |     bool evalCode(const std::string& code, | 
					
						
							|  |  |  |                   const std::string& filename = std::string()); | 
					
						
							| 
									
										
										
										
											2018-12-11 03:44:49 +08:00
										 |  |  |     bool evalFile(const std::string& filename, | 
					
						
							|  |  |  |                   const Params& params = Params()); | 
					
						
							| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-15 07:38:27 +08:00
										 |  |  |     void consolePrint(const char* text) { | 
					
						
							|  |  |  |       onConsolePrint(text); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  |   private: | 
					
						
							| 
									
										
										
										
											2018-09-01 01:30:32 +08:00
										 |  |  |     void onConsolePrint(const char* text); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  |     lua_State* L; | 
					
						
							|  |  |  |     EngineDelegate* m_delegate; | 
					
						
							|  |  |  |     bool m_printLastResult; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-07 02:12:48 +08:00
										 |  |  |   class ScopedEngineDelegate { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     ScopedEngineDelegate(Engine* engine, EngineDelegate* delegate) | 
					
						
							|  |  |  |       : m_engine(engine), | 
					
						
							|  |  |  |         m_oldDelegate(engine->delegate()) { | 
					
						
							|  |  |  |       m_engine->setDelegate(delegate); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ~ScopedEngineDelegate() { | 
					
						
							|  |  |  |       m_engine->setDelegate(m_oldDelegate); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   private: | 
					
						
							|  |  |  |     Engine* m_engine; | 
					
						
							|  |  |  |     EngineDelegate* m_oldDelegate; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 05:12:43 +08:00
										 |  |  |   int push_image_iterator_function(lua_State* L, const doc::Image* image, int extraArgIndex); | 
					
						
							| 
									
										
										
										
											2019-04-19 09:23:33 +08:00
										 |  |  |   void push_brush(lua_State* L, const doc::BrushRef& brush); | 
					
						
							| 
									
										
										
										
											2018-09-05 03:10:32 +08:00
										 |  |  |   void push_cel_image(lua_State* L, doc::Cel* cel); | 
					
						
							| 
									
										
										
										
											2018-11-23 23:56:30 +08:00
										 |  |  |   void push_cels(lua_State* L, const doc::ObjectIds& cels); | 
					
						
							|  |  |  |   void push_cels(lua_State* L, doc::Layer* layer); | 
					
						
							|  |  |  |   void push_cels(lua_State* L, doc::Sprite* sprite); | 
					
						
							| 
									
										
										
										
											2019-01-04 04:17:10 +08:00
										 |  |  |   void push_color_space(lua_State* L, const gfx::ColorSpace& cs); | 
					
						
							| 
									
										
										
										
											2019-08-11 01:37:18 +08:00
										 |  |  |   void push_doc_range(lua_State* L, Site& site); | 
					
						
							| 
									
										
										
										
											2019-04-18 10:59:59 +08:00
										 |  |  |   void push_image(lua_State* L, doc::Image* image); | 
					
						
							| 
									
										
										
										
											2018-11-23 23:56:30 +08:00
										 |  |  |   void push_images(lua_State* L, const doc::ObjectIds& images); | 
					
						
							|  |  |  |   void push_layers(lua_State* L, const doc::ObjectIds& layers); | 
					
						
							| 
									
										
										
										
											2019-04-25 06:08:25 +08:00
										 |  |  |   void push_palette(lua_State* L, doc::Palette* palette); | 
					
						
							| 
									
										
										
										
											2018-09-05 03:10:32 +08:00
										 |  |  |   void push_sprite_cel(lua_State* L, doc::Cel* cel); | 
					
						
							|  |  |  |   void push_sprite_frame(lua_State* L, doc::Sprite* sprite, doc::frame_t frame); | 
					
						
							|  |  |  |   void push_sprite_frames(lua_State* L, doc::Sprite* sprite); | 
					
						
							| 
									
										
										
										
											2018-11-23 23:56:30 +08:00
										 |  |  |   void push_sprite_frames(lua_State* L, doc::Sprite* sprite, const std::vector<doc::frame_t>& frames); | 
					
						
							| 
									
										
										
										
											2018-09-05 03:10:32 +08:00
										 |  |  |   void push_sprite_layers(lua_State* L, doc::Sprite* sprite); | 
					
						
							|  |  |  |   void push_sprite_palette(lua_State* L, doc::Sprite* sprite, doc::Palette* palette); | 
					
						
							|  |  |  |   void push_sprite_palettes(lua_State* L, doc::Sprite* sprite); | 
					
						
							|  |  |  |   void push_sprite_selection(lua_State* L, doc::Sprite* sprite); | 
					
						
							|  |  |  |   void push_sprite_slices(lua_State* L, doc::Sprite* sprite); | 
					
						
							|  |  |  |   void push_sprite_tags(lua_State* L, doc::Sprite* sprite); | 
					
						
							| 
									
										
										
										
											2018-09-12 23:55:56 +08:00
										 |  |  |   void push_sprites(lua_State* L); | 
					
						
							| 
									
										
										
										
											2019-03-23 20:18:59 +08:00
										 |  |  |   void push_tool(lua_State* L, tools::Tool* tool); | 
					
						
							| 
									
										
										
										
											2019-04-18 10:59:59 +08:00
										 |  |  |   void push_userdata(lua_State* L, doc::WithUserData* userData); | 
					
						
							| 
									
										
										
										
											2019-04-21 11:04:49 +08:00
										 |  |  |   void push_version(lua_State* L, const base::Version& ver); | 
					
						
							| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   gfx::Point convert_args_into_point(lua_State* L, int index); | 
					
						
							|  |  |  |   gfx::Rect convert_args_into_rect(lua_State* L, int index); | 
					
						
							|  |  |  |   gfx::Size convert_args_into_size(lua_State* L, int index); | 
					
						
							| 
									
										
										
										
											2018-09-05 03:10:32 +08:00
										 |  |  |   app::Color convert_args_into_color(lua_State* L, int index); | 
					
						
							|  |  |  |   doc::color_t convert_args_into_pixel_color(lua_State* L, int index); | 
					
						
							| 
									
										
										
										
											2018-09-11 00:49:41 +08:00
										 |  |  |   doc::Palette* get_palette_from_arg(lua_State* L, int index); | 
					
						
							| 
									
										
										
										
											2018-09-12 05:29:15 +08:00
										 |  |  |   doc::Image* may_get_image_from_arg(lua_State* L, int index); | 
					
						
							| 
									
										
										
										
											2018-09-13 22:53:41 +08:00
										 |  |  |   doc::Image* get_image_from_arg(lua_State* L, int index); | 
					
						
							| 
									
										
										
										
											2018-09-12 23:17:48 +08:00
										 |  |  |   doc::Cel* get_image_cel_from_arg(lua_State* L, int index); | 
					
						
							| 
									
										
										
										
											2018-11-23 23:56:30 +08:00
										 |  |  |   doc::frame_t get_frame_number_from_arg(lua_State* L, int index); | 
					
						
							| 
									
										
										
										
											2019-02-16 04:19:23 +08:00
										 |  |  |   const doc::Mask* get_mask_from_arg(lua_State* L, int index); | 
					
						
							| 
									
										
										
										
											2019-03-23 20:18:59 +08:00
										 |  |  |   tools::Tool* get_tool_from_arg(lua_State* L, int index); | 
					
						
							| 
									
										
										
										
											2019-04-19 09:23:33 +08:00
										 |  |  |   doc::BrushRef get_brush_from_arg(lua_State* L, int index); | 
					
						
							| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-18 10:59:59 +08:00
										 |  |  |   // Used by App.open(), Sprite{ fromFile }, and Image{ fromFile }
 | 
					
						
							|  |  |  |   enum class LoadSpriteFromFileParam { FullAniAsSprite, | 
					
						
							|  |  |  |                                        OneFrameAsImage }; | 
					
						
							|  |  |  |   int load_sprite_from_file(lua_State* L, const char* filename, | 
					
						
							|  |  |  |                             const LoadSpriteFromFileParam param); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-20 22:25:08 +08:00
										 |  |  | } // namespace script
 | 
					
						
							|  |  |  | } // namespace app
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 |