GDScript: Use "is" keyword for type checking.
Replaces the `extends` keyword with `is` in the context of testing for type compatibility. `extends` is still used for declaring class inheritance. Example: ```gdscript extends Node2D func _input(ev): if ev is InputEventKey: print("yay, key event") ```
This commit is contained in:
parent
f89641907f
commit
015d36d18b
7 changed files with 12 additions and 8 deletions
|
@ -1014,7 +1014,7 @@ int GDCompiler::_parse_expression(CodeGen &codegen, const GDParser::Node *p_expr
|
|||
}
|
||||
|
||||
} break;
|
||||
case GDParser::OperatorNode::OP_EXTENDS: {
|
||||
case GDParser::OperatorNode::OP_IS: {
|
||||
|
||||
ERR_FAIL_COND_V(on->arguments.size() != 2, false);
|
||||
|
||||
|
|
|
@ -358,12 +358,12 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
|
|||
|
||||
if (a->get_type() != Variant::OBJECT || a->operator Object *() == NULL) {
|
||||
|
||||
err_text = "Left operand of 'extends' is not an instance of anything.";
|
||||
err_text = "Left operand of 'is' is not an instance of anything.";
|
||||
break;
|
||||
}
|
||||
if (b->get_type() != Variant::OBJECT || b->operator Object *() == NULL) {
|
||||
|
||||
err_text = "Right operand of 'extends' is not a class.";
|
||||
err_text = "Right operand of 'is' is not a class.";
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
@ -401,7 +401,7 @@ Variant GDFunction::call(GDInstance *p_instance, const Variant **p_args, int p_a
|
|||
|
||||
if (!nc) {
|
||||
|
||||
err_text = "Right operand of 'extends' is not a class (type: '" + obj_B->get_class() + "').";
|
||||
err_text = "Right operand of 'is' is not a class (type: '" + obj_B->get_class() + "').";
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -1077,7 +1077,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool
|
|||
case GDTokenizer::TK_OP_BIT_AND: op = OperatorNode::OP_BIT_AND; break;
|
||||
case GDTokenizer::TK_OP_BIT_OR: op = OperatorNode::OP_BIT_OR; break;
|
||||
case GDTokenizer::TK_OP_BIT_XOR: op = OperatorNode::OP_BIT_XOR; break;
|
||||
case GDTokenizer::TK_PR_EXTENDS: op = OperatorNode::OP_EXTENDS; break;
|
||||
case GDTokenizer::TK_PR_IS: op = OperatorNode::OP_IS; break;
|
||||
case GDTokenizer::TK_CF_IF: op = OperatorNode::OP_TERNARY_IF; break;
|
||||
case GDTokenizer::TK_CF_ELSE: op = OperatorNode::OP_TERNARY_ELSE; break;
|
||||
default: valid = false; break;
|
||||
|
@ -1117,7 +1117,7 @@ GDParser::Node *GDParser::_parse_expression(Node *p_parent, bool p_static, bool
|
|||
|
||||
switch (expression[i].op) {
|
||||
|
||||
case OperatorNode::OP_EXTENDS:
|
||||
case OperatorNode::OP_IS:
|
||||
priority = -1;
|
||||
break; //before anything
|
||||
|
||||
|
@ -1420,7 +1420,7 @@ GDParser::Node *GDParser::_reduce_expression(Node *p_node, bool p_to_const) {
|
|||
}
|
||||
}
|
||||
|
||||
if (op->op == OperatorNode::OP_EXTENDS) {
|
||||
if (op->op == OperatorNode::OP_IS) {
|
||||
//nothing much
|
||||
return op;
|
||||
}
|
||||
|
|
|
@ -216,7 +216,7 @@ public:
|
|||
OP_CALL,
|
||||
OP_PARENT_CALL,
|
||||
OP_YIELD,
|
||||
OP_EXTENDS,
|
||||
OP_IS,
|
||||
//indexing operator
|
||||
OP_INDEX,
|
||||
OP_INDEX_NAMED,
|
||||
|
|
|
@ -1812,6 +1812,7 @@ void GDScriptLanguage::get_reserved_words(List<String> *p_words) const {
|
|||
"breakpoint",
|
||||
"class",
|
||||
"extends",
|
||||
"is",
|
||||
"func",
|
||||
"preload",
|
||||
"setget",
|
||||
|
|
|
@ -90,6 +90,7 @@ const char *GDTokenizer::token_names[TK_MAX] = {
|
|||
"func",
|
||||
"class",
|
||||
"extends",
|
||||
"is",
|
||||
"onready",
|
||||
"tool",
|
||||
"static",
|
||||
|
@ -864,6 +865,7 @@ void GDTokenizerText::_advance() {
|
|||
{ TK_PR_FUNCTION, "func" },
|
||||
{ TK_PR_CLASS, "class" },
|
||||
{ TK_PR_EXTENDS, "extends" },
|
||||
{ TK_PR_IS, "is" },
|
||||
{ TK_PR_ONREADY, "onready" },
|
||||
{ TK_PR_TOOL, "tool" },
|
||||
{ TK_PR_STATIC, "static" },
|
||||
|
|
|
@ -96,6 +96,7 @@ public:
|
|||
TK_PR_FUNCTION,
|
||||
TK_PR_CLASS,
|
||||
TK_PR_EXTENDS,
|
||||
TK_PR_IS,
|
||||
TK_PR_ONREADY,
|
||||
TK_PR_TOOL,
|
||||
TK_PR_STATIC,
|
||||
|
|
Loading…
Reference in a new issue