@@ -1157,7 +1157,7 @@ bool Expression::_compile_expression() {
1157
1157
return false ;
1158
1158
}
1159
1159
1160
- bool Expression::_execute (const Array &p_inputs, Object *p_instance, Expression::ENode *p_node, Variant &r_ret, String &r_error_str) {
1160
+ bool Expression::_execute (const Array &p_inputs, Object *p_instance, Expression::ENode *p_node, Variant &r_ret, bool p_const_calls_only, String &r_error_str) {
1161
1161
switch (p_node->type ) {
1162
1162
case Expression::ENode::TYPE_INPUT: {
1163
1163
const Expression::InputNode *in = static_cast <const Expression::InputNode *>(p_node);
@@ -1183,15 +1183,15 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
1183
1183
const Expression::OperatorNode *op = static_cast <const Expression::OperatorNode *>(p_node);
1184
1184
1185
1185
Variant a;
1186
- bool ret = _execute (p_inputs, p_instance, op->nodes [0 ], a, r_error_str);
1186
+ bool ret = _execute (p_inputs, p_instance, op->nodes [0 ], a, p_const_calls_only, r_error_str);
1187
1187
if (ret) {
1188
1188
return true ;
1189
1189
}
1190
1190
1191
1191
Variant b;
1192
1192
1193
1193
if (op->nodes [1 ]) {
1194
- ret = _execute (p_inputs, p_instance, op->nodes [1 ], b, r_error_str);
1194
+ ret = _execute (p_inputs, p_instance, op->nodes [1 ], b, p_const_calls_only, r_error_str);
1195
1195
if (ret) {
1196
1196
return true ;
1197
1197
}
@@ -1209,14 +1209,14 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
1209
1209
const Expression::IndexNode *index = static_cast <const Expression::IndexNode *>(p_node);
1210
1210
1211
1211
Variant base;
1212
- bool ret = _execute (p_inputs, p_instance, index ->base , base, r_error_str);
1212
+ bool ret = _execute (p_inputs, p_instance, index ->base , base, p_const_calls_only, r_error_str);
1213
1213
if (ret) {
1214
1214
return true ;
1215
1215
}
1216
1216
1217
1217
Variant idx;
1218
1218
1219
- ret = _execute (p_inputs, p_instance, index ->index , idx, r_error_str);
1219
+ ret = _execute (p_inputs, p_instance, index ->index , idx, p_const_calls_only, r_error_str);
1220
1220
if (ret) {
1221
1221
return true ;
1222
1222
}
@@ -1233,7 +1233,7 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
1233
1233
const Expression::NamedIndexNode *index = static_cast <const Expression::NamedIndexNode *>(p_node);
1234
1234
1235
1235
Variant base;
1236
- bool ret = _execute (p_inputs, p_instance, index ->base , base, r_error_str);
1236
+ bool ret = _execute (p_inputs, p_instance, index ->base , base, p_const_calls_only, r_error_str);
1237
1237
if (ret) {
1238
1238
return true ;
1239
1239
}
@@ -1253,7 +1253,7 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
1253
1253
arr.resize (array->array .size ());
1254
1254
for (int i = 0 ; i < array->array .size (); i++) {
1255
1255
Variant value;
1256
- bool ret = _execute (p_inputs, p_instance, array->array [i], value, r_error_str);
1256
+ bool ret = _execute (p_inputs, p_instance, array->array [i], value, p_const_calls_only, r_error_str);
1257
1257
1258
1258
if (ret) {
1259
1259
return true ;
@@ -1270,14 +1270,14 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
1270
1270
Dictionary d;
1271
1271
for (int i = 0 ; i < dictionary->dict .size (); i += 2 ) {
1272
1272
Variant key;
1273
- bool ret = _execute (p_inputs, p_instance, dictionary->dict [i + 0 ], key, r_error_str);
1273
+ bool ret = _execute (p_inputs, p_instance, dictionary->dict [i + 0 ], key, p_const_calls_only, r_error_str);
1274
1274
1275
1275
if (ret) {
1276
1276
return true ;
1277
1277
}
1278
1278
1279
1279
Variant value;
1280
- ret = _execute (p_inputs, p_instance, dictionary->dict [i + 1 ], value, r_error_str);
1280
+ ret = _execute (p_inputs, p_instance, dictionary->dict [i + 1 ], value, p_const_calls_only, r_error_str);
1281
1281
if (ret) {
1282
1282
return true ;
1283
1283
}
@@ -1297,7 +1297,7 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
1297
1297
1298
1298
for (int i = 0 ; i < constructor->arguments .size (); i++) {
1299
1299
Variant value;
1300
- bool ret = _execute (p_inputs, p_instance, constructor->arguments [i], value, r_error_str);
1300
+ bool ret = _execute (p_inputs, p_instance, constructor->arguments [i], value, p_const_calls_only, r_error_str);
1301
1301
1302
1302
if (ret) {
1303
1303
return true ;
@@ -1325,7 +1325,7 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
1325
1325
1326
1326
for (int i = 0 ; i < bifunc->arguments .size (); i++) {
1327
1327
Variant value;
1328
- bool ret = _execute (p_inputs, p_instance, bifunc->arguments [i], value, r_error_str);
1328
+ bool ret = _execute (p_inputs, p_instance, bifunc->arguments [i], value, p_const_calls_only, r_error_str);
1329
1329
if (ret) {
1330
1330
return true ;
1331
1331
}
@@ -1346,7 +1346,7 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
1346
1346
const Expression::CallNode *call = static_cast <const Expression::CallNode *>(p_node);
1347
1347
1348
1348
Variant base;
1349
- bool ret = _execute (p_inputs, p_instance, call->base , base, r_error_str);
1349
+ bool ret = _execute (p_inputs, p_instance, call->base , base, p_const_calls_only, r_error_str);
1350
1350
1351
1351
if (ret) {
1352
1352
return true ;
@@ -1359,7 +1359,7 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
1359
1359
1360
1360
for (int i = 0 ; i < call->arguments .size (); i++) {
1361
1361
Variant value;
1362
- ret = _execute (p_inputs, p_instance, call->arguments [i], value, r_error_str);
1362
+ ret = _execute (p_inputs, p_instance, call->arguments [i], value, p_const_calls_only, r_error_str);
1363
1363
1364
1364
if (ret) {
1365
1365
return true ;
@@ -1369,7 +1369,11 @@ bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression:
1369
1369
}
1370
1370
1371
1371
Callable::CallError ce;
1372
- base.call (call->method , (const Variant **)argp.ptr (), argp.size (), r_ret, ce);
1372
+ if (p_const_calls_only) {
1373
+ base.call_const (call->method , (const Variant **)argp.ptr (), argp.size (), r_ret, ce);
1374
+ } else {
1375
+ base.call (call->method , (const Variant **)argp.ptr (), argp.size (), r_ret, ce);
1376
+ }
1373
1377
1374
1378
if (ce.error != Callable::CallError::CALL_OK) {
1375
1379
r_error_str = vformat (RTR (" On call to '%s':" ), String (call->method ));
@@ -1408,13 +1412,13 @@ Error Expression::parse(const String &p_expression, const Vector<String> &p_inpu
1408
1412
return OK;
1409
1413
}
1410
1414
1411
- Variant Expression::execute (Array p_inputs, Object *p_base, bool p_show_error) {
1415
+ Variant Expression::execute (Array p_inputs, Object *p_base, bool p_show_error, bool p_const_calls_only ) {
1412
1416
ERR_FAIL_COND_V_MSG (error_set, Variant (), " There was previously a parse error: " + error_str + " ." );
1413
1417
1414
1418
execution_error = false ;
1415
1419
Variant output;
1416
1420
String error_txt;
1417
- bool err = _execute (p_inputs, p_base, root, output, error_txt);
1421
+ bool err = _execute (p_inputs, p_base, root, output, p_const_calls_only, error_txt);
1418
1422
if (err) {
1419
1423
execution_error = true ;
1420
1424
error_str = error_txt;
@@ -1434,7 +1438,7 @@ String Expression::get_error_text() const {
1434
1438
1435
1439
void Expression::_bind_methods () {
1436
1440
ClassDB::bind_method (D_METHOD (" parse" , " expression" , " input_names" ), &Expression::parse, DEFVAL (Vector<String>()));
1437
- ClassDB::bind_method (D_METHOD (" execute" , " inputs" , " base_instance" , " show_error" ), &Expression::execute, DEFVAL (Array ()), DEFVAL (Variant ()), DEFVAL (true ));
1441
+ ClassDB::bind_method (D_METHOD (" execute" , " inputs" , " base_instance" , " show_error" , " const_calls_only " ), &Expression::execute, DEFVAL (Array ()), DEFVAL (Variant ()), DEFVAL (true ), DEFVAL ( false ));
1438
1442
ClassDB::bind_method (D_METHOD (" has_execute_failed" ), &Expression::has_execute_failed);
1439
1443
ClassDB::bind_method (D_METHOD (" get_error_text" ), &Expression::get_error_text);
1440
1444
}
0 commit comments