mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-01-26 02:49:18 +01:00
Added a new method to Expression so it can be used with multiple threads simultenously.
This commit is contained in:
parent
4b9982d2d9
commit
66c2b12fc0
@ -2209,6 +2209,33 @@ Variant Expression::execute(Array p_inputs, Object *p_base, bool p_show_error) {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Array Expression::execute_arr(Array p_inputs, Object *p_base, bool p_show_error) {
|
||||||
|
Array ret;
|
||||||
|
ret.resize(3);
|
||||||
|
|
||||||
|
ERR_FAIL_COND_V_MSG(error_set, ret, "There was previously a parse error: " + error_str + ".");
|
||||||
|
|
||||||
|
execution_error = false;
|
||||||
|
Variant output;
|
||||||
|
String error_txt;
|
||||||
|
|
||||||
|
bool err = _execute(p_inputs, p_base, root, output, error_txt);
|
||||||
|
|
||||||
|
ret[0] = output;
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
ret[1] = true;
|
||||||
|
ret[2] = error_txt;
|
||||||
|
|
||||||
|
ERR_FAIL_COND_V_MSG(p_show_error, ret, error_str);
|
||||||
|
} else {
|
||||||
|
ret[1] = false;
|
||||||
|
ret[2] = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
bool Expression::has_execute_failed() const {
|
bool Expression::has_execute_failed() const {
|
||||||
return execution_error;
|
return execution_error;
|
||||||
}
|
}
|
||||||
@ -2220,6 +2247,7 @@ String Expression::get_error_text() const {
|
|||||||
void Expression::_bind_methods() {
|
void Expression::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("parse", "expression", "input_names"), &Expression::parse, DEFVAL(Vector<String>()));
|
ClassDB::bind_method(D_METHOD("parse", "expression", "input_names"), &Expression::parse, DEFVAL(Vector<String>()));
|
||||||
ClassDB::bind_method(D_METHOD("execute", "inputs", "base_instance", "show_error"), &Expression::execute, DEFVAL(Array()), DEFVAL(Variant()), DEFVAL(true));
|
ClassDB::bind_method(D_METHOD("execute", "inputs", "base_instance", "show_error"), &Expression::execute, DEFVAL(Array()), DEFVAL(Variant()), DEFVAL(true));
|
||||||
|
ClassDB::bind_method(D_METHOD("execute_arr", "inputs", "base_instance", "show_error"), &Expression::execute_arr, DEFVAL(Array()), DEFVAL(Variant()), DEFVAL(true));
|
||||||
ClassDB::bind_method(D_METHOD("has_execute_failed"), &Expression::has_execute_failed);
|
ClassDB::bind_method(D_METHOD("has_execute_failed"), &Expression::has_execute_failed);
|
||||||
ClassDB::bind_method(D_METHOD("get_error_text"), &Expression::get_error_text);
|
ClassDB::bind_method(D_METHOD("get_error_text"), &Expression::get_error_text);
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,8 @@
|
|||||||
|
|
||||||
#include "core/object/reference.h"
|
#include "core/object/reference.h"
|
||||||
|
|
||||||
|
#include "core/variant/array.h"
|
||||||
|
|
||||||
class Expression : public Reference {
|
class Expression : public Reference {
|
||||||
GDCLASS(Expression, Reference);
|
GDCLASS(Expression, Reference);
|
||||||
|
|
||||||
@ -358,7 +360,10 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Error parse(const String &p_expression, const Vector<String> &p_input_names = Vector<String>());
|
Error parse(const String &p_expression, const Vector<String> &p_input_names = Vector<String>());
|
||||||
|
|
||||||
Variant execute(Array p_inputs, Object *p_base = nullptr, bool p_show_error = true);
|
Variant execute(Array p_inputs, Object *p_base = nullptr, bool p_show_error = true);
|
||||||
|
Array execute_arr(Array p_inputs, Object *p_base = nullptr, bool p_show_error = true);
|
||||||
|
|
||||||
bool has_execute_failed() const;
|
bool has_execute_failed() const;
|
||||||
String get_error_text() const;
|
String get_error_text() const;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<class name="Expression" inherits="Reference" version="4.2">
|
<class name="Expression" inherits="Reference" version="4.3">
|
||||||
<brief_description>
|
<brief_description>
|
||||||
A class that stores an expression you can execute.
|
A class that stores an expression you can execute.
|
||||||
</brief_description>
|
</brief_description>
|
||||||
@ -36,6 +36,15 @@
|
|||||||
If you defined input variables in [method parse], you can specify their values in the inputs array, in the same order.
|
If you defined input variables in [method parse], you can specify their values in the inputs array, in the same order.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="execute_arr">
|
||||||
|
<return type="Array" />
|
||||||
|
<argument index="0" name="inputs" type="Array" default="[ ]" />
|
||||||
|
<argument index="1" name="base_instance" type="Object" default="null" />
|
||||||
|
<argument index="2" name="show_error" type="bool" default="true" />
|
||||||
|
<description>
|
||||||
|
Same as [method execute] except it does not set member variables. ret[0] is the result, ret[1] is a bool telling you whether execute was successful or not, ret[2] is a String contanining the error string if there was any.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="get_error_text" qualifiers="const">
|
<method name="get_error_text" qualifiers="const">
|
||||||
<return type="String" />
|
<return type="String" />
|
||||||
<description>
|
<description>
|
||||||
|
Loading…
Reference in New Issue
Block a user