1 /*************************************************************************/
2 /*  pluginscript_language.h                                              */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md).   */
10 /*                                                                       */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the       */
13 /* "Software"), to deal in the Software without restriction, including   */
14 /* without limitation the rights to use, copy, modify, merge, publish,   */
15 /* distribute, sublicense, and/or sell copies of the Software, and to    */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions:                                             */
18 /*                                                                       */
19 /* The above copyright notice and this permission notice shall be        */
20 /* included in all copies or substantial portions of the Software.       */
21 /*                                                                       */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
29 /*************************************************************************/
30 
31 #ifndef PLUGINSCRIPT_LANGUAGE_H
32 #define PLUGINSCRIPT_LANGUAGE_H
33 
34 // Godot imports
35 #include "core/io/resource_loader.h"
36 #include "core/io/resource_saver.h"
37 #include "core/map.h"
38 #include "core/script_language.h"
39 #include "core/self_list.h"
40 // PluginScript imports
41 #include "pluginscript_loader.h"
42 #include <pluginscript/godot_pluginscript.h>
43 
44 class PluginScript;
45 class PluginScriptInstance;
46 
47 class PluginScriptLanguage : public ScriptLanguage {
48 	friend class PluginScript;
49 	friend class PluginScriptInstance;
50 
51 	Ref<ResourceFormatLoaderPluginScript> _resource_loader;
52 	Ref<ResourceFormatSaverPluginScript> _resource_saver;
53 	const godot_pluginscript_language_desc _desc;
54 	godot_pluginscript_language_data *_data;
55 
56 	Mutex *_lock;
57 	SelfList<PluginScript>::List _script_list;
58 
59 public:
60 	virtual String get_name() const;
61 
get_resource_loader()62 	_FORCE_INLINE_ Ref<ResourceFormatLoaderPluginScript> get_resource_loader() { return _resource_loader; }
get_resource_saver()63 	_FORCE_INLINE_ Ref<ResourceFormatSaverPluginScript> get_resource_saver() { return _resource_saver; }
64 
65 	/* LANGUAGE FUNCTIONS */
66 	virtual void init();
67 	virtual String get_type() const;
68 	virtual String get_extension() const;
69 	virtual Error execute_file(const String &p_path);
70 	virtual void finish();
71 
72 	/* EDITOR FUNCTIONS */
73 	virtual void get_reserved_words(List<String> *p_words) const;
74 	virtual void get_comment_delimiters(List<String> *p_delimiters) const;
75 	virtual void get_string_delimiters(List<String> *p_delimiters) const;
76 	virtual Ref<Script> get_template(const String &p_class_name, const String &p_base_class_name) const;
77 	virtual bool validate(const String &p_script, int &r_line_error, int &r_col_error, String &r_test_error, const String &p_path = "", List<String> *r_functions = NULL, List<ScriptLanguage::Warning> *r_warnings = NULL, Set<int> *r_safe_lines = NULL) const;
78 	virtual Script *create_script() const;
79 	virtual bool has_named_classes() const;
80 	virtual bool supports_builtin_mode() const;
can_inherit_from_file()81 	virtual bool can_inherit_from_file() { return true; }
82 	virtual int find_function(const String &p_function, const String &p_code) const;
83 	virtual String make_function(const String &p_class, const String &p_name, const PoolStringArray &p_args) const;
84 	virtual Error complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptCodeCompletionOption> *r_options, bool &r_force, String &r_call_hint);
85 	virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const;
86 	virtual void add_global_constant(const StringName &p_variable, const Variant &p_value);
87 
88 	/* MULTITHREAD FUNCTIONS */
89 
90 	//some VMs need to be notified of thread creation/exiting to allocate a stack
91 	// void thread_enter() {}
92 	// void thread_exit() {}
93 
94 	/* DEBUGGER FUNCTIONS */
95 
96 	virtual String debug_get_error() const;
97 	virtual int debug_get_stack_level_count() const;
98 	virtual int debug_get_stack_level_line(int p_level) const;
99 	virtual String debug_get_stack_level_function(int p_level) const;
100 	virtual String debug_get_stack_level_source(int p_level) const;
101 	virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
102 	virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
103 	virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1);
104 	virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1);
105 
106 	// virtual Vector<StackInfo> debug_get_current_stack_info() { return Vector<StackInfo>(); }
107 
108 	virtual void reload_all_scripts();
109 	virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload);
110 
111 	/* LOADER FUNCTIONS */
112 
113 	virtual void get_recognized_extensions(List<String> *p_extensions) const;
114 	virtual void get_public_functions(List<MethodInfo> *p_functions) const;
115 	virtual void get_public_constants(List<Pair<String, Variant> > *p_constants) const;
116 
117 	virtual void profiling_start();
118 	virtual void profiling_stop();
119 
120 	virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max);
121 	virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max);
122 
123 	virtual void frame();
124 
125 	void lock();
126 	void unlock();
127 
128 	PluginScriptLanguage(const godot_pluginscript_language_desc *desc);
129 	virtual ~PluginScriptLanguage();
130 };
131 
132 #endif // PLUGINSCRIPT_LANGUAGE_H
133