1 /*************************************************************************/
2 /* register_types.cpp */
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 #include "register_types.h"
32
33 #include "core/io/resource_loader.h"
34 #include "core/io/resource_saver.h"
35 #include "core/os/dir_access.h"
36 #include "core/os/os.h"
37 #include "core/project_settings.h"
38 #include "scene/main/scene_tree.h"
39
40 #include "pluginscript_language.h"
41 #include "pluginscript_script.h"
42 #include <pluginscript/godot_pluginscript.h>
43
44 static List<PluginScriptLanguage *> pluginscript_languages;
45
_check_language_desc(const godot_pluginscript_language_desc * desc)46 static Error _check_language_desc(const godot_pluginscript_language_desc *desc) {
47 ERR_FAIL_COND_V(!desc->name || desc->name == String(), ERR_BUG);
48 ERR_FAIL_COND_V(!desc->type || desc->type == String(), ERR_BUG);
49 ERR_FAIL_COND_V(!desc->extension || desc->extension == String(), ERR_BUG);
50 ERR_FAIL_COND_V(!desc->recognized_extensions || !desc->recognized_extensions[0], ERR_BUG);
51 ERR_FAIL_COND_V(!desc->init, ERR_BUG);
52 ERR_FAIL_COND_V(!desc->finish, ERR_BUG);
53
54 // desc->reserved_words is not mandatory
55 // desc->comment_delimiters is not mandatory
56 // desc->string_delimiters is not mandatory
57
58 // desc->get_template_source_code is not mandatory
59 // desc->validate is not mandatory
60
61 // desc->get_template_source_code is not mandatory
62 // desc->validate is not mandatory
63 // desc->find_function is not mandatory
64 // desc->make_function is not mandatory
65 // desc->complete_code is not mandatory
66 // desc->auto_indent_code is not mandatory
67 ERR_FAIL_COND_V(!desc->add_global_constant, ERR_BUG);
68 // desc->debug_get_error is not mandatory
69 // desc->debug_get_stack_level_count is not mandatory
70 // desc->debug_get_stack_level_line is not mandatory
71 // desc->debug_get_stack_level_function is not mandatory
72 // desc->debug_get_stack_level_source is not mandatory
73 // desc->debug_get_stack_level_locals is not mandatory
74 // desc->debug_get_stack_level_members is not mandatory
75 // desc->debug_get_globals is not mandatory
76 // desc->debug_parse_stack_level_expression is not mandatory
77 // desc->profiling_start is not mandatory
78 // desc->profiling_stop is not mandatory
79 // desc->profiling_get_accumulated_data is not mandatory
80 // desc->profiling_get_frame_data is not mandatory
81 // desc->profiling_frame is not mandatory
82
83 ERR_FAIL_COND_V(!desc->script_desc.init, ERR_BUG);
84 ERR_FAIL_COND_V(!desc->script_desc.finish, ERR_BUG);
85
86 ERR_FAIL_COND_V(!desc->script_desc.instance_desc.init, ERR_BUG);
87 ERR_FAIL_COND_V(!desc->script_desc.instance_desc.finish, ERR_BUG);
88 ERR_FAIL_COND_V(!desc->script_desc.instance_desc.set_prop, ERR_BUG);
89 ERR_FAIL_COND_V(!desc->script_desc.instance_desc.get_prop, ERR_BUG);
90 ERR_FAIL_COND_V(!desc->script_desc.instance_desc.call_method, ERR_BUG);
91 ERR_FAIL_COND_V(!desc->script_desc.instance_desc.notification, ERR_BUG);
92 // desc->script_desc.instance_desc.refcount_incremented is not mandatory
93 // desc->script_desc.instance_desc.refcount_decremented is not mandatory
94 return OK;
95 }
96
godot_pluginscript_register_language(const godot_pluginscript_language_desc * language_desc)97 void GDAPI godot_pluginscript_register_language(const godot_pluginscript_language_desc *language_desc) {
98 Error ret = _check_language_desc(language_desc);
99 if (ret) {
100 ERR_FAIL();
101 }
102 PluginScriptLanguage *language = memnew(PluginScriptLanguage(language_desc));
103 ScriptServer::register_language(language);
104 ResourceLoader::add_resource_format_loader(language->get_resource_loader());
105 ResourceSaver::add_resource_format_saver(language->get_resource_saver());
106 pluginscript_languages.push_back(language);
107 }
108
register_pluginscript_types()109 void register_pluginscript_types() {
110 ClassDB::register_class<PluginScript>();
111 }
112
unregister_pluginscript_types()113 void unregister_pluginscript_types() {
114 for (List<PluginScriptLanguage *>::Element *e = pluginscript_languages.front(); e; e = e->next()) {
115 PluginScriptLanguage *language = e->get();
116 ScriptServer::unregister_language(language);
117 ResourceLoader::remove_resource_format_loader(language->get_resource_loader());
118 ResourceSaver::remove_resource_format_saver(language->get_resource_saver());
119 memdelete(language);
120 }
121 }
122