@@ -101,7 +101,6 @@ GDScriptParser::GDScriptParser() {
101101 register_annotation (MethodInfo (" @onready" ), AnnotationInfo::VARIABLE, &GDScriptParser::onready_annotation);
102102 // Export annotations.
103103 register_annotation (MethodInfo (" @export" ), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_NONE, Variant::NIL>);
104- register_annotation (MethodInfo (" @export_storage" ), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_NONE, Variant::NIL>);
105104 register_annotation (MethodInfo (" @export_enum" , PropertyInfo (Variant::STRING, " names" )), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_ENUM, Variant::NIL>, varray (), true );
106105 register_annotation (MethodInfo (" @export_file" , PropertyInfo (Variant::STRING, " filter" )), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_FILE, Variant::STRING>, varray (" " ), true );
107106 register_annotation (MethodInfo (" @export_dir" ), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_DIR, Variant::STRING>);
@@ -121,6 +120,7 @@ GDScriptParser::GDScriptParser() {
121120 register_annotation (MethodInfo (" @export_flags_3d_physics" ), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_LAYERS_3D_PHYSICS, Variant::INT>);
122121 register_annotation (MethodInfo (" @export_flags_3d_navigation" ), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_LAYERS_3D_NAVIGATION, Variant::INT>);
123122 register_annotation (MethodInfo (" @export_flags_avoidance" ), AnnotationInfo::VARIABLE, &GDScriptParser::export_annotations<PROPERTY_HINT_LAYERS_AVOIDANCE, Variant::INT>);
123+ register_annotation (MethodInfo (" @export_storage" ), AnnotationInfo::VARIABLE, &GDScriptParser::export_storage_annotation);
124124 register_annotation (MethodInfo (" @export_custom" , PropertyInfo (Variant::INT, " hint" , PROPERTY_HINT_NONE, " " , PROPERTY_USAGE_CLASS_IS_ENUM, " PropertyHint" ), PropertyInfo (Variant::STRING, " hint_string" ), PropertyInfo (Variant::INT, " usage" , PROPERTY_HINT_NONE, " " , PROPERTY_USAGE_CLASS_IS_BITFIELD, " PropertyUsageFlags" )), AnnotationInfo::VARIABLE, &GDScriptParser::export_custom_annotation, varray (PROPERTY_USAGE_DEFAULT));
125125 // Export grouping annotations.
126126 register_annotation (MethodInfo (" @export_category" , PropertyInfo (Variant::STRING, " name" )), AnnotationInfo::STANDALONE, &GDScriptParser::export_group_annotations<PROPERTY_USAGE_CATEGORY>);
@@ -4295,7 +4295,7 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node
42954295 case GDScriptParser::DataType::BUILTIN:
42964296 variable->export_info .type = export_type.builtin_type ;
42974297 variable->export_info .hint = PROPERTY_HINT_NONE;
4298- variable->export_info .hint_string = Variant::get_type_name (export_type. builtin_type );
4298+ variable->export_info .hint_string = String ( );
42994299 break ;
43004300 case GDScriptParser::DataType::NATIVE:
43014301 if (ClassDB::is_parent_class (export_type.native_type , SNAME (" Resource" ))) {
@@ -4396,12 +4396,6 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node
43964396 push_error (_get_annotation_error_string (p_annotation->name , expected_types, variable->get_datatype ()), p_annotation);
43974397 return false ;
43984398 }
4399- } else if (p_annotation->name == SNAME (" @export_storage" )) {
4400- use_default_variable_type_check = false ; // Can be applied to a variable of any type.
4401-
4402- // Save the info because the compiler uses export info for overwriting member info.
4403- variable->export_info = export_type.to_property_info (variable->identifier ->name );
4404- variable->export_info .usage |= PROPERTY_USAGE_STORAGE;
44054399 }
44064400
44074401 if (use_default_variable_type_check) {
@@ -4421,11 +4415,38 @@ bool GDScriptParser::export_annotations(const AnnotationNode *p_annotation, Node
44214415 if (variable->export_info .hint ) {
44224416 hint_prefix += " /" + itos (variable->export_info .hint );
44234417 }
4418+ variable->export_info .type = original_export_type_builtin;
44244419 variable->export_info .hint = PROPERTY_HINT_TYPE_STRING;
44254420 variable->export_info .hint_string = hint_prefix + " :" + variable->export_info .hint_string ;
4426- variable->export_info .type = original_export_type_builtin;
4421+ variable->export_info .usage = PROPERTY_USAGE_DEFAULT;
4422+ variable->export_info .class_name = StringName ();
4423+ }
4424+
4425+ return true ;
4426+ }
4427+
4428+ // For `@export_storage` and `@export_custom`, there is no need to check the variable type, argument values,
4429+ // or handle array exports in a special way, so they are implemented as separate methods.
4430+
4431+ bool GDScriptParser::export_storage_annotation (const AnnotationNode *p_annotation, Node *p_node, ClassNode *p_class) {
4432+ ERR_FAIL_COND_V_MSG (p_node->type != Node::VARIABLE, false , vformat (R"( "%s" annotation can only be applied to variables.)" , p_annotation->name ));
4433+
4434+ VariableNode *variable = static_cast <VariableNode *>(p_node);
4435+ if (variable->is_static ) {
4436+ push_error (vformat (R"( Annotation "%s" cannot be applied to a static variable.)" , p_annotation->name ), p_annotation);
4437+ return false ;
4438+ }
4439+ if (variable->exported ) {
4440+ push_error (vformat (R"( Annotation "%s" cannot be used with another "@export" annotation.)" , p_annotation->name ), p_annotation);
4441+ return false ;
44274442 }
44284443
4444+ variable->exported = true ;
4445+
4446+ // Save the info because the compiler uses export info for overwriting member info.
4447+ variable->export_info = variable->get_datatype ().to_property_info (variable->identifier ->name );
4448+ variable->export_info .usage |= PROPERTY_USAGE_STORAGE;
4449+
44294450 return true ;
44304451}
44314452
@@ -4434,6 +4455,10 @@ bool GDScriptParser::export_custom_annotation(const AnnotationNode *p_annotation
44344455 ERR_FAIL_COND_V_MSG (p_annotation->resolved_arguments .size () < 2 , false , R"( Annotation "@export_custom" requires 2 arguments.)" );
44354456
44364457 VariableNode *variable = static_cast <VariableNode *>(p_node);
4458+ if (variable->is_static ) {
4459+ push_error (vformat (R"( Annotation "%s" cannot be applied to a static variable.)" , p_annotation->name ), p_annotation);
4460+ return false ;
4461+ }
44374462 if (variable->exported ) {
44384463 push_error (vformat (R"( Annotation "%s" cannot be used with another "@export" annotation.)" , p_annotation->name ), p_annotation);
44394464 return false ;
0 commit comments