[3.x] GDScript: Fix get_method_list for custom functions

This commit is contained in:
Danil Alexeev 2022-11-09 17:59:35 +03:00
parent a81d96c637
commit e922e49b13
No known key found for this signature in database
GPG key ID: 124453E157DA8DC7
3 changed files with 46 additions and 13 deletions

View file

@ -1628,7 +1628,10 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser
codegen.current_line = 0;
codegen.call_max = 0;
codegen.debug_stack = ScriptDebugger::get_singleton() != nullptr;
#ifdef TOOLS_ENABLED
Vector<StringName> argnames;
Vector<Variant> default_arg_values;
#endif
int stack_level = 0;
@ -1693,6 +1696,15 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser
for (int i = 0; i < p_func->default_values.size(); i++) {
_parse_expression(codegen, p_func->default_values[i], stack_level, true);
defarg_addr.push_back(codegen.opcodes.size());
#ifdef TOOLS_ENABLED
const GDScriptParser::OperatorNode *assign = static_cast<const GDScriptParser::OperatorNode *>(p_func->default_values[i]);
if (assign->arguments.size() >= 2 && assign->arguments[1]->type == GDScriptParser::Node::TYPE_CONSTANT) {
const GDScriptParser::ConstantNode *cn = static_cast<const GDScriptParser::ConstantNode *>(assign->arguments[1]);
default_arg_values.push_back(cn->value);
} else {
default_arg_values.push_back(Variant());
}
#endif
}
defarg_addr.invert();
@ -1742,6 +1754,7 @@ Error GDScriptCompiler::_parse_function(GDScript *p_script, const GDScriptParser
#ifdef TOOLS_ENABLED
gdfunc->arg_names = argnames;
gdfunc->default_arg_values = default_arg_values;
#endif
//constants
if (codegen.constant_map.size()) {