Allow preload to accept a const string.
In preload() parsing this code will lookup the identifier in the local constant database. If the identifier corresponds to a string constant it is used as the path for preload(). Currently this does not work for global constants, only constants declared in the same class as the preload is happening. We can implement a full fix too. Maybe we can use this PR to discuss the possibilities. This (partially) fixes #6798
This commit is contained in:
parent
9cdd364fc0
commit
3e5743ca36
1 changed files with 25 additions and 4 deletions
|
@ -386,21 +386,42 @@ GDParser::Node* GDParser::_parse_expression(Node *p_parent,bool p_static,bool p_
|
||||||
tokenizer->advance();
|
tokenizer->advance();
|
||||||
|
|
||||||
String path;
|
String path;
|
||||||
|
bool found_constant = false;
|
||||||
bool valid = false;
|
bool valid = false;
|
||||||
|
ConstantNode *cn;
|
||||||
|
|
||||||
Node *subexpr = _parse_and_reduce_expression(p_parent, p_static);
|
Node *subexpr = _parse_and_reduce_expression(p_parent, p_static);
|
||||||
if (subexpr) {
|
if (subexpr) {
|
||||||
if (subexpr->type == Node::TYPE_CONSTANT) {
|
if (subexpr->type == Node::TYPE_CONSTANT) {
|
||||||
ConstantNode *cn = static_cast<ConstantNode*>(subexpr);
|
cn = static_cast<ConstantNode*>(subexpr);
|
||||||
if (cn->value.get_type() == Variant::STRING) {
|
found_constant = true;
|
||||||
valid = true;
|
}
|
||||||
path = (String) cn->value;
|
if (subexpr->type == Node::TYPE_IDENTIFIER) {
|
||||||
|
IdentifierNode *in = static_cast<IdentifierNode*>(subexpr);
|
||||||
|
Vector<ClassNode::Constant> ce = current_class->constant_expressions;
|
||||||
|
|
||||||
|
// Try to find the constant expression by the identifier
|
||||||
|
for(int i=0; i < ce.size(); ++i){
|
||||||
|
if(ce[i].identifier == in->name) {
|
||||||
|
if(ce[i].expression->type == Node::TYPE_CONSTANT) {
|
||||||
|
cn = static_cast<ConstantNode*>(ce[i].expression);
|
||||||
|
found_constant = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (found_constant && cn->value.get_type() == Variant::STRING) {
|
||||||
|
valid = true;
|
||||||
|
path = (String) cn->value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
_set_error("expected string constant as 'preload' argument.");
|
_set_error("expected string constant as 'preload' argument.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!path.is_abs_path() && base_path!="")
|
if (!path.is_abs_path() && base_path!="")
|
||||||
path=base_path+"/"+path;
|
path=base_path+"/"+path;
|
||||||
path = path.replace("///","//").simplify_path();
|
path = path.replace("///","//").simplify_path();
|
||||||
|
|
Loading…
Reference in a new issue