GDScript: Add support for variadic functions

This commit is contained in:
Danil Alexeev 2025-03-30 12:59:05 +03:00
parent 3b963ab8b6
commit ee121ef80e
No known key found for this signature in database
GPG key ID: 5A52F75A8679EC57
33 changed files with 416 additions and 65 deletions

View file

@ -508,9 +508,22 @@ void ExtendGDScriptParser::parse_function_symbol(const GDScriptParser::FunctionN
parameters += " = " + parameter->initializer->reduced_value.to_json_string();
}
}
if (p_func->is_vararg()) {
if (!p_func->parameters.is_empty()) {
parameters += ", ";
}
const ParameterNode *rest_param = p_func->rest_parameter;
parameters += "..." + rest_param->identifier->name + ": " + rest_param->get_datatype().to_string();
}
r_symbol.detail += parameters + ")";
if (p_func->get_datatype().is_hard_type()) {
r_symbol.detail += " -> " + p_func->get_datatype().to_string();
const DataType return_type = p_func->get_datatype();
if (return_type.is_hard_type()) {
if (return_type.kind == DataType::BUILTIN && return_type.builtin_type == Variant::NIL) {
r_symbol.detail += " -> void";
} else {
r_symbol.detail += " -> " + return_type.to_string();
}
}
List<GDScriptParser::SuiteNode *> function_nodes;