summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/math/expression.cpp28
-rw-r--r--core/math/expression.h1
2 files changed, 29 insertions, 0 deletions
diff --git a/core/math/expression.cpp b/core/math/expression.cpp
index 46f81ce5c3..568893e905 100644
--- a/core/math/expression.cpp
+++ b/core/math/expression.cpp
@@ -98,6 +98,7 @@ const char *Expression::func_name[Expression::FUNC_MAX] = {
"typeof",
"type_exists",
"char",
+ "ord",
"str",
"print",
"printerr",
@@ -164,6 +165,7 @@ int Expression::get_func_argument_count(BuiltinFunc p_func) {
case OBJ_WEAKREF:
case TYPE_OF:
case TEXT_CHAR:
+ case TEXT_ORD:
case TEXT_STR:
case TEXT_PRINT:
case TEXT_PRINTERR:
@@ -676,6 +678,32 @@ void Expression::exec_func(BuiltinFunc p_func, const Variant **p_inputs, Variant
*r_return = String(result);
} break;
+ case TEXT_ORD: {
+
+ if (p_inputs[0]->get_type() != Variant::STRING) {
+
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::STRING;
+
+ return;
+ }
+
+ String str = *p_inputs[0];
+
+ if (str.length() != 1) {
+
+ r_error_str = RTR("Expected a string of length 1 (a character).");
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::STRING;
+
+ return;
+ }
+
+ *r_return = str.get(0);
+
+ } break;
case TEXT_STR: {
String str = *p_inputs[0];
diff --git a/core/math/expression.h b/core/math/expression.h
index 833220592c..aac27276d7 100644
--- a/core/math/expression.h
+++ b/core/math/expression.h
@@ -97,6 +97,7 @@ public:
TYPE_OF,
TYPE_EXISTS,
TEXT_CHAR,
+ TEXT_ORD,
TEXT_STR,
TEXT_PRINT,
TEXT_PRINTERR,