I’m drawing blanks trying to write a comptime functions to return a zero-terminated string of a typename. For example, for a string "ldtk.Scene" it’d return just "Scene". But I don’t know how to do this. Here’s what I tried:
Comptime-Mutable Memory Changes is a very good and thorough summary of what is and isn’t allowed to become runtime-known, but the relevant part is this:
So the easiest fix is probably something like this:
Also note that in this particular case, you don’t need to make a copy, since results of @typeName are already null-terminated, and since you take the last characters, they will still be null-terminated. So, something like this should also work:
Very cool, thanks for the help! I did find that article but I guess I didn’t fully internalize it. I did try something similar to the above copy trick, but couldn’t get it to work.
As for my original problem, I did realize I can write a much simpler version that doesn’t have this problem:
src\lua_common.zig:27:40: error: index syntax required for slice type '[:0]u8'
const copy = buffer[0..last.len :0].*;
~~~~~~~~~~~~~~~~~~~~~~^~
Dropping the .* part from the copy slice, I get a build error but the error is not shown:
Build Summary: 10/13 steps succeeded; 1 failed
run transitive failure
└─ run zig2d transitive failure
└─ zig build-exe zig2d Debug native failure
error: the following build command failed with exit code 1:
C:\Users\janne\dev\zig2d\.zig-cache\o\e15bb8313dbb2af998d110a7f9162efc\build.exe C:\Users\janne\scoop\apps\zig-dev\0.14.0-dev.1820\zig.exe C:\Users\janne\scoop\apps\zig-dev\0.14.0-dev.1820\lib C:\Users\janne\dev\zig2d C:\Users\janne\dev\zig2d\.zig-cache C:\Users\janne\AppData\Local\zig --seed 0x38ebb4af -Z9a358dfc02c21192 run -freference-trace=15
I also tried to extend my other version to add a suffix to the returned string, but somehow I don’t seem to have a good grasp on nailing comptime functions:
src\lua_common.zig:28:36: error: unable to resolve comptime value
return "L_" ++ fullTypeName[idx + 1 ..];
~~~~~~~~~~~~^~~~~~~~~~~~
src\lua_common.zig:28:36: note: slice value being concatenated must be comptime-known