Added ToString-Method for Vectors

This commit is contained in:
Simon Lübeß
2024-11-03 19:09:28 +01:00
parent 80048951f8
commit 4957f3c033
+26
View File
@@ -20,6 +20,8 @@ struct VectorAttribute<T, ComponentCount> : Attribute, IComptimeTypeApply where
GenerateEqualityOperators(type); GenerateEqualityOperators(type);
GenerateArrayAccess(type); GenerateArrayAccess(type);
GenerateToString(type);
} }
[Comptime] [Comptime]
@@ -311,6 +313,30 @@ struct VectorAttribute<T, ComponentCount> : Attribute, IComptimeTypeApply where
Compiler.EmitTypeBody(type, arrayAccess); Compiler.EmitTypeBody(type, arrayAccess);
} }
[Comptime]
private static void GenerateToString(Type type)
{
String string = scope String();
for (int i < ComponentCount)
{
if (i != 0)
string.Append(", ");
string.AppendF($"{{{ComponentNames[i]}}}");
}
String func = scope $"""
public void ToString(System.String buffer)
{{
buffer.AppendF($"({string})");
}}
""";
Compiler.EmitTypeBody(type, func);
}
} }
[AttributeUsage(.Struct | .Class)] [AttributeUsage(.Struct | .Class)]