Not-Nik / raylib-zig

Manually tweaked, auto-generated raylib bindings for zig. https://github.com/raysan5/raylib
MIT License
623 stars 115 forks source link

DrawText text paramenter #46

Closed ZanovelloAlberto closed 1 year ago

ZanovelloAlberto commented 1 year ago

DrawText functions accept as text parameters a ':0' terminated sentinel array

Not-Nik commented 1 year ago

What's the reasoning behind this change? I was under the impression that Zig strings were fine being passed to functions as []const u8.

Also this change should be reflected in the generate_functions.py script and also apply to all other functions accepting strings.

ZanovelloAlberto commented 1 year ago

far from being an expert here what i figure out: the c implementation uses the '\0' to recognize the end of the array, so placing ":0" we ensure that the slice will have it at the end, most of the time it work anyway cause it seem that (zig/llvm idk) places by default at the end of a string ("this") or an array literal ([_]u8{'t','h','i','s'}) a '\0'.

example:


//this is actually "hi mum\0"
const hi = "hi mum";

drawText(&hi);
// printed result: "hi mum"
// CORRECT

drawText(hi[0..2]);
// printed result: "hi mum"
// WRONG: expected --> "hi "

c dont care about your zig slices it just take the pointer and search for the '\0'.

// this is: "hi\0 mum\0";
const hi = "hi\0 mum";
drawText(hi[0..6]);
// print: "hi"

so your slices must be '\0' terminated

Not-Nik commented 1 year ago

Please update the generator script to fix this