I tried composing a string during comptime. The string is dependent on a type given. Currently i m trying somthing like this:
const size: usize = str: {
comptime {
var length: usize = calculateLength();
break :str length;
}
};
comptime var string: [size]u8 = undefined;
const actual_length = len: {
comptime {
@memset(string[0..], 0);
var string_builder: StringBuilder = .{ .buffer = string[0..] };
_ = string_builder.addSlice(create).addSlice(table_name).addSlice("(").addSlice(create_2);
buildStringFields(&string_builder, .{ .include_id = false, .include_type = true });
_ = string_builder.addSlice(")");
break :len string_builder.position;
}
};
@compileLog(string);
someFunction(string[0..actual_length);
The compileLog gives me the correct result. But the compiler gives an error if im using the variable:
src/root.zig:135:36: error: runtime value contains reference to comptime var
someFunction(string[0..actual_length]);
Is it even possible to compose a string like this (or differntly)?
Thanks in advance