glfw: remove [*c] pointers from api and return lengthed strings when possible

This commit is contained in:
Silver 2021-11-11 09:42:49 +00:00 committed by Stephen Gutekanst
parent 28a0aebd95
commit 673ce14acf
8 changed files with 43 additions and 31 deletions

View file

@ -212,10 +212,13 @@ pub const Key = enum(c_int) {
/// @thread_safety This function must only be called from the main thread.
///
/// see also: input_key_name
pub inline fn getName(self: Key, scancode: isize) Error![*c]const u8 {
const name = cc.glfwGetKeyName(@enumToInt(self), @intCast(c_int, scancode));
pub inline fn getName(self: Key, scancode: isize) Error!?[:0]const u8 {
const name_opt = cc.glfwGetKeyName(@enumToInt(self), @intCast(c_int, scancode));
try getError();
return name;
return if (name_opt) |name|
std.mem.span(name)
else
null;
}
/// Returns the platform-specific scancode of the specified key.