#Convert enum to custom string values
1 messages · Page 1 of 1 (latest)
instead of having this function, you could use:
https://ziglang.org/documentation/master/std/#A;std:enums.tagName
also, the problem with your function is, that you're expecting a const pointer to an array be returned, string literals in zig are generally considered to be of type:
[N:0]const u8, which can also be coerced to: [N]const u8 and []const u8.
to fix your problem, to use your own function, you could just:
pub fn toString(self: TokenType) []const u8 {
const str = switch (self) {
.Illegal => "illegal",
.Eof => "eof",
};
return str;
}
okay. i change it to that.
using as follows
try stdout.print("Token: {s}\n", tokenType);```
get this error
@compileError("expected tuple or struct argument, found " ++ @typeName(ArgsType));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
print__anon_3740: /usr/lib/zig/std/io/writer.zig:28:27
main: zscript.zig:23:19
remaining reference traces hidden; use '-freference-trace' to see all reference traces```
Print functions take a tuple as second argument
try stdout.print("Token: {s}\n", .{tokenType});```