1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
/*************************************************************************/
/* script_language.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "script_language.h"
ScriptLanguage *ScriptServer::_languages[MAX_LANGUAGES];
int ScriptServer::_language_count=0;
bool ScriptServer::scripting_enabled=true;
void Script::_notification( int p_what) {
if (p_what==NOTIFICATION_POSTINITIALIZE) {
if (ScriptDebugger::get_singleton())
ScriptDebugger::get_singleton()->set_break_language(get_language());
}
}
void Script::_bind_methods() {
ObjectTypeDB::bind_method(_MD("can_instance"),&Script::can_instance);
//ObjectTypeDB::bind_method(_MD("instance_create","base_object"),&Script::instance_create);
ObjectTypeDB::bind_method(_MD("instance_has","base_object"),&Script::instance_has);
ObjectTypeDB::bind_method(_MD("has_source_code"),&Script::has_source_code);
ObjectTypeDB::bind_method(_MD("get_source_code"),&Script::get_source_code);
ObjectTypeDB::bind_method(_MD("set_source_code","source"),&Script::set_source_code);
ObjectTypeDB::bind_method(_MD("reload"),&Script::reload);
}
void ScriptServer::set_scripting_enabled(bool p_enabled) {
scripting_enabled=p_enabled;
}
bool ScriptServer::is_scripting_enabled() {
return scripting_enabled;
}
int ScriptServer::get_language_count() {
return _language_count;
}
ScriptLanguage* ScriptServer::get_language(int p_idx) {
ERR_FAIL_INDEX_V(p_idx,_language_count,NULL);
return _languages[p_idx];
}
void ScriptServer::register_language(ScriptLanguage *p_language) {
ERR_FAIL_COND( _language_count >= MAX_LANGUAGES );
_languages[_language_count++]=p_language;
}
Variant ScriptInstance::call(const StringName& p_method,VARIANT_ARG_DECLARE) {
VARIANT_ARGPTRS;
int argc=0;
for(int i=0;i<VARIANT_ARG_MAX;i++) {
if (argptr[i]->get_type()==Variant::NIL)
break;
argc++;
}
Variant::CallError error;
return call(p_method,argptr,argc,error);
}
void ScriptInstance::call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount) {
Variant::CallError ce;
call(p_method,p_args,p_argcount,ce); // script may not support multilevel calls
}
void ScriptInstance::call_multilevel_reversed(const StringName& p_method,const Variant** p_args,int p_argcount) {
Variant::CallError ce;
call(p_method,p_args,p_argcount,ce); // script may not support multilevel calls
}
void ScriptInstance::call_multilevel(const StringName& p_method,VARIANT_ARG_DECLARE) {
VARIANT_ARGPTRS;
int argc=0;
for(int i=0;i<VARIANT_ARG_MAX;i++) {
if (argptr[i]->get_type()==Variant::NIL)
break;
argc++;
}
Variant::CallError error;
call_multilevel(p_method,argptr,argc);
}
ScriptInstance::~ScriptInstance() {
}
void ScriptLanguage::frame() {
}
ScriptDebugger * ScriptDebugger::singleton=NULL;
void ScriptDebugger::set_lines_left(int p_left) {
lines_left=p_left;
}
int ScriptDebugger::get_lines_left() const {
return lines_left;
}
void ScriptDebugger::set_depth(int p_depth) {
depth=p_depth;
}
int ScriptDebugger::get_depth() const {
return depth;
}
void ScriptDebugger::insert_breakpoint(int p_line, const StringName& p_source) {
if (!breakpoints.has(p_line))
breakpoints[p_line]=Set<StringName>();
breakpoints[p_line].insert(p_source);
}
void ScriptDebugger::remove_breakpoint(int p_line, const StringName& p_source) {
if (!breakpoints.has(p_line))
return;
breakpoints[p_line].erase(p_source);
if (breakpoints[p_line].size()==0)
breakpoints.erase(p_line);
}
bool ScriptDebugger::is_breakpoint(int p_line,const StringName& p_source) const {
if (!breakpoints.has(p_line))
return false;
return breakpoints[p_line].has(p_source);
}
bool ScriptDebugger::is_breakpoint_line(int p_line) const {
return breakpoints.has(p_line);
}
String ScriptDebugger::breakpoint_find_source(const String& p_source) const {
return p_source;
}
void ScriptDebugger::clear_breakpoints() {
breakpoints.clear();
}
void ScriptDebugger::idle_poll() {
}
void ScriptDebugger::line_poll() {
}
void ScriptDebugger::set_break_language(ScriptLanguage *p_lang) {
break_lang=p_lang;
}
ScriptLanguage* ScriptDebugger::get_break_language() const{
return break_lang;
}
ScriptDebugger::ScriptDebugger() {
singleton=this;
lines_left=-1;
depth=-1;
break_lang=NULL;
}
bool PlaceHolderScriptInstance::set(const StringName& p_name, const Variant& p_value) {
if (values.has(p_name)) {
values[p_name]=p_value;
return true;
}
return false;
}
bool PlaceHolderScriptInstance::get(const StringName& p_name, Variant &r_ret) const {
if (values.has(p_name)) {
r_ret=values[p_name];
return true;
} return false;
}
void PlaceHolderScriptInstance::get_property_list(List<PropertyInfo> *p_properties) const {
for(const List<PropertyInfo>::Element *E=properties.front();E;E=E->next()) {
p_properties->push_back(E->get());
}
}
void PlaceHolderScriptInstance::update(const List<PropertyInfo> &p_properties,const Map<StringName,Variant>& p_values) {
Set<StringName> new_values;
for(const List<PropertyInfo>::Element *E=p_properties.front();E;E=E->next()) {
StringName n = E->get().name;
new_values.insert(n);
if (!values.has(n) || values[n].get_type()!=E->get().type) {
if (p_values.has(n))
values[n]=p_values[n];
}
}
properties=p_properties;
List<StringName> to_remove;
for(Map<StringName,Variant>::Element *E=values.front();E;E=E->next()) {
if (!new_values.has(E->key()))
to_remove.push_back(E->key());
}
while(to_remove.size()) {
values.erase(to_remove.front()->get());
to_remove.pop_front();
}
if (owner && owner->get_script_instance()==this)
owner->_change_notify();
//change notify
}
PlaceHolderScriptInstance::PlaceHolderScriptInstance(ScriptLanguage *p_language, Ref<Script> p_script,Object *p_owner) {
language=p_language;
script=p_script;
owner=p_owner;
}
PlaceHolderScriptInstance::~PlaceHolderScriptInstance() {
if (script.is_valid()) {
script->_placeholder_erased(this);
}
}
|