Unnamed: 0
int64
0
0
repo_id
stringlengths
5
186
file_path
stringlengths
15
223
content
stringlengths
1
32.8M
0
repos
repos/zee_alloc/build.zig
const Builder = @import("std").build.Builder; pub fn build(b: *Builder) void { const mode = b.standardReleaseOptions(); const lib = b.addStaticLibrary("zee_alloc", "src/main.zig"); lib.setBuildMode(mode); var main_tests = b.addTest("src/main.zig"); main_tests.setBuildMode(mode); const test_step = b.step("test", "Run library tests"); test_step.dependOn(&main_tests.step); const build_docs = b.addSystemCommand(&[_][]const u8{ b.zig_exe, "build-lib", "src/wasm_exports.zig", "-femit-docs", "-fno-emit-bin", "-target", "wasm32-freestanding", "--output-dir", ".", }); const doc_step = b.step("docs", "Generate the docs"); doc_step.dependOn(&build_docs.step); b.default_step.dependOn(&lib.step); b.installArtifact(lib); }
0
repos/zee_alloc
repos/zee_alloc/src/main.zig
const std = @import("std"); const builtin = @import("builtin"); const Allocator = std.mem.Allocator; const meta_size = 2 * @sizeOf(usize); const min_payload_size = meta_size; const min_frame_size = meta_size + min_payload_size; const jumbo_index = 0; const page_index = 1; pub const ZeeAllocDefaults = ZeeAlloc(Config{}); pub const Config = struct { /// ZeeAlloc will request a multiple of `page_size` from the backing allocator. /// **Must** be a power of two. page_size: usize = std.math.max(std.mem.page_size, 65536), // 64K ought to be enough for everybody validation: Validation = .External, jumbo_match_strategy: JumboMatchStrategy = .Closest, buddy_strategy: BuddyStrategy = .Fast, shrink_strategy: ShrinkStrategy = .Defer, pub const JumboMatchStrategy = enum { /// Use the frame that wastes the least space /// Scans the entire jumbo freelist, which is slower but keeps memory pretty tidy Closest, /// Use only exact matches /// -75 bytes vs `.Closest` /// Similar performance to Closest if allocation sizes are consistent throughout lifetime Exact, /// Use the first frame that fits /// -75 bytes vs `.Closest` /// Initially faster to allocate but causes major fragmentation issues First, }; pub const BuddyStrategy = enum { /// Return the raw free frame immediately /// Generally faster because it does not recombine or resplit frames, /// but it also requires more underlying memory Fast, /// Recombine with free buddies to reclaim storage /// +153 bytes vs `.Fast` /// More efficient use of existing memory at the cost of cycles and bytes Coalesce, }; pub const ShrinkStrategy = enum { /// Return a smaller view into the same frame /// Faster because it ignores shrink, but never reclaims space until freed Defer, /// Split the frame into smallest usable chunk /// +112 bytes vs `.Defer` /// Better at reclaiming non-jumbo memory, but never reclaims jumbo until freed Chunkify, }; pub const Validation = enum { /// Enable all validations, including library internals Dev, /// Only validate external boundaries — e.g. `realloc` or `free` External, /// Turn off all validations — pretend this library is `--release-small` Unsafe, fn useInternal(comptime self: Validation) bool { if (builtin.mode == .Debug) { return true; } return self == .Dev; } fn useExternal(comptime self: Validation) bool { return switch (builtin.mode) { .Debug => true, .ReleaseSafe => self == .Dev or self == .External, else => false, }; } fn assertInternal(comptime self: Validation, ok: bool) void { @setRuntimeSafety(comptime self.useInternal()); if (!ok) unreachable; } fn assertExternal(comptime self: Validation, ok: bool) void { @setRuntimeSafety(comptime self.useExternal()); if (!ok) unreachable; } }; }; pub fn ZeeAlloc(comptime conf: Config) type { std.debug.assert(conf.page_size >= std.mem.page_size); std.debug.assert(std.math.isPowerOfTwo(conf.page_size)); const inv_bitsize_ref = page_index + std.math.log2_int(usize, conf.page_size); const size_buckets = inv_bitsize_ref - std.math.log2_int(usize, min_frame_size) + 1; // + 1 jumbo list return struct { const Self = @This(); const config = conf; // Synthetic representation -- should not be created directly, but instead carved out of []u8 bytes const Frame = packed struct { const alignment = 2 * @sizeOf(usize); const allocated_signal = @intToPtr(*Frame, std.math.maxInt(usize)); next: ?*Frame, frame_size: usize, // We can't embed arbitrarily sized arrays in a struct so stick a placeholder here payload: [min_payload_size]u8, fn isCorrectSize(memsize: usize) bool { return memsize >= min_frame_size and (memsize % conf.page_size == 0 or std.math.isPowerOfTwo(memsize)); } pub fn init(raw_bytes: []u8) *Frame { @setRuntimeSafety(comptime conf.validation.useInternal()); const node = @ptrCast(*Frame, raw_bytes.ptr); node.frame_size = raw_bytes.len; node.validate() catch unreachable; return node; } pub fn restoreAddr(addr: usize) *Frame { @setRuntimeSafety(comptime conf.validation.useInternal()); const node = @intToPtr(*Frame, addr); node.validate() catch unreachable; return node; } pub fn restorePayload(payload: [*]u8) !*Frame { @setRuntimeSafety(comptime conf.validation.useInternal()); const node = @fieldParentPtr(Frame, "payload", @ptrCast(*[min_payload_size]u8, payload)); try node.validate(); return node; } pub fn validate(self: *Frame) !void { if (@ptrToInt(self) % alignment != 0) { return error.UnalignedMemory; } if (!Frame.isCorrectSize(self.frame_size)) { return error.UnalignedMemory; } } pub fn isAllocated(self: *Frame) bool { return self.next == allocated_signal; } pub fn markAllocated(self: *Frame) void { self.next = allocated_signal; } pub fn payloadSize(self: *Frame) usize { @setRuntimeSafety(comptime conf.validation.useInternal()); return self.frame_size - meta_size; } pub fn payloadSlice(self: *Frame, start: usize, end: usize) []u8 { @setRuntimeSafety(comptime conf.validation.useInternal()); conf.validation.assertInternal(start <= end); conf.validation.assertInternal(end <= self.payloadSize()); const ptr = @ptrCast([*]u8, &self.payload); return ptr[start..end]; } }; const FreeList = packed struct { first: ?*Frame, pub fn init() FreeList { return FreeList{ .first = null }; } pub fn root(self: *FreeList) *Frame { // Due to packed struct layout, FreeList.first == Frame.next // This enables more graceful iteration without needing a back reference. // Since this is not a full frame, accessing any other field will corrupt memory. // Thar be dragons 🐉 return @ptrCast(*Frame, self); } pub fn prepend(self: *FreeList, node: *Frame) void { node.next = self.first; self.first = node; } pub fn remove(self: *FreeList, target: *Frame) !void { var iter = self.root(); while (iter.next) |next| : (iter = next) { if (next == target) { _ = self.removeAfter(iter); return; } } return error.ElementNotFound; } pub fn removeAfter(self: *FreeList, ref: *Frame) *Frame { const next_node = ref.next.?; ref.next = next_node.next; return next_node; } }; /// The definitive™ way of using `ZeeAlloc` pub const wasm_allocator = &_wasm.allocator; var _wasm = init(&wasm_page_allocator); backing_allocator: *Allocator, free_lists: [size_buckets]FreeList = [_]FreeList{FreeList.init()} ** size_buckets, allocator: Allocator = Allocator{ .allocFn = alloc, .resizeFn = resize, }, pub fn init(backing_allocator: *Allocator) Self { return Self{ .backing_allocator = backing_allocator }; } fn allocNode(self: *Self, memsize: usize) !*Frame { @setRuntimeSafety(comptime conf.validation.useInternal()); const alloc_size = unsafeAlignForward(memsize + meta_size); const rawData = try self.backing_allocator.allocFn(self.backing_allocator, alloc_size, conf.page_size, 0, 0); return Frame.init(rawData); } fn findFreeNode(self: *Self, memsize: usize) ?*Frame { @setRuntimeSafety(comptime conf.validation.useInternal()); var search_size = self.padToFrameSize(memsize); while (true) : (search_size *= 2) { const i = self.freeListIndex(search_size); var free_list = &self.free_lists[i]; var closest_match_prev: ?*Frame = null; var closest_match_size: usize = std.math.maxInt(usize); var iter = free_list.root(); while (iter.next) |next| : (iter = next) { switch (conf.jumbo_match_strategy) { .Exact => { if (next.frame_size == search_size) { return free_list.removeAfter(iter); } }, .Closest => { if (next.frame_size == search_size) { return free_list.removeAfter(iter); } else if (next.frame_size > search_size and next.frame_size < closest_match_size) { closest_match_prev = iter; closest_match_size = next.frame_size; } }, .First => { if (next.frame_size >= search_size) { return free_list.removeAfter(iter); } }, } } if (closest_match_prev) |prev| { return free_list.removeAfter(prev); } if (i <= page_index) { return null; } } } fn chunkify(self: *Self, node: *Frame, target_size: usize, len_align: u29) usize { @setCold(config.shrink_strategy != .Defer); @setRuntimeSafety(comptime conf.validation.useInternal()); conf.validation.assertInternal(target_size <= node.payloadSize()); if (node.frame_size <= conf.page_size) { const target_frame_size = self.padToFrameSize(target_size); var sub_frame_size = node.frame_size / 2; while (sub_frame_size >= target_frame_size) : (sub_frame_size /= 2) { const start = node.payloadSize() - sub_frame_size; const sub_frame_data = node.payloadSlice(start, node.payloadSize()); const sub_node = Frame.init(sub_frame_data); self.freeListOfSize(sub_frame_size).prepend(sub_node); node.frame_size = sub_frame_size; } } return std.mem.alignAllocLen(node.payloadSize(), target_size, len_align); } fn free(self: *Self, target: *Frame) void { @setCold(true); @setRuntimeSafety(comptime conf.validation.useInternal()); var node = target; if (conf.buddy_strategy == .Coalesce) { while (node.frame_size < conf.page_size) : (node.frame_size *= 2) { // 16: [0, 16], [32, 48] // 32: [0, 32], [64, 96] const node_addr = @ptrToInt(node); const buddy_addr = node_addr ^ node.frame_size; const buddy = Frame.restoreAddr(buddy_addr); if (buddy.isAllocated() or buddy.frame_size != node.frame_size) { break; } self.freeListOfSize(buddy.frame_size).remove(buddy) catch unreachable; // Use the lowest address as the new root node = Frame.restoreAddr(node_addr & buddy_addr); } } self.freeListOfSize(node.frame_size).prepend(node); } // https://github.com/ziglang/zig/issues/2426 fn unsafeCeilPowerOfTwo(comptime T: type, value: T) T { @setRuntimeSafety(comptime conf.validation.useInternal()); if (value <= 2) return value; const Shift = comptime std.math.Log2Int(T); return @as(T, 1) << @intCast(Shift, @bitSizeOf(T) - @clz(T, value - 1)); } fn unsafeLog2Int(comptime T: type, x: T) std.math.Log2Int(T) { @setRuntimeSafety(comptime conf.validation.useInternal()); conf.validation.assertInternal(x != 0); return @intCast(std.math.Log2Int(T), @bitSizeOf(T) - 1 - @clz(T, x)); } fn unsafeAlignForward(size: usize) usize { @setRuntimeSafety(comptime conf.validation.useInternal()); const forward = size + (conf.page_size - 1); return forward & ~(conf.page_size - 1); } fn padToFrameSize(self: *Self, memsize: usize) usize { @setRuntimeSafety(comptime conf.validation.useInternal()); const meta_memsize = std.math.max(memsize + meta_size, min_frame_size); return std.math.min(unsafeCeilPowerOfTwo(usize, meta_memsize), unsafeAlignForward(meta_memsize)); // More byte-efficient of this: // const meta_memsize = memsize + meta_size; // if (meta_memsize <= min_frame_size) { // return min_frame_size; // } else if (meta_memsize < conf.page_size) { // return ceilPowerOfTwo(usize, meta_memsize); // } else { // return std.mem.alignForward(meta_memsize, conf.page_size); // } } fn freeListOfSize(self: *Self, frame_size: usize) *FreeList { @setRuntimeSafety(comptime conf.validation.useInternal()); const i = self.freeListIndex(frame_size); return &self.free_lists[i]; } fn freeListIndex(self: *Self, frame_size: usize) usize { @setRuntimeSafety(comptime conf.validation.useInternal()); conf.validation.assertInternal(Frame.isCorrectSize(frame_size)); return inv_bitsize_ref - std.math.min(inv_bitsize_ref, unsafeLog2Int(usize, frame_size)); // More byte-efficient of this: // if (frame_size > conf.page_size) { // return jumbo_index; // } else if (frame_size <= min_frame_size) { // return self.free_lists.len - 1; // } else { // return inv_bitsize_ref - unsafeLog2Int(usize, frame_size); // } } fn alloc(allocator: *Allocator, n: usize, ptr_align: u29, len_align: u29, ret_addr: usize) Allocator.Error![]u8 { const self = @fieldParentPtr(Self, "allocator", allocator); if (ptr_align > min_frame_size) { return error.OutOfMemory; } const node = self.findFreeNode(n) orelse try self.allocNode(n); node.markAllocated(); const len = self.chunkify(node, n, len_align); return node.payloadSlice(0, len); } fn resize(allocator: *Allocator, buf: []u8, buf_align: u29, new_size: usize, len_align: u29, ret_addr: usize) Allocator.Error!usize { const self = @fieldParentPtr(Self, "allocator", allocator); @setRuntimeSafety(comptime conf.validation.useExternal()); const node = Frame.restorePayload(buf.ptr) catch unreachable; conf.validation.assertExternal(node.isAllocated()); if (new_size == 0) { self.free(node); return 0; } else if (new_size > node.payloadSize()) { return error.OutOfMemory; } else switch (conf.shrink_strategy) { .Defer => return new_size, .Chunkify => return self.chunkify(node, new_size, len_align), } } fn debugCount(self: *Self, index: usize) usize { var count: usize = 0; var iter = self.free_lists[index].first; while (iter) |node| : (iter = node.next) { count += 1; } return count; } fn debugCountAll(self: *Self) usize { var count: usize = 0; for (self.free_lists) |_, i| { count += self.debugCount(i); } return count; } fn debugDump(self: *Self) void { for (self.free_lists) |_, i| { std.debug.warn("{}: {}\n", i, self.debugCount(i)); } } }; } fn assertIf(comptime run_assert: bool, ok: bool) void { @setRuntimeSafety(run_assert); if (!ok) unreachable; } var wasm_page_allocator = init: { if (builtin.cpu.arch != .wasm32) { @compileError("wasm allocator is only available for wasm32 arch"); } // std.heap.WasmPageAllocator is designed for reusing pages // We never free, so this lets us stay super small const WasmPageAllocator = struct { fn alloc(allocator: *Allocator, n: usize, alignment: u29, len_align: u29, ret_addr: usize) Allocator.Error![]u8 { const is_debug = builtin.mode == .Debug; @setRuntimeSafety(is_debug); assertIf(is_debug, n % std.mem.page_size == 0); // Should only be allocating page size chunks assertIf(is_debug, alignment % std.mem.page_size == 0); // Should only align to page_size increments const requested_page_count = @intCast(u32, n / std.mem.page_size); const prev_page_count = @wasmMemoryGrow(0, requested_page_count); if (prev_page_count < 0) { return error.OutOfMemory; } const start_ptr = @intToPtr([*]u8, @intCast(usize, prev_page_count) * std.mem.page_size); return start_ptr[0..n]; } }; break :init Allocator{ .allocFn = WasmPageAllocator.alloc, .resizeFn = undefined, // Shouldn't be shrinking / freeing }; }; pub const ExportC = struct { allocator: *std.mem.Allocator, malloc: bool = true, free: bool = true, calloc: bool = false, realloc: bool = false, pub fn run(comptime conf: ExportC) void { const Funcs = struct { fn malloc(size: usize) callconv(.C) ?*c_void { if (size == 0) { return null; } //const result = conf.allocator.alloc(u8, size) catch return null; const result = conf.allocator.allocFn(conf.allocator, size, 1, 1, 0) catch return null; return result.ptr; } fn calloc(num_elements: usize, element_size: usize) callconv(.C) ?*c_void { const size = num_elements *% element_size; const c_ptr = @call(.{ .modifier = .never_inline }, malloc, .{size}); if (c_ptr) |ptr| { const p = @ptrCast([*]u8, ptr); @memset(p, 0, size); } return c_ptr; } fn realloc(c_ptr: ?*c_void, new_size: usize) callconv(.C) ?*c_void { if (new_size == 0) { @call(.{ .modifier = .never_inline }, free, .{c_ptr}); return null; } else if (c_ptr) |ptr| { // Use a synthetic slice const p = @ptrCast([*]u8, ptr); const result = conf.allocator.realloc(p[0..1], new_size) catch return null; return @ptrCast(*c_void, result.ptr); } else { return @call(.{ .modifier = .never_inline }, malloc, .{new_size}); } } fn free(c_ptr: ?*c_void) callconv(.C) void { if (c_ptr) |ptr| { // Use a synthetic slice. zee_alloc will free via corresponding metadata. const p = @ptrCast([*]u8, ptr); //conf.allocator.free(p[0..1]); _ = conf.allocator.resizeFn(conf.allocator, p[0..1], 0, 0, 0, 0) catch unreachable; } } }; if (conf.malloc) { @export(Funcs.malloc, .{ .name = "malloc" }); } if (conf.calloc) { @export(Funcs.calloc, .{ .name = "calloc" }); } if (conf.realloc) { @export(Funcs.realloc, .{ .name = "realloc" }); } if (conf.free) { @export(Funcs.free, .{ .name = "free" }); } } }; // Tests const testing = std.testing; test "ZeeAlloc helpers" { var buf: [0]u8 = undefined; var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(buf[0..]); var zee_alloc = ZeeAllocDefaults.init(&fixed_buffer_allocator.allocator); const page_size = ZeeAllocDefaults.config.page_size; // freeListIndex { testing.expectEqual(zee_alloc.freeListIndex(page_size), page_index); testing.expectEqual(zee_alloc.freeListIndex(page_size / 2), page_index + 1); testing.expectEqual(zee_alloc.freeListIndex(page_size / 4), page_index + 2); } // padToFrameSize { testing.expectEqual(zee_alloc.padToFrameSize(page_size - meta_size), page_size); testing.expectEqual(zee_alloc.padToFrameSize(page_size), 2 * page_size); testing.expectEqual(zee_alloc.padToFrameSize(page_size - meta_size + 1), 2 * page_size); testing.expectEqual(zee_alloc.padToFrameSize(2 * page_size), 3 * page_size); } } test "ZeeAlloc internals" { var buf: [1000000]u8 = undefined; // node count makes sense { var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(buf[0..]); var zee_alloc = ZeeAllocDefaults.init(&fixed_buffer_allocator.allocator); testing.expectEqual(zee_alloc.debugCountAll(), 0); var small1 = try zee_alloc.allocator.create(u8); var prev_free_nodes = zee_alloc.debugCountAll(); testing.expect(prev_free_nodes > 0); var small2 = try zee_alloc.allocator.create(u8); testing.expectEqual(zee_alloc.debugCountAll(), prev_free_nodes - 1); prev_free_nodes = zee_alloc.debugCountAll(); var big1 = try zee_alloc.allocator.alloc(u8, 127 * 1024); testing.expectEqual(zee_alloc.debugCountAll(), prev_free_nodes); zee_alloc.allocator.free(big1); testing.expectEqual(zee_alloc.debugCountAll(), prev_free_nodes + 1); testing.expectEqual(zee_alloc.debugCount(jumbo_index), 1); } // BuddyStrategy = Coalesce { var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(buf[0..]); var zee_alloc = ZeeAlloc(Config{ .buddy_strategy = .Coalesce }).init(&fixed_buffer_allocator.allocator); var small = try zee_alloc.allocator.create(u8); testing.expect(zee_alloc.debugCountAll() > 1); zee_alloc.allocator.destroy(small); testing.expectEqual(zee_alloc.debugCountAll(), 1); } // realloc reuses frame if possible { var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(buf[0..]); var zee_alloc = ZeeAllocDefaults.init(&fixed_buffer_allocator.allocator); const orig = try zee_alloc.allocator.alloc(u8, 1); const addr = orig.ptr; var i: usize = 2; while (i <= min_payload_size) : (i += 1) { var re = try zee_alloc.allocator.realloc(orig, i); testing.expectEqual(re.ptr, addr); } } // allocated_signal { var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(buf[0..]); var zee_alloc = ZeeAllocDefaults.init(&fixed_buffer_allocator.allocator); const payload = try zee_alloc.allocator.alloc(u8, 1); const frame = try ZeeAllocDefaults.Frame.restorePayload(payload.ptr); testing.expect(frame.isAllocated()); zee_alloc.allocator.free(payload); testing.expect(!frame.isAllocated()); } } // -- functional tests from std/heap.zig fn testAllocator(allocator: *std.mem.Allocator) !void { var slice = try allocator.alloc(*i32, 100); testing.expectEqual(slice.len, 100); for (slice) |*item, i| { item.* = try allocator.create(i32); item.*.* = @intCast(i32, i); } slice = try allocator.realloc(slice, 20000); testing.expectEqual(slice.len, 20000); for (slice[0..100]) |item, i| { testing.expectEqual(item.*, @intCast(i32, i)); allocator.destroy(item); } slice = allocator.shrink(slice, 50); testing.expectEqual(slice.len, 50); slice = allocator.shrink(slice, 25); testing.expectEqual(slice.len, 25); slice = allocator.shrink(slice, 0); testing.expectEqual(slice.len, 0); slice = try allocator.realloc(slice, 10); testing.expectEqual(slice.len, 10); allocator.free(slice); } fn testAllocatorAligned(allocator: *Allocator, comptime alignment: u29) !void { // initial var slice = try allocator.alignedAlloc(u8, alignment, 10); testing.expectEqual(slice.len, 10); // grow slice = try allocator.realloc(slice, 100); testing.expectEqual(slice.len, 100); // shrink slice = allocator.shrink(slice, 10); testing.expectEqual(slice.len, 10); // go to zero slice = allocator.shrink(slice, 0); testing.expectEqual(slice.len, 0); // realloc from zero slice = try allocator.realloc(slice, 100); testing.expectEqual(slice.len, 100); // shrink with shrink slice = allocator.shrink(slice, 10); testing.expectEqual(slice.len, 10); // shrink to zero slice = allocator.shrink(slice, 0); testing.expectEqual(slice.len, 0); } fn testAllocatorLargeAlignment(allocator: *Allocator) Allocator.Error!void { //Maybe a platform's page_size is actually the same as or // very near usize? // TODO: support ultra wide alignment (bigger than page_size) //if (std.mem.page_size << 2 > std.math.maxInt(usize)) return; //const USizeShift = @IntType(false, std.math.log2(usize.bit_count)); //const large_align = u29(std.mem.page_size << 2); const USizeShift = @IntType(false, std.math.log2(usize.bit_count)); const large_align: u29 = std.mem.page_size; var align_mask: usize = undefined; _ = @shlWithOverflow(usize, ~@as(usize, 0), @as(USizeShift, @ctz(usize, large_align)), &align_mask); var slice = try allocator.alignedAlloc(u8, large_align, 500); testing.expectEqual(@ptrToInt(slice.ptr) & align_mask, @ptrToInt(slice.ptr)); slice = allocator.shrink(slice, 100); testing.expectEqual(@ptrToInt(slice.ptr) & align_mask, @ptrToInt(slice.ptr)); slice = try allocator.realloc(slice, 5000); testing.expectEqual(@ptrToInt(slice.ptr) & align_mask, @ptrToInt(slice.ptr)); slice = allocator.shrink(slice, 10); testing.expectEqual(@ptrToInt(slice.ptr) & align_mask, @ptrToInt(slice.ptr)); slice = try allocator.realloc(slice, 20000); testing.expectEqual(@ptrToInt(slice.ptr) & align_mask, @ptrToInt(slice.ptr)); allocator.free(slice); } fn testAllocatorAlignedShrink(allocator: *Allocator) Allocator.Error!void { var debug_buffer: [1000]u8 = undefined; const debug_allocator = &std.heap.FixedBufferAllocator.init(&debug_buffer).allocator; const alloc_size = std.mem.page_size * 2 + 50; var slice = try allocator.alignedAlloc(u8, 16, alloc_size); defer allocator.free(slice); var stuff_to_free = std.ArrayList([]align(16) u8).init(debug_allocator); // On Windows, VirtualAlloc returns addresses aligned to a 64K boundary, // which is 16 pages, hence the 32. This test may require to increase // the size of the allocations feeding the `allocator` parameter if they // fail, because of this high over-alignment we want to have. while (@ptrToInt(slice.ptr) == std.mem.alignForward(@ptrToInt(slice.ptr), std.mem.page_size * 32)) { try stuff_to_free.append(slice); slice = try allocator.alignedAlloc(u8, 16, alloc_size); } while (stuff_to_free.popOrNull()) |item| { allocator.free(item); } slice[0] = 0x12; slice[60] = 0x34; // realloc to a smaller size but with a larger alignment slice = try allocator.alignedRealloc(slice, std.mem.page_size, alloc_size / 2); testing.expectEqual(slice[0], 0x12); testing.expectEqual(slice[60], 0x34); } test "ZeeAlloc with FixedBufferAllocator" { var buf: [1000000]u8 = undefined; var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(buf[0..]); var zee_alloc = ZeeAllocDefaults.init(&fixed_buffer_allocator.allocator); try testAllocator(&zee_alloc.allocator); // try testAllocatorAligned(&zee_alloc.allocator, 8); // try testAllocatorLargeAlignment(&zee_alloc.allocator); // try testAllocatorAlignedShrink(&zee_alloc.allocator); } test "ZeeAlloc with PageAllocator" { var zee_alloc = ZeeAllocDefaults.init(std.heap.page_allocator); try testAllocator(&zee_alloc.allocator); try testAllocatorAligned(&zee_alloc.allocator, 8); // try testAllocatorLargeAlignment(&zee_alloc.allocator); // try testAllocatorAlignedShrink(&zee_alloc.allocator); }
0
repos/zee_alloc
repos/zee_alloc/src/fuzz.zig
// https://github.com/andrewrk/zig-general-purpose-allocator/blob/520b396/test/fuzz.zig const std = @import("std"); const zee_alloc = @import("main.zig"); const test_config = zee_alloc.Config{}; test "fuzz testing" { var za = zee_alloc.ZeeAllocDefaults.init(std.heap.page_allocator); const allocator = &za.allocator; const seed = 0x1234; var prng = std.rand.DefaultPrng.init(seed); const rand = &prng.random; var allocated_n: usize = 0; var freed_n: usize = 0; const Free = struct { slice: []u8, it_index: usize, }; var free_queue = std.ArrayList(Free).init(allocator); var it_index: usize = 0; while (true) : (it_index += 1) { const is_small = rand.boolean(); const size = if (is_small) rand.uintLessThanBiased(usize, std.mem.page_size) else std.mem.page_size + rand.uintLessThanBiased(usize, 10 * 1024 * 1024); const iterations_until_free = rand.uintLessThanBiased(usize, 100); const slice = allocator.alloc(u8, size) catch unreachable; allocated_n += size; free_queue.append(Free{ .slice = slice, .it_index = it_index + iterations_until_free, }) catch unreachable; var free_i: usize = 0; while (free_i < free_queue.items.len) { const item = &free_queue.items[free_i]; if (item.it_index <= it_index) { // free time allocator.free(item.slice); freed_n += item.slice.len; _ = free_queue.swapRemove(free_i); continue; } free_i += 1; } std.debug.warn("index={} allocated: {Bi:2} freed: {Bi:2}\n", .{ it_index, allocated_n, freed_n }); //za.debugDump(); } }
0
repos/zee_alloc
repos/zee_alloc/src/bench.zig
const builtin = @import("builtin"); const std = @import("std"); const debug = std.debug; const io = std.io; const math = std.math; const mem = std.mem; const meta = std.meta; const time = std.time; const Decl = builtin.TypeInfo.Declaration; pub fn benchmark(comptime B: type) !void { const args = if (@hasDecl(B, "args")) B.args else [_]void{{}}; const iterations: u32 = if (@hasDecl(B, "iterations")) B.iterations else 100000; comptime var max_fn_name_len = 0; const functions = comptime blk: { var res: []const Decl = &[_]Decl{}; for (meta.declarations(B)) |decl| { if (decl.data != Decl.Data.Fn) continue; if (max_fn_name_len < decl.name.len) max_fn_name_len = decl.name.len; res = res ++ [_]Decl{decl}; } break :blk res; }; if (functions.len == 0) @compileError("No benchmarks to run."); const max_name_spaces = comptime math.max(max_fn_name_len + digits(u64, 10, args.len) + 1, "Benchmark".len); var timer = try time.Timer.start(); debug.warn("\n", .{}); debug.warn("Benchmark", .{}); nTimes(' ', (max_name_spaces - "Benchmark".len) + 1); nTimes(' ', digits(u64, 10, math.maxInt(u64)) - "Mean(ns)".len); debug.warn("Mean(ns)\n", .{}); nTimes('-', max_name_spaces + digits(u64, 10, math.maxInt(u64)) + 1); debug.warn("\n", .{}); inline for (functions) |def| { for (args) |arg, index| { var runtime_sum: u128 = 0; var i: usize = 0; while (i < iterations) : (i += 1) { timer.reset(); const res = switch (@TypeOf(arg)) { void => @field(B, def.name)(), else => @field(B, def.name)(arg), }; const runtime = timer.read(); runtime_sum += runtime; doNotOptimize(res); } const runtime_mean = @intCast(u64, runtime_sum / iterations); debug.warn("{}.{}", .{ def.name, index }); nTimes(' ', (max_name_spaces - (def.name.len + digits(u64, 10, index) + 1)) + 1); nTimes(' ', digits(u64, 10, math.maxInt(u64)) - digits(u64, 10, runtime_mean)); debug.warn("{}\n", .{runtime_mean}); } } } /// Pretend to use the value so the optimizer cant optimize it out. fn doNotOptimize(val: anytype) void { const T = @TypeOf(val); var store: T = undefined; @ptrCast(*volatile T, &store).* = val; } fn digits(comptime N: type, comptime base: comptime_int, n: N) usize { comptime var res = 1; comptime var check = base; inline while (check <= math.maxInt(N)) : ({ check *= base; res += 1; }) { if (n < check) return res; } return res; } fn nTimes(c: u8, times: usize) void { var i: usize = 0; while (i < times) : (i += 1) debug.warn("{c}", .{c}); } const zee_alloc = @import("main.zig"); var test_buf: [1024 * 1024]u8 = undefined; test "ZeeAlloc benchmark" { try benchmark(struct { const Arg = struct { num: usize, size: usize, fn benchAllocator(a: Arg, allocator: *std.mem.Allocator, comptime free: bool) !void { var i: usize = 0; while (i < a.num) : (i += 1) { const bytes = try allocator.alloc(u8, a.size); defer if (free) allocator.free(bytes); } } }; pub const args = [_]Arg{ Arg{ .num = 10 * 1, .size = 1024 * 1 }, Arg{ .num = 10 * 2, .size = 1024 * 1 }, Arg{ .num = 10 * 4, .size = 1024 * 1 }, Arg{ .num = 10 * 1, .size = 1024 * 2 }, Arg{ .num = 10 * 2, .size = 1024 * 2 }, Arg{ .num = 10 * 4, .size = 1024 * 2 }, Arg{ .num = 10 * 1, .size = 1024 * 4 }, Arg{ .num = 10 * 2, .size = 1024 * 4 }, Arg{ .num = 10 * 4, .size = 1024 * 4 }, }; pub const iterations = 10000; pub fn FixedBufferAllocator(a: Arg) void { var fba = std.heap.FixedBufferAllocator.init(test_buf[0..]); a.benchAllocator(&fba.allocator, false) catch unreachable; } pub fn Arena_FixedBufferAllocator(a: Arg) void { var fba = std.heap.FixedBufferAllocator.init(test_buf[0..]); var arena = std.heap.ArenaAllocator.init(&fba.allocator); defer arena.deinit(); a.benchAllocator(&arena.allocator, false) catch unreachable; } pub fn ZeeAlloc_FixedBufferAllocator(a: Arg) void { var fba = std.heap.FixedBufferAllocator.init(test_buf[0..]); var za = zee_alloc.ZeeAllocDefaults.init(&fba.allocator); a.benchAllocator(&za.allocator, false) catch unreachable; } pub fn PageAllocator(a: Arg) void { a.benchAllocator(std.heap.page_allocator, true) catch unreachable; } pub fn Arena_PageAllocator(a: Arg) void { var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); defer arena.deinit(); a.benchAllocator(&arena.allocator, false) catch unreachable; } pub fn ZeeAlloc_PageAllocator(a: Arg) void { var za = zee_alloc.ZeeAllocDefaults.init(std.heap.page_allocator); a.benchAllocator(&za.allocator, false) catch unreachable; } }); }
0
repos/zee_alloc
repos/zee_alloc/src/wasm_exports.zig
const builtin = @import("builtin"); const std = @import("std"); const zee_alloc = @import("main.zig"); // Pull in for documentation usingnamespace zee_alloc; comptime { (zee_alloc.ExportC{ .allocator = zee_alloc.ZeeAllocDefaults.wasm_allocator, .malloc = true, .free = true, .realloc = true, .calloc = true, }).run(); // TODO: use this once we get inferred struct initializers -- https://github.com/ziglang/zig/issues/685 // zee_alloc.ExportC.run(.{ // .allocator = zee_alloc.ZeeAllocDefaults.wasm_allocator, // .malloc = true, // .free = true, // .realloc = true, // .calloc = true, // }); }
0
repos/zee_alloc
repos/zee_alloc/src/ceil_power_of_two.zig
// Source: https://github.com/ziglang/zig/issues/2426 const std = @import("std"); // naive implementation // this can overflow (i.e. ceilPowerOfTwo(u4, 9)) export fn ceilPowerOfTwo0(value: usize) usize { if (value <= 2) return value; var power: usize = 1; while (power < value) power *= 2; return power; } // using log2_int_ceil // this can overflow (i.e. ceilPowerOfTwo(u4, 9)) export fn ceilPowerOfTwo1(value: usize) usize { if (value <= 2) return value; const log2_val = std.math.log2_int_ceil(usize, value); return usize(1) << log2_val; } // using bit shifting with special case for value <= 2 // this can overflow (i.e. ceilPowerOfTwo(u4, 9)) export fn ceilPowerOfTwo2(value: usize) usize { if (value <= 2) return value; var x = value - 1; comptime var i = 1; inline while (usize.bit_count > i) : (i *= 2) { x |= (x >> i); } return x + 1; } // using bit shifting with wrapping arithmetic operators to avoid special case // ceilPowerOfTwo(u4, 9) will erroneously return 0 due to wrapping export fn ceilPowerOfTwo3(value: usize) usize { var x = value -% 1; comptime var i = 1; inline while (usize.bit_count > i) : (i *= 2) { x |= (x >> i); } return x +% 1; } // using @clz // this can overflow (i.e. ceilPowerOfTwo(u4, 9)) with "integer cast truncated bits" export fn ceilPowerOfTwo4(value: usize) usize { if (value <= 2) return value; const Shift = comptime std.math.Log2Int(usize); return usize(1) << @intCast(Shift, usize.bit_count - @clz(usize, value - 1)); }
0
repos/zee_alloc
repos/zee_alloc/docs/data.js
zigAnalysis={"typeKinds": ["Type","Void","Bool","NoReturn","Int","Float","Pointer","Array","Struct","ComptimeFloat","ComptimeInt","Undefined","Null","Optional","ErrorUnion","ErrorSet","Enum","Union","Fn","BoundFn","Opaque","Frame","AnyFrame","Vector","EnumLiteral"],"params": {"zigId": "NYx2YuytuVj96GkUTKJVuunvTBFyX8ibOEiW7JYLrwERG4FaZL8w_OXm9JFDSj1j","zigVersion": "0.6.0+dc4fea983","builds": [{"target": "wasm32-freestanding-musl"}],"rootName": "wasm_exports"},"rootPkg": 0,"calls": [{"fn": 40,"result": {"type": 33,"value": 34},"args": [{"type": 33,"value": 35}]},{"fn": 41,"result": {"type": 37,"value": null},"args": [{"type": 33,"value": 38}]},{"fn": 1,"result": {"type": 39,"value": "undefined"},"args": [{"type": 40,"value": null}]},{"fn": 42,"result": {"type": 37,"value": null},"args": [{"type": 37,"value": null},{"type": 37,"value": null}]},{"fn": 43,"result": {"type": 33,"value": 43},"args": [{"type": 40,"value": null},{"type": 44,"value": 5}]},{"fn": 43,"result": {"type": 33,"value": 35},"args": [{"type": 40,"value": null},{"type": 44,"value": 160}]},{"fn": 43,"result": {"type": 33,"value": 34},"args": [{"type": 40,"value": null},{"type": 44,"value": 8}]},{"fn": 44,"result": {"type": 40,"value": null},"args": [{"type": 46,"value": null}]},{"fn": 45,"result": {"type": 33,"value": 48},"args": [{"type": 49,"value": null}]},{"fn": 46,"result": {"type": 39,"value": "undefined"},"args": [{"type": 51,"value": null}]},{"fn": 40,"result": {"type": 33,"value": 43},"args": [{"type": 33,"value": 38}]},{"fn": 47,"result": {"type": 33,"value": 38},"args": [{"type": 33,"value": 38},{"type": 33,"value": 38}]},{"fn": 47,"result": {"type": 33,"value": 43},"args": [{"type": 33,"value": 43},{"type": 33,"value": 43}]},{"fn": 48,"result": {"type": 40,"value": null},"args": [{"type": 38,"value": 65536}]},{"fn": 49,"result": {"type": 40,"value": null},"args": [{"type": 46,"value": null}]},{"fn": 50,"result": {"type": 43,"value": 4},"args": [{"type": 33,"value": 38},{"type": 38,"value": 16}]},{"fn": 50,"result": {"type": 43,"value": 16},"args": [{"type": 33,"value": 38},{"type": 38,"value": 65536}]}],"packages": [{"name": "","file": 0,"main": 56,"table": {"builtin": 1,"std": 2,"root": 0}},{"name": "builtin","file": 1,"main": 57,"table": {"std": 2}},{"name": "std","file": 2,"main": 58,"table": {"builtin": 1,"std": 2,"root": 0}}],"types": [{"kind": 18,"name": "fn([]const u8, ?*std.builtin.StackTrace) noreturn","generic": false,"ret": 59,"args": [60,61]},{"kind": 18,"name": "fn(bool) void","generic": false,"ret": 39,"args": [40]},{"kind": 18,"name": "fn(*std.mem.Allocator) main.ZeeAlloc((struct main.Config constant))","generic": false,"ret": 48,"args": [62]},{"kind": 18,"name": "fn(*std.mem.Allocator, []u8, u29, usize, u29) std.mem.Error![]u8","generic": false,"ret": 63,"args": [62,64,65,38,65]},{"kind": 18,"name": "fn() main.FreeList","generic": false,"ret": 66},{"kind": 18,"name": "fn(*std.mem.Allocator, []u8, u29, usize, u29) []u8","generic": false,"ret": 64,"args": [62,64,65,38,65]},{"kind": 18,"name": "fn(usize) callconv(.C) ?*c_void","generic": false,"ret": 67,"args": [38]},{"kind": 18,"name": "fn(usize, usize) callconv(.C) ?*c_void","generic": false,"ret": 67,"args": [38,38]},{"kind": 18,"name": "fn(?*c_void, usize) callconv(.C) ?*c_void","generic": false,"ret": 67,"args": [67,38]},{"kind": 18,"name": "fn(?*c_void) callconv(.C) void","generic": false,"ret": 39,"args": [67]},{"kind": 18,"name": "fn([*]u8) @TypeOf(main.Frame.restorePayload).ReturnType.ErrorSet!*main.Frame","generic": false,"ret": 68,"args": [69]},{"kind": 18,"name": "fn(*main.Frame) usize","generic": false,"ret": 38,"args": [70]},{"kind": 18,"name": "fn(*main.Frame, usize, usize) []u8","generic": false,"ret": 64,"args": [70,38,38]},{"kind": 18,"name": "fn(*main.ZeeAlloc((struct main.Config constant)), usize) ?*main.Frame","generic": false,"ret": 71,"args": [72,38]},{"kind": 18,"name": "fn(*main.ZeeAlloc((struct main.Config constant)), usize) @TypeOf(main.ZeeAlloc((struct main.Config constant)).allocNode).ReturnType.ErrorSet!*main.Frame","generic": false,"ret": 73,"args": [72,38]},{"kind": 18,"name": "fn(usize) usize","generic": false,"ret": 38,"args": [38]},{"kind": 18,"name": "fn([]u8) *main.Frame","generic": false,"ret": 70,"args": [64]},{"kind": 18,"name": "fn(*main.Frame) void","generic": false,"ret": 39,"args": [70]},{"kind": 18,"name": "fn(*main.ZeeAlloc((struct main.Config constant)), *main.Frame, usize) []u8","generic": false,"ret": 64,"args": [72,70,38]},{"kind": 18,"name": "fn([]u8, []const u8) void","generic": false,"ret": 39,"args": [64,60]},{"kind": 18,"name": "fn(*main.ZeeAlloc((struct main.Config constant)), *main.Frame) void","generic": false,"ret": 39,"args": [72,70]},{"kind": 18,"name": "fn(*main.Frame) bool","generic": false,"ret": 40,"args": [70]},{"kind": 18,"name": "fn(*main.Frame) @TypeOf(main.Frame.validate).ReturnType.ErrorSet!void","generic": false,"ret": 74,"args": [70]},{"kind": 18,"name": "fn(usize) bool","generic": false,"ret": 40,"args": [38]},{"kind": 18,"name": "fn(*main.ZeeAlloc((struct main.Config constant)), usize) usize","generic": false,"ret": 38,"args": [72,38]},{"kind": 18,"name": "fn(*main.FreeList) *main.Frame","generic": false,"ret": 70,"args": [75]},{"kind": 18,"name": "fn(*main.FreeList, *main.Frame) *main.Frame","generic": false,"ret": 70,"args": [75,70]},{"kind": 18,"name": "fn(*main.ZeeAlloc((struct main.Config constant)), usize) *main.FreeList","generic": false,"ret": 75,"args": [72,38]},{"kind": 18,"name": "fn(*main.FreeList, *main.Frame) void","generic": false,"ret": 39,"args": [75,70]},{"kind": 18,"name": "fn(usize, usize) usize","generic": false,"ret": 38,"args": [38,38]},{"kind": 18,"name": "fn(usize) u5","generic": false,"ret": 43,"args": [38]},{"kind": 18,"name": "fn(u5, u5) u5","generic": false,"ret": 43,"args": [43,43]},{"kind": 18,"name": "fn(type) var","generic": true,"args": [33]},{"kind": 0},{"kind": 4,"u": 8},{"kind": 4,"u": 160},{"kind": 18,"name": "fn(type) var","generic": true,"args": [33]},{"kind": 10,"name": "comptime_int"},{"kind": 4,"u": 32},{"kind": 1,"name": "void"},{"kind": 2},{"kind": 18,"name": "fn(var,var) var","generic": true,"args": [null,null]},{"kind": 18,"name": "fn(bool,var) var","generic": true,"args": [40,null]},{"kind": 4,"u": 5},{"kind": 4,"u": 16},{"kind": 18,"name": "fn(main.Validation) var","generic": true,"args": [46]},{"kind": 16,"name": "main.Validation","src": 48,"pubDecls": [],"privDecls": [0,1,2,3],"fields": [0,1,2]},{"kind": 18,"name": "fn(main.Config) var","generic": true,"args": [49]},{"kind": 8,"name": "main.ZeeAlloc((struct main.Config constant))","src": 49,"pubDecls": [4,5],"privDecls": [6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25],"fields": [62,82,83]},{"kind": 8,"name": "main.Config","src": 50,"pubDecls": [26,27,28,29],"privDecls": [],"fields": [38,46,84,86,85]},{"kind": 18,"name": "fn(main.ExportC) var","generic": true,"args": [51]},{"kind": 8,"name": "main.ExportC","src": 51,"pubDecls": [30],"privDecls": [],"fields": [62,40,40,40,40]},{"kind": 18,"name": "fn(type,var) var","generic": true,"args": [33,null]},{"kind": 18,"name": "fn(var) var","generic": true,"args": [null]},{"kind": 18,"name": "fn(main.Validation) var","generic": true,"args": [46]},{"kind": 18,"name": "fn(type,var) var","generic": true,"args": [33,null]},{"kind": 8,"name": "(root)","src": 52,"pubDecls": [31,32,33,34],"privDecls": [35,36,37],"file": 0},{"kind": 8,"name": "builtin","src": 53,"pubDecls": [38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83],"privDecls": [],"file": 1},{"kind": 8,"name": "std","src": 54,"pubDecls": [84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153],"privDecls": [],"file": 2},{"kind": 3,"name": "noreturn"},{"kind": 6,"len": 2,"const": true,"elem": 34},{"kind": 13,"child": 106},{"kind": 6,"elem": 83},{"kind": 14,"err": 107,"payload": 64},{"kind": 6,"len": 2,"elem": 34},{"kind": 4,"u": 29},{"kind": 8,"name": "main.FreeList","src": 55,"pubDecls": [154,155,156,157,158],"privDecls": [],"fields": [71]},{"kind": 13,"child": 108},{"kind": 14,"err": 109,"payload": 70},{"kind": 6,"len": 1,"elem": 34},{"kind": 6,"elem": 80},{"kind": 13,"child": 70},{"kind": 6,"elem": 48},{"kind": 14,"err": 110,"payload": 70},{"kind": 14,"err": 111,"payload": 39},{"kind": 6,"elem": 66},{"kind": 8,"name": "main","src": 56,"pubDecls": [34,32,33,31],"privDecls": [159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174],"file": 3},{"kind": 18,"name": "fn(main.Validation,var) var","generic": true,"args": [46,null]},{"kind": 18,"name": "fn(main.Validation,var) var","generic": true,"args": [46,null]},{"kind": 18,"name": "fn(type,var) var","generic": true,"args": [33,null]},{"kind": 8,"name": "main.Frame","src": 57,"pubDecls": [175,176,177,178,179,180,181,182],"privDecls": [183,184,185],"fields": [71,38,114]},{"kind": 18,"name": "fn(type,var) var","generic": true,"args": [33,null]},{"kind": 7,"len": 14,"elem": 66},{"kind": 8,"name": "std.mem.Allocator","src": 58,"pubDecls": [186,187,188,189,190,191,192,193,194,195,196,197,198,199],"privDecls": [200],"fields": [3,5]},{"kind": 16,"name": "main.JumboMatchStrategy","src": 59,"pubDecls": [],"privDecls": [],"fields": [0,1,2]},{"kind": 16,"name": "main.ShrinkStrategy","src": 60,"pubDecls": [],"privDecls": [],"fields": [0,1,2]},{"kind": 16,"name": "main.BuddyStrategy","src": 61,"pubDecls": [],"privDecls": [],"fields": [0,1]},{"kind": 8,"name": "std.builtin","src": 62,"pubDecls": [38,40,39,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,60,59,62,61,63,64,65,67,66,68,69,70,71,72,73,75,74,76,77,78,79,80,81,82,83],"privDecls": [201,202],"file": 4},{"kind": 16,"name": "std.builtin.OutputMode","src": 63,"pubDecls": [],"privDecls": [],"fields": [0,1,2]},{"kind": 16,"name": "std.builtin.Mode","src": 64,"pubDecls": [],"privDecls": [],"fields": [0,1,2,3]},{"kind": 8,"name": "std.target.Os","src": 65,"pubDecls": [203,204,205,206,207,208],"privDecls": [],"fields": [116,119]},{"kind": 8,"name": "std.builtin.StackTrace","src": 66,"pubDecls": [],"privDecls": [],"fields": [38,120]},{"kind": 16,"name": "std.builtin.CallingConvention","src": 67,"pubDecls": [],"privDecls": [],"fields": [0,1,2,3,4,5,6,7,8,9,10,11,12,13]},{"kind": 8,"name": "std.builtin.CallOptions","src": 68,"pubDecls": [209],"privDecls": [],"fields": [121,122]},{"kind": 8,"name": "std.builtin.Version","src": 69,"pubDecls": [210,211,212,213],"privDecls": [],"fields": [124,124,124]},{"kind": 16,"name": "std.builtin.GlobalLinkage","src": 70,"pubDecls": [],"privDecls": [],"fields": [0,1,2,3]},{"kind": 17,"name": "std.builtin.TypeInfo","src": 71,"pubDecls": [214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233],"privDecls": [],"fields": [39,39,39,39,144,137,128,126,125,39,39,39,39,134,127,133,135,132,142,142,39,39,140,136,39]},{"kind": 16,"name": "std.builtin.LinkMode","src": 72,"pubDecls": [],"privDecls": [],"fields": [0,1]},{"kind": 8,"name": "std.builtin.ExportOptions","src": 73,"pubDecls": [],"privDecls": [],"fields": [60,95,145]},{"kind": 16,"name": "std.target.Arch","src": 74,"pubDecls": [234,235,236,237,238,239,240,241,242,243,244,245],"privDecls": [],"fields": [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50]},{"kind": 8,"name": "std.mem","src": 75,"pubDecls": [246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,322,323,324,325,326,327,328,329,330,331,332,333],"privDecls": [334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351],"file": 5},{"kind": 8,"name": "std.math","src": 76,"pubDecls": [352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380,381,382,383,384,385,386,387,388,389,390,391,392,393,394,395,396,397,398,399,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,440,441,442,443,444,445,446,447,448,449,450,451,452,453,454,455,456,457,458,459,460,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,478,479,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510],"privDecls": [511,512,513,514,515,516,517,518,519,520,521,522,523,524],"file": 6},{"kind": 8,"name": "std.debug","src": 77,"pubDecls": [525,526,527,528,529,530,531,532,533,534,535,536,537,538,539,540,541,542,543,544,545,546,547,548,549,550,551,552,553,554,555,556,557],"privDecls": [558,559,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,600,601,602,603,604,605,606,607,608,609],"file": 7},{"kind": 8,"name": "std.meta","src": 78,"pubDecls": [610,611,612,613,614,615,616,617,618,619,620,621,622,623,624,625,626,627,628,629,630,631,632,633,634],"privDecls": [635,636,637,638,639,640,641,642],"file": 8},{"kind": 8,"name": "std.start","src": 79,"pubDecls": [643],"privDecls": [644,645,646,647,648,649,650,651,652,653,654,655,656,657,658,659,660,661],"file": 9},{"kind": 8,"name": "std.target.Target","src": 80,"pubDecls": [662,663,664,665,666,667,668,669,670,671,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,687,688,689,690,691,692,693,694,695,696,697,698,699,700,701,702,703,704,705,706,707,708,709,710],"privDecls": [],"fields": [148,90,149]},{"kind": 6,"elem": 91},{"kind": 15,"name": "std.mem.Error","errors": [0]},{"kind": 6,"elem": 150},{"kind": 15,"name": "@TypeOf(main.Frame.restorePayload).ReturnType.ErrorSet","fn": 12,"errors": [1]},{"kind": 15,"name": "@TypeOf(main.ZeeAlloc((struct main.Config constant)).allocNode).ReturnType.ErrorSet","fn": 16,"errors": [0]},{"kind": 15,"name": "@TypeOf(main.Frame.validate).ReturnType.ErrorSet","fn": 25,"errors": [1]},{"kind": 18,"name": "fn(u32, u32) callconv(.C) i32","generic": false,"ret": 151,"args": [124,124]},{"kind": 18,"name": "fn(bool,var) var","generic": true,"args": [40,null]},{"kind": 7,"len": 8,"elem": 34},{"kind": 8,"name": "std.target","src": 81,"pubDecls": [711],"privDecls": [712,713,714,715],"file": 10},{"kind": 16,"name": "std.target.Tag","src": 82,"pubDecls": [716,717],"privDecls": [],"fields": [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36]},{"kind": 8,"name": "std.target.LinuxVersionRange","src": 83,"pubDecls": [718],"privDecls": [],"fields": [123,94]},{"kind": 16,"name": "std.target.WindowsVersion","src": 84,"pubDecls": [719],"privDecls": [],"fields": [67108864,83886080,83951616,84017152,100663296,100728832,100794368,100859904,167772160,167772161,167772162,167772163,167772164,167772165,167772166,167772167]},{"kind": 17,"name": "std.target.VersionRange","src": 85,"pubDecls": [720],"privDecls": [],"fields": [39,123,117,152]},{"kind": 6,"len": 2,"elem": 38},{"kind": 16,"name": "std.builtin.Modifier","src": 86,"pubDecls": [],"privDecls": [],"fields": [0,1,2,3,4,5,6,7]},{"kind": 13,"child": 153},{"kind": 8,"name": "std.builtin.Range","src": 87,"pubDecls": [721],"privDecls": [],"fields": [94,94]},{"kind": 4,"u": 32},{"kind": 8,"name": "std.builtin.Struct","src": 88,"pubDecls": [],"privDecls": [],"fields": [130,154,155]},{"kind": 8,"name": "std.builtin.Array","src": 89,"pubDecls": [],"privDecls": [],"fields": [37,33,156]},{"kind": 8,"name": "std.builtin.ErrorUnion","src": 90,"pubDecls": [],"privDecls": [],"fields": [33,33]},{"kind": 8,"name": "std.builtin.Pointer","src": 91,"pubDecls": [722],"privDecls": [],"fields": [157,40,40,37,33,40,156]},{"kind": 8,"name": "std.builtin.EnumField","src": 92,"pubDecls": [],"privDecls": [],"fields": [60,37]},{"kind": 16,"name": "std.builtin.ContainerLayout","src": 93,"pubDecls": [],"privDecls": [],"fields": [0,1,2]},{"kind": 8,"name": "std.builtin.Declaration","src": 94,"pubDecls": [723],"privDecls": [],"fields": [60,40,158]},{"kind": 8,"name": "std.builtin.Union","src": 95,"pubDecls": [],"privDecls": [],"fields": [130,159,160,155]},{"kind": 13,"child": 161},{"kind": 8,"name": "std.builtin.Optional","src": 96,"pubDecls": [],"privDecls": [],"fields": [33]},{"kind": 8,"name": "std.builtin.Enum","src": 97,"pubDecls": [],"privDecls": [],"fields": [130,33,162,155,40]},{"kind": 8,"name": "std.builtin.Vector","src": 98,"pubDecls": [],"privDecls": [],"fields": [37,33]},{"kind": 8,"name": "std.builtin.Float","src": 99,"pubDecls": [],"privDecls": [],"fields": [37]},{"kind": 8,"name": "std.builtin.UnionField","src": 100,"pubDecls": [],"privDecls": [],"fields": [60,163,33]},{"kind": 8,"name": "std.builtin.StructField","src": 101,"pubDecls": [],"privDecls": [],"fields": [60,164,33,156]},{"kind": 8,"name": "std.builtin.AnyFrame","src": 102,"pubDecls": [],"privDecls": [],"fields": [159]},{"kind": 8,"name": "std.builtin.Error","src": 103,"pubDecls": [],"privDecls": [],"fields": [60,37]},{"kind": 8,"name": "std.builtin.Fn","src": 104,"pubDecls": [],"privDecls": [],"fields": [92,40,40,159,165]},{"kind": 8,"name": "std.builtin.FnArg","src": 105,"pubDecls": [],"privDecls": [],"fields": [40,40,159]},{"kind": 8,"name": "std.builtin.Int","src": 106,"pubDecls": [],"privDecls": [],"fields": [40,37]},{"kind": 13,"child": 60},{"kind": 18,"name": "fn(type,var,var) var","generic": true,"args": [33,null,null]},{"kind": 18,"name": "fn(var,var) var","generic": true,"args": [null,null]},{"kind": 8,"name": "std.target.Cpu","src": 107,"pubDecls": [724,725,726,727],"privDecls": [],"fields": [99,168,169]},{"kind": 16,"name": "std.target.Abi","src": 108,"pubDecls": [728,729,730,731],"privDecls": [],"fields": [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]},{"kind": 20,"name": "c_void"},{"kind": 4,"i": 32},{"kind": 8,"name": "std.target.Range","src": 109,"pubDecls": [732],"privDecls": [],"fields": [118,118]},{"kind": 6,"len": 2,"align": 16,"elem": 34},{"kind": 6,"len": 2,"elem": 139},{"kind": 6,"len": 2,"elem": 131},{"kind": 20,"name": "(var)"},{"kind": 16,"name": "std.builtin.Size","src": 110,"pubDecls": [],"privDecls": [],"fields": [0,1,2,3]},{"kind": 17,"name": "std.builtin.Data","src": 111,"pubDecls": [733],"privDecls": [],"fields": [33,33,170]},{"kind": 13,"child": 33},{"kind": 6,"len": 2,"elem": 138},{"kind": 6,"len": 2,"elem": 141},{"kind": 6,"len": 2,"elem": 129},{"kind": 13,"child": 129},{"kind": 13,"child": 37},{"kind": 6,"len": 2,"elem": 143},{"kind": 8,"name": "std.target.Model","src": 112,"pubDecls": [734,735,736],"privDecls": [],"fields": [60,171,169]},{"kind": 8,"name": "std.target.Feature","src": 113,"pubDecls": [737,738],"privDecls": [],"fields": [34,60,171,60,169]},{"kind": 6,"const": true,"elem": 166},{"kind": 8,"name": "std.target.Set","src": 114,"pubDecls": [739,740,741,742,743,744,745,746,747,748,749,750,751,752,753,754],"privDecls": [],"fields": [172]},{"kind": 8,"name": "std.builtin.FnDecl","src": 115,"pubDecls": [755],"privDecls": [],"fields": [33,173,40,40,40,145,33,174]},{"kind": 13,"child": 175},{"kind": 7,"len": 5,"elem": 38},{"kind": 16,"name": "std.builtin.Inline","src": 116,"pubDecls": [],"privDecls": [],"fields": [0,1,2]},{"kind": 6,"len": 2,"elem": 60},{"kind": 6,"len": 2,"const": true,"elem": 34}],"decls": [{"import": 76,"src": 24,"name": "assertExternal","kind": "const","type": 77,"value": 51},{"import": 76,"src": 27,"name": "assertInternal","kind": "const","type": 78,"value": 52},{"import": 76,"src": 42,"name": "useExternal","kind": "const","type": 45,"value": 44},{"import": 76,"src": 46,"name": "useInternal","kind": "const","type": 54,"value": 49},{"import": 76,"src": 117,"name": "wasm_allocator","kind": "const","type": 62,"value": null},{"import": 76,"src": 2,"name": "init","kind": "const","type": 2,"value": 2},{"import": 76,"src": 36,"name": "unsafeCeilPowerOfTwo","kind": "const","type": 79,"value": 53},{"import": 76,"src": 16,"name": "allocNode","kind": "const","type": 14,"value": 16},{"import": 76,"src": 5,"name": "realloc","kind": "const","type": 3,"value": 5},{"import": 76,"src": 118,"name": "Frame","kind": "const","type": 33,"value": 80},{"import": 76,"src": 119,"name": "config","kind": "const","type": 49,"value": null},{"import": 76,"src": 32,"name": "freeListOfSize","kind": "const","type": 27,"value": 32},{"import": 76,"src": 38,"name": "unsafeLog2Int","kind": "const","type": 81,"value": 54},{"import": 76,"src": 120,"name": "debugCountAll"},{"import": 76,"src": 121,"name": "Self","kind": "const","type": 33,"value": 48},{"import": 76,"src": 122,"name": "debugCount"},{"import": 76,"src": 29,"name": "freeListIndex","kind": "const","type": 24,"value": 29},{"import": 76,"src": 22,"name": "free","kind": "const","type": 20,"value": 22},{"import": 76,"src": 123,"name": "_wasm","kind": "var","type": 48,"value": null},{"import": 76,"src": 17,"name": "unsafeAlignForward","kind": "const","type": 15,"value": 17},{"import": 76,"src": 124,"name": "FreeList","kind": "const","type": 33,"value": 66},{"import": 76,"src": 20,"name": "chunkify","kind": "const","type": 18,"value": 20},{"import": 76,"src": 28,"name": "padToFrameSize","kind": "const","type": 24,"value": 28},{"import": 76,"src": 6,"name": "shrink","kind": "const","type": 5,"value": 6},{"import": 76,"src": 15,"name": "findFreeNode","kind": "const","type": 13,"value": 15},{"import": 76,"src": 125,"name": "debugDump"},{"import": 76,"src": 126,"name": "JumboMatchStrategy","kind": "const","type": 33,"value": 84},{"import": 76,"src": 127,"name": "Validation","kind": "const","type": 33,"value": 46},{"import": 76,"src": 128,"name": "ShrinkStrategy","kind": "const","type": 33,"value": 85},{"import": 76,"src": 129,"name": "BuddyStrategy","kind": "const","type": 33,"value": 86},{"import": 76,"src": 44,"name": "run","kind": "const","type": 50,"value": 46},{"import": 76,"src": 130,"name": "ExportC","kind": "const","type": 33,"value": 51},{"import": 76,"src": 131,"name": "ZeeAllocDefaults","kind": "const","type": 33,"value": 48},{"import": 76,"src": 132,"name": "Config","kind": "const","type": 33,"value": 49},{"import": 76,"src": 43,"name": "ZeeAlloc","kind": "const","type": 47,"value": 45},{"import": 56,"src": 133,"name": "builtin"},{"import": 56,"src": 134,"name": "std"},{"import": 56,"src": 135,"name": "zee_alloc","kind": "const","type": 33,"value": 76},{"import": 87,"src": 136,"name": "CodeModel"},{"import": 57,"src": 137,"name": "code_model"},{"import": 87,"src": 0,"name": "default_panic","kind": "const","type": 0,"value": 0},{"import": 87,"src": 138,"name": "OutputMode","kind": "const","type": 33,"value": 88},{"import": 57,"src": 139,"name": "cpu"},{"import": 57,"src": 140,"name": "mode","kind": "const","type": 89,"value": null},{"import": 57,"src": 141,"name": "os","kind": "const","type": 90,"value": null},{"import": 57,"src": 142,"name": "abi"},{"import": 87,"src": 143,"name": "StackTrace","kind": "const","type": 33,"value": 91},{"import": 57,"src": 144,"name": "output_mode","kind": "const","type": 88,"value": null},{"import": 87,"src": 145,"name": "CallingConvention","kind": "const","type": 33,"value": 92},{"import": 87,"src": 146,"name": "Cpu"},{"import": 87,"src": 147,"name": "CallOptions","kind": "const","type": 33,"value": 93},{"import": 87,"src": 148,"name": "Mode","kind": "const","type": 33,"value": 89},{"import": 87,"src": 149,"name": "TestFn"},{"import": 87,"src": 150,"name": "Os","kind": "const","type": 33,"value": 90},{"import": 87,"src": 151,"name": "Version","kind": "const","type": 33,"value": 94},{"import": 87,"src": 152,"name": "GlobalLinkage","kind": "const","type": 33,"value": 95},{"import": 87,"src": 153,"name": "Abi"},{"import": 57,"src": 154,"name": "have_error_return_tracing"},{"import": 87,"src": 155,"name": "TypeInfo","kind": "const","type": 33,"value": 96},{"import": 57,"src": 156,"name": "position_independent_code"},{"import": 87,"src": 157,"name": "AtomicRmwOp"},{"import": 57,"src": 158,"name": "link_libc"},{"import": 87,"src": 159,"name": "LinkMode","kind": "const","type": 33,"value": 97},{"import": 87,"src": 160,"name": "ExportOptions","kind": "const","type": 33,"value": 98},{"import": 57,"src": 161,"name": "object_format"},{"import": 57,"src": 162,"name": "arch","kind": "const","type": 99,"value": null},{"import": 57,"src": 163,"name": "endian"},{"import": 87,"src": 164,"name": "FloatMode"},{"import": 87,"src": 165,"name": "AtomicOrder"},{"import": 87,"src": 166,"name": "TypeId"},{"import": 87,"src": 167,"name": "ObjectFormat"},{"import": 57,"src": 168,"name": "is_test"},{"import": 87,"src": 169,"name": "Target"},{"import": 87,"src": 170,"name": "PanicFn","kind": "const","type": 33,"value": 0},{"import": 57,"src": 171,"name": "link_mode","kind": "const","type": 97,"value": null},{"import": 87,"src": 172,"name": "Arch","kind": "const","type": 33,"value": 99},{"import": 57,"src": 173,"name": "valgrind_support"},{"import": 87,"src": 174,"name": "SubSystem"},{"import": 87,"src": 175,"name": "subsystem"},{"import": 87,"src": 176,"name": "Endian"},{"import": 87,"src": 177,"name": "panic","kind": "const","type": 0,"value": 0},{"import": 57,"src": 178,"name": "link_libcpp"},{"import": 57,"src": 179,"name": "strip_debug_info"},{"import": 57,"src": 180,"name": "single_threaded"},{"import": 58,"src": 181,"name": "mem","kind": "const","type": 33,"value": 100},{"import": 58,"src": 182,"name": "DynLib"},{"import": 58,"src": 183,"name": "builtin","kind": "const","type": 33,"value": 87},{"import": 58,"src": 184,"name": "SinglyLinkedList"},{"import": 58,"src": 185,"name": "PackedIntArrayEndian"},{"import": 58,"src": 186,"name": "PackedIntArray"},{"import": 58,"src": 187,"name": "math","kind": "const","type": 33,"value": 101},{"import": 58,"src": 188,"name": "Thread"},{"import": 58,"src": 189,"name": "ArrayListAlignedUnmanaged"},{"import": 58,"src": 190,"name": "BufSet"},{"import": 58,"src": 191,"name": "ArrayListSentineled"},{"import": 58,"src": 192,"name": "fifo"},{"import": 58,"src": 193,"name": "os"},{"import": 58,"src": 194,"name": "debug","kind": "const","type": 33,"value": 102},{"import": 58,"src": 195,"name": "dwarf"},{"import": 58,"src": 196,"name": "testing"},{"import": 58,"src": 197,"name": "event"},{"import": 58,"src": 198,"name": "unicode"},{"import": 58,"src": 199,"name": "ArrayListUnmanaged"},{"import": 58,"src": 200,"name": "build"},{"import": 58,"src": 201,"name": "http"},{"import": 58,"src": 202,"name": "elf"},{"import": 58,"src": 203,"name": "ComptimeStringMap"},{"import": 58,"src": 204,"name": "SegmentedList"},{"import": 58,"src": 205,"name": "ascii"},{"import": 58,"src": 206,"name": "io"},{"import": 58,"src": 207,"name": "ChildProcess"},{"import": 58,"src": 208,"name": "hash_map"},{"import": 58,"src": 209,"name": "fmt"},{"import": 58,"src": 210,"name": "base64"},{"import": 58,"src": 211,"name": "atomic"},{"import": 58,"src": 212,"name": "TailQueue"},{"import": 58,"src": 213,"name": "json"},{"import": 58,"src": 214,"name": "once"},{"import": 58,"src": 215,"name": "ResetEvent"},{"import": 58,"src": 216,"name": "pdb"},{"import": 58,"src": 217,"name": "BufMap"},{"import": 58,"src": 218,"name": "coff"},{"import": 58,"src": 219,"name": "crypto"},{"import": 58,"src": 220,"name": "hash"},{"import": 58,"src": 221,"name": "sort"},{"import": 58,"src": 222,"name": "cache_hash"},{"import": 58,"src": 223,"name": "c"},{"import": 58,"src": 224,"name": "cstr"},{"import": 58,"src": 225,"name": "rb"},{"import": 58,"src": 226,"name": "rand"},{"import": 58,"src": 227,"name": "meta","kind": "const","type": 33,"value": 103},{"import": 58,"src": 228,"name": "net"},{"import": 58,"src": 229,"name": "fs"},{"import": 58,"src": 230,"name": "heap"},{"import": 58,"src": 231,"name": "start","kind": "const","type": 33,"value": 104},{"import": 58,"src": 232,"name": "ArrayListAligned"},{"import": 58,"src": 233,"name": "AutoHashMap"},{"import": 58,"src": 234,"name": "PriorityQueue"},{"import": 58,"src": 235,"name": "Mutex"},{"import": 58,"src": 236,"name": "time"},{"import": 58,"src": 237,"name": "Progress"},{"import": 58,"src": 238,"name": "Target","kind": "const","type": 33,"value": 105},{"import": 58,"src": 239,"name": "packed_int_array"},{"import": 58,"src": 240,"name": "valgrind"},{"import": 58,"src": 241,"name": "PackedIntSliceEndian"},{"import": 58,"src": 242,"name": "HashMap"},{"import": 58,"src": 243,"name": "zig"},{"import": 58,"src": 244,"name": "ArrayList"},{"import": 58,"src": 245,"name": "SpinLock"},{"import": 58,"src": 246,"name": "PackedIntSlice"},{"import": 58,"src": 247,"name": "process"},{"import": 58,"src": 248,"name": "macho"},{"import": 58,"src": 249,"name": "BloomFilter"},{"import": 58,"src": 250,"name": "StringHashMap"},{"import": 76,"src": 31,"name": "removeAfter","kind": "const","type": 26,"value": 31},{"import": 76,"src": 4,"name": "init","kind": "const","type": 4,"value": 4},{"import": 76,"src": 30,"name": "root","kind": "const","type": 25,"value": 30},{"import": 76,"src": 251,"name": "remove"},{"import": 76,"src": 33,"name": "prepend","kind": "const","type": 28,"value": 33},{"import": 76,"src": 252,"name": "builtin","kind": "const","type": 33,"value": 57},{"import": 76,"src": 253,"name": "page_index","kind": "const","type": 37,"value": null},{"import": 76,"src": 254,"name": "testAllocatorAligned"},{"import": 76,"src": 255,"name": "testAllocatorAlignedShrink"},{"import": 76,"src": 256,"name": "min_frame_size","kind": "const","type": 37,"value": null},{"import": 76,"src": 257,"name": "wasm_page_allocator","kind": "var","type": 83,"value": null},{"import": 76,"src": 258,"name": "std","kind": "const","type": 33,"value": 58},{"import": 76,"src": 259,"name": "testAllocator"},{"import": 76,"src": 260,"name": "testAllocatorLargeAlignment"},{"import": 76,"src": 261,"name": "llvm.wasm.memory.grow.i32","kind": "const","type": 112,"value": 55},{"import": 76,"src": 262,"name": "min_payload_size","kind": "const","type": 37,"value": null},{"import": 76,"src": 263,"name": "jumbo_index"},{"import": 76,"src": 264,"name": "testing"},{"import": 76,"src": 265,"name": "meta_size","kind": "const","type": 37,"value": null},{"import": 76,"src": 11,"name": "assertIf","kind": "const","type": 113,"value": 56},{"import": 76,"src": 266,"name": "Allocator","kind": "const","type": 33,"value": 83},{"import": 76,"src": 12,"name": "restorePayload","kind": "const","type": 10,"value": 12},{"import": 76,"src": 23,"name": "isAllocated","kind": "const","type": 21,"value": 23},{"import": 76,"src": 25,"name": "validate","kind": "const","type": 22,"value": 25},{"import": 76,"src": 267,"name": "restoreAddr"},{"import": 76,"src": 14,"name": "payloadSlice","kind": "const","type": 12,"value": 14},{"import": 76,"src": 18,"name": "init","kind": "const","type": 16,"value": 18},{"import": 76,"src": 19,"name": "markAllocated","kind": "const","type": 17,"value": 19},{"import": 76,"src": 13,"name": "payloadSize","kind": "const","type": 11,"value": 13},{"import": 76,"src": 26,"name": "isCorrectSize","kind": "const","type": 23,"value": 26},{"import": 76,"src": 268,"name": "alignment","kind": "const","type": 37,"value": null},{"import": 76,"src": 269,"name": "allocated_signal","kind": "const","type": 70,"value": null},{"import": 100,"src": 270,"name": "destroy"},{"import": 100,"src": 271,"name": "realloc"},{"import": 100,"src": 272,"name": "allocSentinel"},{"import": 100,"src": 273,"name": "shrink"},{"import": 100,"src": 274,"name": "Error","kind": "const","type": 33,"value": 107},{"import": 100,"src": 275,"name": "alignedShrink"},{"import": 100,"src": 276,"name": "alignedAlloc"},{"import": 100,"src": 277,"name": "alloc"},{"import": 100,"src": 278,"name": "alignedRealloc"},{"import": 100,"src": 279,"name": "dupe"},{"import": 100,"src": 280,"name": "dupeZ"},{"import": 100,"src": 281,"name": "free"},{"import": 100,"src": 282,"name": "allocWithOptions"},{"import": 100,"src": 283,"name": "create"},{"import": 100,"src": 284,"name": "AllocWithOptionsPayload"},{"import": 87,"src": 285,"name": "root","kind": "const","type": 33,"value": 56},{"import": 87,"src": 286,"name": "std","kind": "const","type": 33,"value": 58},{"import": 115,"src": 287,"name": "Tag","kind": "const","type": 33,"value": 116},{"import": 115,"src": 288,"name": "LinuxVersionRange","kind": "const","type": 33,"value": 117},{"import": 115,"src": 289,"name": "WindowsVersion","kind": "const","type": 33,"value": 118},{"import": 115,"src": 290,"name": "VersionRange","kind": "const","type": 33,"value": 119},{"import": 115,"src": 291,"name": "requiresLibC"},{"import": 115,"src": 292,"name": "defaultVersionRange"},{"import": 87,"src": 293,"name": "Modifier","kind": "const","type": 33,"value": 121},{"import": 87,"src": 294,"name": "Range","kind": "const","type": 33,"value": 123},{"import": 87,"src": 295,"name": "format"},{"import": 87,"src": 296,"name": "parse"},{"import": 87,"src": 297,"name": "order"},{"import": 87,"src": 298,"name": "Struct","kind": "const","type": 33,"value": 125},{"import": 87,"src": 299,"name": "Array","kind": "const","type": 33,"value": 126},{"import": 87,"src": 300,"name": "ErrorUnion","kind": "const","type": 33,"value": 127},{"import": 87,"src": 301,"name": "Pointer","kind": "const","type": 33,"value": 128},{"import": 87,"src": 302,"name": "EnumField","kind": "const","type": 33,"value": 129},{"import": 87,"src": 303,"name": "ContainerLayout","kind": "const","type": 33,"value": 130},{"import": 87,"src": 304,"name": "Declaration","kind": "const","type": 33,"value": 131},{"import": 87,"src": 305,"name": "Union","kind": "const","type": 33,"value": 132},{"import": 87,"src": 306,"name": "ErrorSet","kind": "const","type": 33,"value": 133},{"import": 87,"src": 307,"name": "Optional","kind": "const","type": 33,"value": 134},{"import": 87,"src": 308,"name": "Enum","kind": "const","type": 33,"value": 135},{"import": 87,"src": 309,"name": "Vector","kind": "const","type": 33,"value": 136},{"import": 87,"src": 310,"name": "Float","kind": "const","type": 33,"value": 137},{"import": 87,"src": 311,"name": "UnionField","kind": "const","type": 33,"value": 138},{"import": 87,"src": 312,"name": "StructField","kind": "const","type": 33,"value": 139},{"import": 87,"src": 313,"name": "AnyFrame","kind": "const","type": 33,"value": 140},{"import": 87,"src": 314,"name": "Error","kind": "const","type": 33,"value": 141},{"import": 87,"src": 315,"name": "Fn","kind": "const","type": 33,"value": 142},{"import": 87,"src": 316,"name": "FnArg","kind": "const","type": 33,"value": 143},{"import": 87,"src": 317,"name": "Int","kind": "const","type": 33,"value": 144},{"import": 115,"src": 318,"name": "genericName"},{"import": 115,"src": 319,"name": "isARM"},{"import": 115,"src": 320,"name": "allFeaturesList"},{"import": 115,"src": 321,"name": "ptrBitWidth"},{"import": 115,"src": 322,"name": "endian"},{"import": 115,"src": 323,"name": "isThumb"},{"import": 115,"src": 324,"name": "parseCpuModel"},{"import": 115,"src": 325,"name": "allCpuModels"},{"import": 115,"src": 326,"name": "toElfMachine"},{"import": 115,"src": 327,"name": "isRISCV"},{"import": 115,"src": 328,"name": "isWasm"},{"import": 115,"src": 329,"name": "isMIPS"},{"import": 100,"src": 330,"name": "toSlice"},{"import": 100,"src": 331,"name": "spanZ"},{"import": 100,"src": 332,"name": "set"},{"import": 100,"src": 333,"name": "writeIntSliceBig"},{"import": 100,"src": 334,"name": "reverse"},{"import": 100,"src": 335,"name": "readIntSliceNative"},{"import": 100,"src": 336,"name": "toBytes"},{"import": 100,"src": 337,"name": "rotate"},{"import": 100,"src": 338,"name": "len"},{"import": 100,"src": 339,"name": "sliceAsBytes"},{"import": 100,"src": 340,"name": "bytesToValue"},{"import": 100,"src": 341,"name": "writeIntForeign"},{"import": 100,"src": 342,"name": "toSliceConst"},{"import": 100,"src": 343,"name": "separate"},{"import": 100,"src": 344,"name": "dupeZ"},{"import": 100,"src": 345,"name": "SplitIterator"},{"import": 100,"src": 346,"name": "max"},{"import": 100,"src": 347,"name": "startsWith"},{"import": 100,"src": 348,"name": "bytesAsSlice"},{"import": 100,"src": 349,"name": "indexOfScalarPos"},{"import": 100,"src": 350,"name": "writeIntSliceNative"},{"import": 100,"src": 351,"name": "indexOf"},{"import": 100,"src": 21,"name": "copy","kind": "const","type": 146,"value": 57},{"import": 100,"src": 352,"name": "writeInt"},{"import": 100,"src": 353,"name": "alignForwardGeneric"},{"import": 100,"src": 354,"name": "swap"},{"import": 100,"src": 355,"name": "lastIndexOfScalar"},{"import": 100,"src": 356,"name": "writeIntSliceLittle"},{"import": 100,"src": 357,"name": "min"},{"import": 100,"src": 358,"name": "readIntNative"},{"import": 100,"src": 359,"name": "indexOfAnyPos"},{"import": 100,"src": 360,"name": "readIntSliceBig"},{"import": 100,"src": 361,"name": "writeIntLittle"},{"import": 100,"src": 362,"name": "lenZ"},{"import": 100,"src": 363,"name": "trimLeft"},{"import": 100,"src": 364,"name": "alignBackwardGeneric"},{"import": 100,"src": 365,"name": "asBytes"},{"import": 100,"src": 366,"name": "readVarInt"},{"import": 100,"src": 367,"name": "isAligned"},{"import": 100,"src": 368,"name": "writeIntSlice"},{"import": 100,"src": 369,"name": "dupe"},{"import": 100,"src": 370,"name": "join"},{"import": 100,"src": 371,"name": "concat"},{"import": 100,"src": 372,"name": "bytesAsValue"},{"import": 100,"src": 373,"name": "toNative"},{"import": 100,"src": 374,"name": "indexOfPos"},{"import": 100,"src": 375,"name": "nativeToLittle"},{"import": 100,"src": 376,"name": "alignBackward"},{"import": 100,"src": 377,"name": "readIntSlice"},{"import": 100,"src": 378,"name": "nativeTo"},{"import": 100,"src": 379,"name": "indexOfSentinel"},{"import": 100,"src": 380,"name": "zeroes"},{"import": 100,"src": 381,"name": "lastIndexOfAny"},{"import": 100,"src": 382,"name": "order"},{"import": 100,"src": 383,"name": "TokenIterator"},{"import": 100,"src": 384,"name": "littleToNative"},{"import": 100,"src": 385,"name": "bigToNative"},{"import": 100,"src": 386,"name": "alignForward"},{"import": 100,"src": 387,"name": "indexOfScalar"},{"import": 100,"src": 388,"name": "nativeToBig"},{"import": 100,"src": 389,"name": "writeIntNative"},{"import": 100,"src": 390,"name": "Allocator","kind": "const","type": 33,"value": 83},{"import": 100,"src": 391,"name": "indexOfAny"},{"import": 100,"src": 392,"name": "readIntBig"},{"import": 100,"src": 393,"name": "span"},{"import": 100,"src": 394,"name": "lessThan"},{"import": 100,"src": 395,"name": "endsWith"},{"import": 100,"src": 396,"name": "trim"},{"import": 100,"src": 397,"name": "tokenize"},{"import": 100,"src": 398,"name": "indexOfDiff"},{"import": 100,"src": 399,"name": "readIntForeign"},{"import": 100,"src": 400,"name": "writeIntSliceForeign"},{"import": 100,"src": 401,"name": "readIntSliceLittle"},{"import": 100,"src": 402,"name": "isAlignedGeneric"},{"import": 100,"src": 403,"name": "trimRight"},{"import": 100,"src": 404,"name": "secureZero"},{"import": 100,"src": 405,"name": "writeIntBig"},{"import": 100,"src": 406,"name": "zeroInit"},{"import": 100,"src": 407,"name": "Span"},{"import": 100,"src": 408,"name": "split"},{"import": 100,"src": 409,"name": "page_size","kind": "const","type": 37,"value": null},{"import": 100,"src": 410,"name": "lastIndexOf"},{"import": 100,"src": 411,"name": "readIntLittle"},{"import": 100,"src": 412,"name": "readIntSliceForeign"},{"import": 100,"src": 413,"name": "copyBackwards"},{"import": 100,"src": 414,"name": "allEqual"},{"import": 100,"src": 415,"name": "eql"},{"import": 100,"src": 416,"name": "readInt"},{"import": 100,"src": 417,"name": "failAllocator"},{"import": 100,"src": 418,"name": "failAllocatorRealloc"},{"import": 100,"src": 419,"name": "BytesAsSliceReturnType"},{"import": 100,"src": 420,"name": "BytesAsValueReturnType"},{"import": 100,"src": 421,"name": "testWriteIntImpl"},{"import": 100,"src": 422,"name": "meta"},{"import": 100,"src": 423,"name": "assert","kind": "const","type": 1,"value": 1},{"import": 100,"src": 424,"name": "builtin","kind": "const","type": 33,"value": 57},{"import": 100,"src": 425,"name": "AsBytesReturnType"},{"import": 100,"src": 426,"name": "math"},{"import": 100,"src": 427,"name": "debug","kind": "const","type": 33,"value": 102},{"import": 100,"src": 428,"name": "testing"},{"import": 100,"src": 429,"name": "SliceAsBytesReturnType"},{"import": 100,"src": 430,"name": "trait"},{"import": 100,"src": 431,"name": "testReadIntImpl"},{"import": 100,"src": 432,"name": "failAllocatorShrink"},{"import": 100,"src": 433,"name": "std","kind": "const","type": 33,"value": 58},{"import": 100,"src": 434,"name": "mem"},{"import": 101,"src": 435,"name": "ceil"},{"import": 101,"src": 436,"name": "isNan"},{"import": 101,"src": 437,"name": "isSignalNan"},{"import": 101,"src": 438,"name": "cosh"},{"import": 101,"src": 439,"name": "floor"},{"import": 101,"src": 440,"name": "nan_u128"},{"import": 101,"src": 441,"name": "modf64_result"},{"import": 101,"src": 442,"name": "hypot"},{"import": 101,"src": 443,"name": "inf_u16"},{"import": 101,"src": 444,"name": "absFloat"},{"import": 101,"src": 445,"name": "f64_true_min"},{"import": 101,"src": 446,"name": "rotr"},{"import": 101,"src": 447,"name": "absCast"},{"import": 101,"src": 448,"name": "cbrt"},{"import": 101,"src": 449,"name": "qnan_f64"},{"import": 101,"src": 450,"name": "Order"},{"import": 101,"src": 451,"name": "round"},{"import": 101,"src": 452,"name": "nan_f32"},{"import": 101,"src": 453,"name": "divFloor"},{"import": 101,"src": 454,"name": "ceilPowerOfTwo"},{"import": 101,"src": 455,"name": "mulWide"},{"import": 101,"src": 456,"name": "sinh"},{"import": 101,"src": 457,"name": "inf_u32"},{"import": 101,"src": 458,"name": "shr"},{"import": 101,"src": 459,"name": "asinh"},{"import": 101,"src": 40,"name": "maxInt","kind": "const","type": 36,"value": 41},{"import": 101,"src": 460,"name": "sin"},{"import": 101,"src": 461,"name": "f64_toint"},{"import": 101,"src": 462,"name": "cast"},{"import": 101,"src": 463,"name": "f128_true_min"},{"import": 101,"src": 464,"name": "two_sqrtpi"},{"import": 101,"src": 465,"name": "acosh"},{"import": 101,"src": 466,"name": "frexp32_result"},{"import": 101,"src": 467,"name": "Complex"},{"import": 101,"src": 468,"name": "raiseOverflow"},{"import": 101,"src": 469,"name": "inf_f128"},{"import": 101,"src": 470,"name": "inf"},{"import": 101,"src": 39,"name": "Log2Int","kind": "const","type": 32,"value": 40},{"import": 101,"src": 47,"name": "log2_int","kind": "const","type": 55,"value": 50},{"import": 101,"src": 471,"name": "add"},{"import": 101,"src": 472,"name": "atanh"},{"import": 101,"src": 473,"name": "lossyCast"},{"import": 101,"src": 474,"name": "modf"},{"import": 101,"src": 475,"name": "mod"},{"import": 101,"src": 476,"name": "f32_max"},{"import": 101,"src": 477,"name": "sqrt1_2"},{"import": 101,"src": 478,"name": "order"},{"import": 101,"src": 479,"name": "tan"},{"import": 101,"src": 480,"name": "ilogb"},{"import": 101,"src": 481,"name": "cos"},{"import": 101,"src": 482,"name": "f64_epsilon"},{"import": 101,"src": 483,"name": "inf_u64"},{"import": 101,"src": 484,"name": "asin"},{"import": 101,"src": 34,"name": "isPowerOfTwo","kind": "const","type": 53,"value": 48},{"import": 101,"src": 485,"name": "nan_u16"},{"import": 101,"src": 486,"name": "inf_f32"},{"import": 101,"src": 487,"name": "f32_true_min"},{"import": 101,"src": 488,"name": "fabs"},{"import": 101,"src": 489,"name": "complex"},{"import": 101,"src": 490,"name": "clamp"},{"import": 101,"src": 491,"name": "atan"},{"import": 101,"src": 492,"name": "raiseDivByZero"},{"import": 101,"src": 493,"name": "snan"},{"import": 101,"src": 494,"name": "f16_true_min"},{"import": 101,"src": 495,"name": "isNegativeInf"},{"import": 101,"src": 496,"name": "log10e"},{"import": 101,"src": 497,"name": "f32_toint"},{"import": 101,"src": 498,"name": "pow"},{"import": 101,"src": 499,"name": "log2"},{"import": 101,"src": 500,"name": "inf_f64"},{"import": 101,"src": 501,"name": "log2_int_ceil"},{"import": 101,"src": 502,"name": "scalbn"},{"import": 101,"src": 503,"name": "qnan_u64"},{"import": 101,"src": 504,"name": "e"},{"import": 101,"src": 505,"name": "ceilPowerOfTwoPromote"},{"import": 101,"src": 506,"name": "f16_min"},{"import": 101,"src": 507,"name": "expm1"},{"import": 101,"src": 508,"name": "signbit"},{"import": 101,"src": 509,"name": "shlExact"},{"import": 101,"src": 510,"name": "nan_f128"},{"import": 101,"src": 511,"name": "frexp"},{"import": 101,"src": 512,"name": "qnan_f32"},{"import": 101,"src": 513,"name": "qnan_u16"},{"import": 101,"src": 514,"name": "f32_min"},{"import": 101,"src": 515,"name": "frexp64_result"},{"import": 101,"src": 516,"name": "CompareOperator"},{"import": 101,"src": 517,"name": "f16_epsilon"},{"import": 101,"src": 518,"name": "rem"},{"import": 101,"src": 519,"name": "qnan_u32"},{"import": 101,"src": 520,"name": "ln10"},{"import": 101,"src": 521,"name": "qnan_u128"},{"import": 101,"src": 522,"name": "sub"},{"import": 101,"src": 523,"name": "floatMantissaBits"},{"import": 101,"src": 35,"name": "max","kind": "const","type": 41,"value": 42},{"import": 101,"src": 524,"name": "nan_u32"},{"import": 101,"src": 525,"name": "acos"},{"import": 101,"src": 526,"name": "f16_max"},{"import": 101,"src": 527,"name": "floorPowerOfTwo"},{"import": 101,"src": 528,"name": "exp"},{"import": 101,"src": 529,"name": "qnan_f16"},{"import": 101,"src": 530,"name": "f64_min"},{"import": 101,"src": 531,"name": "log10"},{"import": 101,"src": 532,"name": "nan_f16"},{"import": 101,"src": 533,"name": "f128_toint"},{"import": 101,"src": 534,"name": "IntFittingRange"},{"import": 101,"src": 535,"name": "nan_u64"},{"import": 101,"src": 536,"name": "rotl"},{"import": 101,"src": 537,"name": "sqrt2"},{"import": 101,"src": 538,"name": "log"},{"import": 101,"src": 539,"name": "raiseUnderflow"},{"import": 101,"src": 37,"name": "min","kind": "const","type": 147,"value": 58},{"import": 101,"src": 540,"name": "minInt"},{"import": 101,"src": 541,"name": "negate"},{"import": 101,"src": 542,"name": "qnan_f128"},{"import": 101,"src": 543,"name": "alignCast"},{"import": 101,"src": 544,"name": "f16_toint"},{"import": 101,"src": 545,"name": "isInf"},{"import": 101,"src": 546,"name": "modf32_result"},{"import": 101,"src": 547,"name": "f128_epsilon"},{"import": 101,"src": 548,"name": "mul"},{"import": 101,"src": 549,"name": "f128_min"},{"import": 101,"src": 550,"name": "divExact"},{"import": 101,"src": 551,"name": "negateCast"},{"import": 101,"src": 552,"name": "isFinite"},{"import": 101,"src": 553,"name": "nan_f64"},{"import": 101,"src": 554,"name": "f128_max"},{"import": 101,"src": 555,"name": "f32_epsilon"},{"import": 101,"src": 556,"name": "forceEval"},{"import": 101,"src": 557,"name": "isNormal"},{"import": 101,"src": 558,"name": "raiseInvalid"},{"import": 101,"src": 559,"name": "compare"},{"import": 101,"src": 560,"name": "shl"},{"import": 101,"src": 561,"name": "ln2"},{"import": 101,"src": 562,"name": "big"},{"import": 101,"src": 563,"name": "f64_max"},{"import": 101,"src": 564,"name": "inf_f16"},{"import": 101,"src": 565,"name": "nan"},{"import": 101,"src": 566,"name": "raiseInexact"},{"import": 101,"src": 567,"name": "inf_u128"},{"import": 101,"src": 568,"name": "copysign"},{"import": 101,"src": 569,"name": "fma"},{"import": 101,"src": 570,"name": "isPositiveInf"},{"import": 101,"src": 571,"name": "sqrt"},{"import": 101,"src": 572,"name": "tanh"},{"import": 101,"src": 573,"name": "approxEq"},{"import": 101,"src": 574,"name": "trunc"},{"import": 101,"src": 575,"name": "floatExponentBits"},{"import": 101,"src": 576,"name": "tau"},{"import": 101,"src": 577,"name": "exp2"},{"import": 101,"src": 578,"name": "log1p"},{"import": 101,"src": 579,"name": "AlignCastError"},{"import": 101,"src": 580,"name": "pi"},{"import": 101,"src": 581,"name": "log2e"},{"import": 101,"src": 582,"name": "powi"},{"import": 101,"src": 583,"name": "absInt"},{"import": 101,"src": 584,"name": "divTrunc"},{"import": 101,"src": 585,"name": "atan2"},{"import": 101,"src": 45,"name": "Min","kind": "const","type": 52,"value": 47},{"import": 101,"src": 586,"name": "ln"},{"import": 101,"src": 587,"name": "testAbsFloat"},{"import": 101,"src": 588,"name": "testDivFloor"},{"import": 101,"src": 589,"name": "testCeilPowerOfTwo"},{"import": 101,"src": 590,"name": "assert","kind": "const","type": 1,"value": 1},{"import": 101,"src": 591,"name": "testMod"},{"import": 101,"src": 592,"name": "testCeilPowerOfTwoPromote"},{"import": 101,"src": 593,"name": "testRem"},{"import": 101,"src": 594,"name": "testFloorPowerOfTwo"},{"import": 101,"src": 595,"name": "testOverflow"},{"import": 101,"src": 596,"name": "testDivExact"},{"import": 101,"src": 597,"name": "testing"},{"import": 101,"src": 598,"name": "std","kind": "const","type": 33,"value": 58},{"import": 101,"src": 599,"name": "testAbsInt"},{"import": 101,"src": 600,"name": "testDivTrunc"},{"import": 102,"src": 601,"name": "LineInfo"},{"import": 102,"src": 602,"name": "TTY"},{"import": 102,"src": 603,"name": "attachSegfaultHandler"},{"import": 102,"src": 604,"name": "captureStackTrace"},{"import": 102,"src": 605,"name": "writeCurrentStackTraceWindows"},{"import": 102,"src": 606,"name": "dumpCurrentStackTrace"},{"import": 102,"src": 607,"name": "getStderrStream"},{"import": 102,"src": 608,"name": "have_segfault_handling_support"},{"import": 102,"src": 609,"name": "detectTTYConfig"},{"import": 102,"src": 610,"name": "writeCurrentStackTrace"},{"import": 102,"src": 611,"name": "dumpStackTrace"},{"import": 102,"src": 612,"name": "DebugInfo"},{"import": 102,"src": 613,"name": "enable_segfault_handler"},{"import": 102,"src": 614,"name": "writeStackTrace"},{"import": 102,"src": 615,"name": "leb"},{"import": 102,"src": 616,"name": "ModuleDebugInfo"},{"import": 102,"src": 617,"name": "getSelfDebugInfo"},{"import": 102,"src": 618,"name": "panic"},{"import": 102,"src": 1,"name": "assert","kind": "const","type": 1,"value": 1},{"import": 102,"src": 619,"name": "printSourceAtAddress"},{"import": 102,"src": 620,"name": "StackIterator"},{"import": 102,"src": 621,"name": "readElfDebugInfo"},{"import": 102,"src": 622,"name": "OpenSelfDebugInfoError"},{"import": 102,"src": 623,"name": "panicExtra"},{"import": 102,"src": 624,"name": "maybeEnableSegfaultHandler"},{"import": 102,"src": 625,"name": "runtime_safety"},{"import": 102,"src": 626,"name": "dumpStackTraceFromBase"},{"import": 102,"src": 627,"name": "dumpStackPointerAddr"},{"import": 102,"src": 628,"name": "getStderrMutex"},{"import": 102,"src": 629,"name": "failing_allocator"},{"import": 102,"src": 630,"name": "openSelfDebugInfo"},{"import": 102,"src": 631,"name": "warn"},{"import": 102,"src": 632,"name": "global_allocator"},{"import": 102,"src": 633,"name": "WHITE"},{"import": 102,"src": 634,"name": "panic_mutex"},{"import": 102,"src": 635,"name": "handleSegfaultWindows"},{"import": 102,"src": 636,"name": "DW"},{"import": 102,"src": 637,"name": "panicking"},{"import": 102,"src": 638,"name": "os"},{"import": 102,"src": 639,"name": "readMachODebugInfo"},{"import": 102,"src": 640,"name": "readSparseBitVector"},{"import": 102,"src": 641,"name": "RESET"},{"import": 102,"src": 642,"name": "elf"},{"import": 102,"src": 643,"name": "MachoSymbol"},{"import": 102,"src": 644,"name": "SymbolInfo"},{"import": 102,"src": 645,"name": "mapWholeFile"},{"import": 102,"src": 646,"name": "io"},{"import": 102,"src": 647,"name": "CYAN"},{"import": 102,"src": 648,"name": "root"},{"import": 102,"src": 649,"name": "maxInt"},{"import": 102,"src": 650,"name": "coff"},{"import": 102,"src": 651,"name": "DIM"},{"import": 102,"src": 652,"name": "GREEN"},{"import": 102,"src": 653,"name": "fs"},{"import": 102,"src": 654,"name": "File"},{"import": 102,"src": 655,"name": "printLineFromFileAnyOs"},{"import": 102,"src": 656,"name": "panic_stage"},{"import": 102,"src": 657,"name": "printLineInfo"},{"import": 102,"src": 658,"name": "process"},{"import": 102,"src": 659,"name": "macho"},{"import": 102,"src": 660,"name": "getDebugInfoAllocator"},{"import": 102,"src": 661,"name": "builtin"},{"import": 102,"src": 662,"name": "windows_segfault_handle"},{"import": 102,"src": 663,"name": "debug_info_allocator"},{"import": 102,"src": 664,"name": "math"},{"import": 102,"src": 665,"name": "handleSegfaultWindowsExtra"},{"import": 102,"src": 666,"name": "stderr_file"},{"import": 102,"src": 667,"name": "Module"},{"import": 102,"src": 668,"name": "resetSegfaultHandler"},{"import": 102,"src": 669,"name": "stderr_stream"},{"import": 102,"src": 670,"name": "stderr_mutex"},{"import": 102,"src": 671,"name": "pdb"},{"import": 102,"src": 672,"name": "std"},{"import": 102,"src": 673,"name": "chopSlice"},{"import": 102,"src": 674,"name": "machoSearchSymbols"},{"import": 102,"src": 675,"name": "handleSegfaultLinux"},{"import": 102,"src": 676,"name": "windows"},{"import": 102,"src": 677,"name": "stderr_file_writer"},{"import": 102,"src": 678,"name": "self_debug_info"},{"import": 102,"src": 679,"name": "readCoffDebugInfo"},{"import": 102,"src": 680,"name": "ArrayList"},{"import": 102,"src": 681,"name": "debug_info_arena_allocator"},{"import": 102,"src": 682,"name": "RED"},{"import": 102,"src": 683,"name": "mem"},{"import": 102,"src": 684,"name": "populateModule"},{"import": 103,"src": 685,"name": "eql"},{"import": 103,"src": 686,"name": "Child"},{"import": 103,"src": 41,"name": "Int","kind": "const","type": 42,"value": 43},{"import": 103,"src": 687,"name": "bitCount"},{"import": 103,"src": 688,"name": "declarations"},{"import": 103,"src": 689,"name": "fieldIndex"},{"import": 103,"src": 690,"name": "refAllDecls"},{"import": 103,"src": 691,"name": "IntToEnumError"},{"import": 103,"src": 692,"name": "alignment"},{"import": 103,"src": 693,"name": "IntType"},{"import": 103,"src": 694,"name": "Vector"},{"import": 103,"src": 695,"name": "fieldInfo"},{"import": 103,"src": 696,"name": "activeTag"},{"import": 103,"src": 697,"name": "declarationInfo"},{"import": 103,"src": 698,"name": "declList"},{"import": 103,"src": 699,"name": "trait"},{"import": 103,"src": 700,"name": "TagType"},{"import": 103,"src": 701,"name": "sentinel"},{"import": 103,"src": 702,"name": "containerLayout"},{"import": 103,"src": 703,"name": "tagName"},{"import": 103,"src": 704,"name": "Elem"},{"import": 103,"src": 705,"name": "intToEnum"},{"import": 103,"src": 706,"name": "TagPayloadType"},{"import": 103,"src": 707,"name": "fields"},{"import": 103,"src": 708,"name": "stringToEnum"},{"import": 103,"src": 709,"name": "mem"},{"import": 103,"src": 710,"name": "builtin","kind": "const","type": 33,"value": 57},{"import": 103,"src": 711,"name": "math"},{"import": 103,"src": 712,"name": "std"},{"import": 103,"src": 713,"name": "debug"},{"import": 103,"src": 714,"name": "testing"},{"import": 103,"src": 715,"name": "testSentinel"},{"import": 103,"src": 716,"name": "TypeInfo","kind": "const","type": 33,"value": 96},{"import": 104,"src": 717,"name": "callMain"},{"import": 104,"src": 718,"name": "builtin","kind": "const","type": 33,"value": 87},{"import": 104,"src": 719,"name": "callMainAsync"},{"import": 104,"src": 720,"name": "EfiMain"},{"import": 104,"src": 721,"name": "root","kind": "const","type": 33,"value": 56},{"import": 104,"src": 722,"name": "uefi"},{"import": 104,"src": 723,"name": "main"},{"import": 104,"src": 724,"name": "callMainWithArgs"},{"import": 104,"src": 725,"name": "start_sym_name"},{"import": 104,"src": 726,"name": "WinMainCRTStartup"},{"import": 104,"src": 727,"name": "posixCallMainAndExit"},{"import": 104,"src": 728,"name": "_DllMainCRTStartup"},{"import": 104,"src": 729,"name": "std","kind": "const","type": 33,"value": 58},{"import": 104,"src": 730,"name": "starting_stack_ptr"},{"import": 104,"src": 731,"name": "wasm_freestanding_start"},{"import": 104,"src": 732,"name": "initEventLoopAndCallMain"},{"import": 104,"src": 733,"name": "assert"},{"import": 104,"src": 734,"name": "bad_main_ret"},{"import": 104,"src": 735,"name": "_start"},{"import": 115,"src": 736,"name": "exeFileExt"},{"import": 115,"src": 737,"name": "x86"},{"import": 115,"src": 738,"name": "amdgpu"},{"import": 115,"src": 739,"name": "getObjectFormat"},{"import": 115,"src": 740,"name": "zigTriple"},{"import": 115,"src": 741,"name": "stack_align","kind": "const","type": 37,"value": null},{"import": 115,"src": 742,"name": "getFloatAbi"},{"import": 115,"src": 743,"name": "isMusl"},{"import": 115,"src": 744,"name": "systemz"},{"import": 115,"src": 745,"name": "isDarwin"},{"import": 115,"src": 746,"name": "isMinGW"},{"import": 115,"src": 747,"name": "linuxTripleSimple"},{"import": 115,"src": 748,"name": "staticLibSuffix"},{"import": 115,"src": 749,"name": "staticLibSuffix_cpu_arch_abi"},{"import": 115,"src": 750,"name": "oFileExt"},{"import": 115,"src": 751,"name": "getObjectFormatSimple"},{"import": 115,"src": 752,"name": "libPrefix_cpu_arch_abi"},{"import": 115,"src": 753,"name": "isGnu"},{"import": 115,"src": 754,"name": "Cpu","kind": "const","type": 33,"value": 148},{"import": 115,"src": 755,"name": "riscv"},{"import": 115,"src": 756,"name": "hasDynamicLinker"},{"import": 115,"src": 757,"name": "DynamicLinker"},{"import": 115,"src": 758,"name": "powerpc"},{"import": 115,"src": 759,"name": "dynamicLibSuffix"},{"import": 115,"src": 760,"name": "arm"},{"import": 115,"src": 761,"name": "standardDynamicLinkerPath"},{"import": 115,"src": 762,"name": "Os","kind": "const","type": 33,"value": 90},{"import": 115,"src": 763,"name": "supportsNewStackCall"},{"import": 115,"src": 764,"name": "Abi","kind": "const","type": 33,"value": 149},{"import": 115,"src": 765,"name": "exeFileExtSimple"},{"import": 115,"src": 766,"name": "bpf"},{"import": 115,"src": 767,"name": "wasm"},{"import": 115,"src": 768,"name": "linuxTriple"},{"import": 115,"src": 769,"name": "mips"},{"import": 115,"src": 770,"name": "sparc"},{"import": 115,"src": 771,"name": "avr"},{"import": 115,"src": 772,"name": "isGnuLibC_os_tag_abi"},{"import": 115,"src": 773,"name": "ObjectFormat"},{"import": 115,"src": 774,"name": "FloatAbi"},{"import": 115,"src": 775,"name": "current"},{"import": 115,"src": 776,"name": "hexagon"},{"import": 115,"src": 777,"name": "isAndroid"},{"import": 115,"src": 778,"name": "isGnuLibC"},{"import": 115,"src": 779,"name": "libPrefix"},{"import": 115,"src": 780,"name": "SubSystem"},{"import": 115,"src": 781,"name": "msp430"},{"import": 115,"src": 782,"name": "aarch64"},{"import": 115,"src": 783,"name": "nvptx"},{"import": 115,"src": 784,"name": "isWasm"},{"import": 115,"src": 785,"name": "Target","kind": "const","type": 33,"value": 105},{"import": 115,"src": 786,"name": "builtin"},{"import": 115,"src": 787,"name": "std","kind": "const","type": 33,"value": 58},{"import": 115,"src": 788,"name": "Version","kind": "const","type": 33,"value": 94},{"import": 115,"src": 789,"name": "mem"},{"import": 115,"src": 790,"name": "dynamicLibSuffix"},{"import": 115,"src": 791,"name": "isDarwin"},{"import": 115,"src": 792,"name": "includesVersion"},{"import": 115,"src": 793,"name": "Range","kind": "const","type": 33,"value": 152},{"import": 115,"src": 794,"name": "default"},{"import": 87,"src": 795,"name": "includesVersion"},{"import": 87,"src": 796,"name": "Size","kind": "const","type": 33,"value": 157},{"import": 87,"src": 797,"name": "Data","kind": "const","type": 33,"value": 158},{"import": 115,"src": 798,"name": "Arch","kind": "const","type": 33,"value": 99},{"import": 115,"src": 799,"name": "Model","kind": "const","type": 33,"value": 166},{"import": 115,"src": 800,"name": "baseline"},{"import": 115,"src": 801,"name": "Feature","kind": "const","type": 33,"value": 167},{"import": 115,"src": 802,"name": "isMusl"},{"import": 115,"src": 803,"name": "oFileExt"},{"import": 115,"src": 804,"name": "default"},{"import": 115,"src": 805,"name": "isGnu"},{"import": 115,"src": 806,"name": "includesVersion"},{"import": 87,"src": 807,"name": "FnDecl","kind": "const","type": 33,"value": 170},{"import": 115,"src": 808,"name": "baseline"},{"import": 115,"src": 809,"name": "generic"},{"import": 115,"src": 810,"name": "toCpu"},{"import": 115,"src": 811,"name": "feature_set_fns"},{"import": 115,"src": 812,"name": "Set","kind": "const","type": 33,"value": 169},{"import": 115,"src": 813,"name": "needed_bit_count","kind": "const","type": 37,"value": null},{"import": 115,"src": 814,"name": "addFeatureSet"},{"import": 115,"src": 815,"name": "removeFeatureSet"},{"import": 115,"src": 816,"name": "removeFeature"},{"import": 115,"src": 817,"name": "ShiftInt"},{"import": 115,"src": 818,"name": "Index","kind": "const","type": 33,"value": 34},{"import": 115,"src": 819,"name": "asBytes"},{"import": 115,"src": 820,"name": "isEnabled"},{"import": 115,"src": 821,"name": "empty"},{"import": 115,"src": 822,"name": "byte_count","kind": "const","type": 37,"value": null},{"import": 115,"src": 823,"name": "usize_count","kind": "const","type": 37,"value": null},{"import": 115,"src": 824,"name": "addFeature"},{"import": 115,"src": 825,"name": "empty_workaround"},{"import": 115,"src": 826,"name": "eql"},{"import": 115,"src": 827,"name": "isEmpty"},{"import": 115,"src": 828,"name": "populateDependencies"},{"import": 87,"src": 829,"name": "Inline","kind": "const","type": 33,"value": 173}],"fns": [{"src": 0,"type": 0},{"src": 1,"type": 1},{"src": 2,"type": 2},{"src": 3,"type": 3},{"src": 4,"type": 4},{"src": 5,"type": 3},{"src": 6,"type": 5},{"src": 7,"type": 6},{"src": 8,"type": 7},{"src": 9,"type": 8},{"src": 10,"type": 9},{"src": 11,"type": 1},{"src": 12,"type": 10},{"src": 13,"type": 11},{"src": 14,"type": 12},{"src": 15,"type": 13},{"src": 16,"type": 14},{"src": 17,"type": 15},{"src": 18,"type": 16},{"src": 19,"type": 17},{"src": 20,"type": 18},{"src": 21,"type": 19},{"src": 22,"type": 20},{"src": 23,"type": 21},{"src": 24,"type": 1},{"src": 25,"type": 22},{"src": 26,"type": 23},{"src": 27,"type": 1},{"src": 28,"type": 24},{"src": 29,"type": 24},{"src": 30,"type": 25},{"src": 31,"type": 26},{"src": 32,"type": 27},{"src": 33,"type": 28},{"src": 34,"type": 23},{"src": 35,"type": 15},{"src": 36,"type": 15},{"src": 37,"type": 29},{"src": 38,"type": 30},{"src": 37,"type": 31},{"src": 39,"type": 32},{"src": 40,"type": 36},{"src": 35,"type": 41},{"src": 41,"type": 42},{"src": 42,"type": 45},{"src": 43,"type": 47},{"src": 44,"type": 50},{"src": 45,"type": 52},{"src": 34,"type": 53},{"src": 46,"type": 54},{"src": 47,"type": 55},{"src": 24,"type": 77},{"src": 27,"type": 78},{"src": 36,"type": 79},{"src": 38,"type": 81},{"src": 261,"type": 112},{"src": 11,"type": 113},{"src": 21,"type": 146},{"src": 37,"type": 147}],"errors": [{"src": 830,"name": "OutOfMemory"},{"src": 831,"name": "UnalignedMemory"}],"astNodes": [{"file": 4,"line": 525,"col": 4,"docs": " This function is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n","fields": [832,833]},{"file": 7,"line": 232,"col": 4,"docs": " This function invokes undefined behavior when `ok` is `false`.\n In Debug and ReleaseSafe modes, calls to this function are always\n generated, and the `unreachable` statement triggers a panic.\n In ReleaseFast and ReleaseSmall modes, calls to this function are\n optimized away, and in fact the optimizer is able to use the assertion\n in its heuristics.\n Inside a test block, it is best to use the `std.testing` module rather\n than this function, because this function may not detect a test failure\n in ReleaseFast and ReleaseSmall mode. Outside of a test block, this assert\n function is the correct function to use.\n","fields": [834]},{"file": 3,"line": 234,"col": 12,"fields": [835]},{"file": 3,"line": 485,"col": 12,"fields": [836,837,838,839,840]},{"file": 3,"line": 186,"col": 16,"fields": []},{"file": 3,"line": 392,"col": 8,"fields": [841,842,843,844,845]},{"file": 3,"line": 430,"col": 8,"fields": [846,847,848,849,850]},{"file": 3,"line": 518,"col": 12,"fields": [851]},{"file": 3,"line": 526,"col": 12,"fields": [852,853]},{"file": 3,"line": 535,"col": 12,"fields": [854,855]},{"file": 3,"line": 549,"col": 12,"fields": [856]},{"file": 3,"line": 470,"col": 0,"fields": [857,858]},{"file": 3,"line": 145,"col": 16,"fields": [859]},{"file": 3,"line": 169,"col": 16,"fields": [860]},{"file": 3,"line": 174,"col": 16,"fields": [861,862,863]},{"file": 3,"line": 245,"col": 8,"fields": [864,865]},{"file": 3,"line": 238,"col": 8,"fields": [866,867]},{"file": 3,"line": 351,"col": 8,"fields": [868]},{"file": 3,"line": 130,"col": 16,"fields": [869]},{"file": 3,"line": 165,"col": 16,"fields": [870]},{"file": 3,"line": 290,"col": 8,"fields": [871,872,873]},{"file": 5,"line": 317,"col": 4,"docs": " Copy all of source into dest at position 0.\n dest.len must be >= source.len.\n dest.ptr must be <= src.ptr.\n","fields": [874,875,876]},{"file": 3,"line": 311,"col": 8,"fields": [877,878]},{"file": 3,"line": 161,"col": 16,"fields": [879]},{"file": 3,"line": 97,"col": 8,"fields": [880,881]},{"file": 3,"line": 152,"col": 16,"fields": [882]},{"file": 3,"line": 126,"col": 12,"fields": [883]},{"file": 3,"line": 92,"col": 8,"fields": [884,885]},{"file": 3,"line": 357,"col": 8,"fields": [886,887]},{"file": 3,"line": 378,"col": 8,"fields": [888,889]},{"file": 3,"line": 190,"col": 16,"fields": [890]},{"file": 3,"line": 215,"col": 16,"fields": [891,892]},{"file": 3,"line": 372,"col": 8,"fields": [893,894]},{"file": 3,"line": 198,"col": 16,"fields": [895,896]},{"file": 6,"line": 777,"col": 4,"fields": [897]},{"file": 6,"line": 307,"col": 4,"fields": [898,899]},{"file": 3,"line": 338,"col": 8,"fields": [900,901]},{"file": 6,"line": 256,"col": 4,"docs": " Returns the smaller number. When one of the parameter's type's full range fits in the other,\n the return type is the smaller type.\n","fields": [902,903]},{"file": 3,"line": 345,"col": 8,"fields": [904,905]},{"file": 6,"line": 452,"col": 4,"fields": [906]},{"file": 6,"line": 910,"col": 4,"fields": [907]},{"file": 8,"line": 678,"col": 4,"fields": [908,909]},{"file": 3,"line": 84,"col": 8,"fields": [910]},{"file": 3,"line": 104,"col": 4,"fields": [911]},{"file": 3,"line": 516,"col": 8,"fields": [912]},{"file": 6,"line": 237,"col": 4,"docs": " Given two types, returns the smallest one which is capable of holding the\n full range of the minimum value.\n","fields": [913,914]},{"file": 3,"line": 77,"col": 8,"fields": [915]},{"file": 6,"line": 868,"col": 4,"fields": [916,917]},{"file": 3,"line": 67,"col": 27,"fields": [918,919,920]},{"file": 3,"line": 111,"col": 11,"fields": [921,922,923]},{"file": 3,"line": 13,"col": 19,"fields": [924,925,926,927,928]},{"file": 3,"line": 509,"col": 20,"fields": [929,930,931,932,933]},{"file": 0,"line": 0,"col": 0,"fields": []},{"file": 1,"line": 0,"col": 0,"fields": []},{"file": 2,"line": 0,"col": 0,"fields": []},{"file": 3,"line": 183,"col": 25,"fields": [934]},{"file": 3,"line": 0,"col": 0,"fields": []},{"file": 3,"line": 117,"col": 22,"fields": [935,936,937]},{"file": 5,"line": 15,"col": 22,"fields": [938,939]},{"file": 3,"line": 23,"col": 35,"fields": [940,941,942]},{"file": 3,"line": 51,"col": 31,"fields": [943,944,945]},{"file": 3,"line": 39,"col": 30,"fields": [946,947]},{"file": 4,"line": 0,"col": 0,"fields": []},{"file": 4,"line": 384,"col": 23,"fields": [948,949,950]},{"file": 4,"line": 107,"col": 17,"fields": [951,952,953,954]},{"file": 10,"line": 13,"col": 19,"fields": [955,956]},{"file": 4,"line": 51,"col": 23,"fields": [957,958]},{"file": 4,"line": 116,"col": 30,"fields": [959,960,961,962,963,964,965,966,967,968,969,970,971,972]},{"file": 4,"line": 458,"col": 24,"fields": [973,974]},{"file": 4,"line": 399,"col": 20,"fields": [975,976,977]},{"file": 4,"line": 58,"col": 26,"fields": [978,979,980,981]},{"file": 4,"line": 137,"col": 21,"fields": [982,983,984,985,986,987,988,989,990,991,992,993,994,995,996,997,998,999,1000,1001,1002,1003,1004,1005,1006]},{"file": 4,"line": 392,"col": 21,"fields": [1007,1008]},{"file": 4,"line": 501,"col": 26,"fields": [1009,1010,1011]},{"file": 10,"line": 552,"col": 25,"fields": [1012,1013,1014,1015,1016,1017,1018,1019,1020,1021,1022,1023,1024,1025,1026,1027,1028,1029,1030,1031,1032,1033,1034,1035,1036,1037,1038,1039,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062]},{"file": 5,"line": 0,"col": 0,"fields": []},{"file": 6,"line": 0,"col": 0,"fields": []},{"file": 7,"line": 0,"col": 0,"fields": []},{"file": 8,"line": 0,"col": 0,"fields": []},{"file": 9,"line": 2,"col": 0,"fields": []},{"file": 10,"line": 8,"col": 19,"fields": [1063,1064,1065]},{"file": 10,"line": 0,"col": 0,"fields": []},{"file": 10,"line": 17,"col": 24,"fields": [1066,1067,1068,1069,1070,1071,1072,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086,1087,1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,1102]},{"file": 10,"line": 105,"col": 38,"fields": [1103,1104]},{"file": 10,"line": 76,"col": 35,"fields": [1105,1106,1107,1108,1109,1110,1111,1112,1113,1114,1115,1116,1117,1118,1119,1120,1121]},{"file": 10,"line": 135,"col": 33,"fields": [1122,1123,1124,1125]},{"file": 4,"line": 464,"col": 25,"fields": [1126,1127,1128,1129,1130,1131,1132,1133]},{"file": 4,"line": 404,"col": 22,"fields": [1134,1135]},{"file": 4,"line": 235,"col": 23,"fields": [1136,1137,1138]},{"file": 4,"line": 205,"col": 22,"fields": [1139,1140,1141]},{"file": 4,"line": 249,"col": 27,"fields": [1142,1143]},{"file": 4,"line": 179,"col": 24,"fields": [1144,1145,1146,1147,1148,1149,1150]},{"file": 4,"line": 267,"col": 26,"fields": [1151,1152]},{"file": 4,"line": 218,"col": 32,"fields": [1153,1154,1155]},{"file": 4,"line": 332,"col": 28,"fields": [1156,1157,1158]},{"file": 4,"line": 292,"col": 22,"fields": [1159,1160,1161,1162]},{"file": 4,"line": 243,"col": 25,"fields": [1163]},{"file": 4,"line": 274,"col": 21,"fields": [1164,1165,1166,1167,1168]},{"file": 4,"line": 325,"col": 23,"fields": [1169,1170]},{"file": 4,"line": 173,"col": 22,"fields": [1171]},{"file": 4,"line": 284,"col": 27,"fields": [1172,1173,1174]},{"file": 4,"line": 226,"col": 28,"fields": [1175,1176,1177,1178]},{"file": 4,"line": 319,"col": 25,"fields": [1179]},{"file": 4,"line": 256,"col": 22,"fields": [1180,1181]},{"file": 4,"line": 309,"col": 19,"fields": [1182,1183,1184,1185,1186]},{"file": 4,"line": 301,"col": 22,"fields": [1187,1188,1189]},{"file": 4,"line": 166,"col": 20,"fields": [1190,1191]},{"file": 10,"line": 425,"col": 20,"fields": [1192,1193,1194]},{"file": 10,"line": 312,"col": 20,"fields": [1195,1196,1197,1198,1199,1200,1201,1202,1203,1204,1205,1206,1207,1208,1209,1210,1211,1212,1213,1214]},{"file": 10,"line": 95,"col": 30,"fields": [1215,1216]},{"file": 4,"line": 195,"col": 25,"fields": [1217,1218,1219,1220]},{"file": 4,"line": 339,"col": 25,"fields": [1221,1222,1223]},{"file": 10,"line": 894,"col": 26,"fields": [1224,1225,1226]},{"file": 10,"line": 436,"col": 28,"fields": [1227,1228,1229,1230,1231]},{"file": 10,"line": 456,"col": 28,"fields": [1232]},{"file": 4,"line": 346,"col": 31,"fields": [1233,1234,1235,1236,1237,1238,1239,1240]},{"file": 4,"line": 358,"col": 35,"fields": [1241,1242,1243]},{"file": 3,"line": 223,"col": 12,"docs": " The definitive™ way of using `ZeeAlloc`\n"},{"file": 3,"line": 117,"col": 8},{"file": 3,"line": 114,"col": 8},{"file": 3,"line": 454,"col": 8,"fields": [1244]},{"file": 3,"line": 112,"col": 8},{"file": 3,"line": 445,"col": 8,"fields": [1245,1246]},{"file": 3,"line": 224,"col": 8},{"file": 3,"line": 183,"col": 8},{"file": 3,"line": 462,"col": 8,"fields": [1247]},{"file": 3,"line": 23,"col": 8},{"file": 3,"line": 67,"col": 8},{"file": 3,"line": 51,"col": 8},{"file": 3,"line": 39,"col": 8},{"file": 3,"line": 509,"col": 4},{"file": 3,"line": 11,"col": 4},{"file": 3,"line": 13,"col": 4},{"file": 0,"line": 0,"col": 0},{"file": 0,"line": 1,"col": 0},{"file": 0,"line": 2,"col": 0},{"file": 4,"line": 96,"col": 4,"docs": " The code model puts constraints on the location of symbols and the size of code and data.\n The selection of a code model is a trade off on speed and restrictions that needs to be selected on a per application basis to meet its requirements.\n A slightly more detailed explanation can be found in (for example) the [System V Application Binary Interface (x86_64)](https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf) 3.5.1.\n\n This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 1,"line": 28,"col": 4},{"file": 4,"line": 384,"col": 4,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 1,"line": 10,"col": 4},{"file": 1,"line": 21,"col": 4},{"file": 1,"line": 16,"col": 4},{"file": 1,"line": 9,"col": 4},{"file": 4,"line": 51,"col": 4,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 1,"line": 3,"col": 4},{"file": 4,"line": 116,"col": 4,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 21,"col": 4,"docs": " Deprecated: use `std.Target.Cpu`.\n"},{"file": 4,"line": 458,"col": 4,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 107,"col": 4,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 509,"col": 4,"docs": " This function type is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 6,"col": 4,"docs": " Deprecated: use `std.Target.Os`.\n"},{"file": 4,"line": 399,"col": 4,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 58,"col": 4,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 12,"col": 4,"docs": " Deprecated: use `std.Target.Abi`.\n"},{"file": 1,"line": 24,"col": 4},{"file": 4,"line": 137,"col": 4,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 1,"line": 26,"col": 4},{"file": 4,"line": 78,"col": 4,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 1,"line": 22,"col": 4},{"file": 4,"line": 392,"col": 4,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 501,"col": 4,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 1,"line": 20,"col": 4},{"file": 1,"line": 8,"col": 4,"docs": " Deprecated: use `std.Target.cpu.arch`\n"},{"file": 1,"line": 2,"col": 4},{"file": 4,"line": 370,"col": 4,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 67,"col": 4,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 133,"col": 4},{"file": 4,"line": 15,"col": 4,"docs": " Deprecated: use `std.Target.ObjectFormat`.\n"},{"file": 1,"line": 5,"col": 4},{"file": 4,"line": 3,"col": 4,"docs": " Deprecated: use `std.Target`.\n"},{"file": 4,"line": 517,"col": 4,"docs": " This function type is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 1,"line": 4,"col": 4},{"file": 4,"line": 9,"col": 4,"docs": " Deprecated: use `std.Target.Cpu.Arch`.\n"},{"file": 1,"line": 25,"col": 4},{"file": 4,"line": 18,"col": 4,"docs": " Deprecated: use `std.Target.SubSystem`.\n"},{"file": 4,"line": 27,"col": 4,"docs": " `explicit_subsystem` is missing when the subsystem is automatically detected,\n so Zig standard library has the subsystem detection logic here. This should generally be\n used rather than `explicit_subsystem`.\n On non-Windows targets, this is `null`.\n"},{"file": 4,"line": 377,"col": 4,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 521,"col": 4,"docs": " This function is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 1,"line": 23,"col": 4},{"file": 1,"line": 27,"col": 4},{"file": 1,"line": 6,"col": 4},{"file": 2,"line": 53,"col": 4},{"file": 2,"line": 11,"col": 4},{"file": 2,"line": 32,"col": 4},{"file": 2,"line": 22,"col": 4},{"file": 2,"line": 15,"col": 4},{"file": 2,"line": 14,"col": 4},{"file": 2,"line": 52,"col": 4},{"file": 2,"line": 27,"col": 4},{"file": 2,"line": 2,"col": 4},{"file": 2,"line": 8,"col": 4},{"file": 2,"line": 3,"col": 4},{"file": 2,"line": 42,"col": 4},{"file": 2,"line": 56,"col": 4},{"file": 2,"line": 38,"col": 4},{"file": 2,"line": 39,"col": 4},{"file": 2,"line": 65,"col": 4},{"file": 2,"line": 41,"col": 4},{"file": 2,"line": 67,"col": 4},{"file": 2,"line": 4,"col": 4},{"file": 2,"line": 31,"col": 4},{"file": 2,"line": 48,"col": 4},{"file": 2,"line": 40,"col": 4},{"file": 2,"line": 10,"col": 4},{"file": 2,"line": 21,"col": 4},{"file": 2,"line": 64,"col": 4},{"file": 2,"line": 49,"col": 4},{"file": 2,"line": 9,"col": 4},{"file": 2,"line": 46,"col": 4},{"file": 2,"line": 43,"col": 4},{"file": 2,"line": 30,"col": 4},{"file": 2,"line": 29,"col": 4},{"file": 2,"line": 25,"col": 4},{"file": 2,"line": 50,"col": 4},{"file": 2,"line": 57,"col": 4},{"file": 2,"line": 20,"col": 4},{"file": 2,"line": 59,"col": 4},{"file": 2,"line": 7,"col": 4},{"file": 2,"line": 35,"col": 4},{"file": 2,"line": 36,"col": 4},{"file": 2,"line": 45,"col": 4},{"file": 2,"line": 63,"col": 4},{"file": 2,"line": 34,"col": 4},{"file": 2,"line": 33,"col": 4},{"file": 2,"line": 37,"col": 4},{"file": 2,"line": 62,"col": 4},{"file": 2,"line": 61,"col": 4},{"file": 2,"line": 54,"col": 4},{"file": 2,"line": 55,"col": 4},{"file": 2,"line": 44,"col": 4},{"file": 2,"line": 47,"col": 4},{"file": 2,"line": 70,"col": 4},{"file": 2,"line": 1,"col": 4},{"file": 2,"line": 5,"col": 4},{"file": 2,"line": 18,"col": 4},{"file": 2,"line": 13,"col": 4},{"file": 2,"line": 66,"col": 4},{"file": 2,"line": 19,"col": 4},{"file": 2,"line": 26,"col": 4},{"file": 2,"line": 58,"col": 4},{"file": 2,"line": 68,"col": 4},{"file": 2,"line": 17,"col": 4},{"file": 2,"line": 12,"col": 4},{"file": 2,"line": 69,"col": 4},{"file": 2,"line": 0,"col": 4},{"file": 2,"line": 23,"col": 4},{"file": 2,"line": 16,"col": 4},{"file": 2,"line": 60,"col": 4},{"file": 2,"line": 51,"col": 4},{"file": 2,"line": 6,"col": 4},{"file": 2,"line": 24,"col": 4},{"file": 3,"line": 203,"col": 16,"fields": [1248,1249]},{"file": 3,"line": 1,"col": 0},{"file": 3,"line": 9,"col": 0},{"file": 3,"line": 689,"col": 0,"fields": [1250,1251]},{"file": 3,"line": 746,"col": 0,"fields": [1252]},{"file": 3,"line": 6,"col": 0},{"file": 3,"line": 477,"col": 0},{"file": 3,"line": 0,"col": 0},{"file": 3,"line": 661,"col": 0,"fields": [1253]},{"file": 3,"line": 713,"col": 0,"fields": [1254]},{"file": 3,"line": 476,"col": 0,"fields": [1255,1256]},{"file": 3,"line": 5,"col": 0},{"file": 3,"line": 8,"col": 0},{"file": 3,"line": 576,"col": 0},{"file": 3,"line": 4,"col": 0},{"file": 3,"line": 2,"col": 0},{"file": 3,"line": 138,"col": 16,"fields": [1257]},{"file": 3,"line": 118,"col": 12},{"file": 3,"line": 119,"col": 12},{"file": 5,"line": 87,"col": 8,"docs": " `ptr` should be the return value of `create`, or otherwise\n have the same address and alignment property.\n","fields": [1258,1259]},{"file": 5,"line": 187,"col": 8,"docs": " This function requests a new byte size for an existing allocation,\n which can be larger, smaller, or the same size as the old memory\n allocation.\n This function is preferred over `shrink`, because it can fail, even\n when shrinking. This gives the allocator a chance to perform a\n cheap shrink operation if possible, or otherwise return OutOfMemory,\n indicating that the caller should keep their capacity, for example\n in `std.ArrayList.shrink`.\n If you need guaranteed success, call `shrink`.\n If `new_n` is 0, this is the same as `free` and it always succeeds.\n","fields": [1260,1261,1262]},{"file": 5,"line": 142,"col": 8,"docs": " Allocates an array of `n + 1` items of type `T` and sets the first `n`\n items to `undefined` and the last item to `sentinel`. Depending on the\n Allocator implementation, it may be required to call `free` once the\n memory is no longer needed, to avoid a resource leak. If the\n `Allocator` implementation is unknown, then correct code will\n call `free` when done.\n\n For allocating a single item, see `create`.\n\n Deprecated; use `allocWithOptions`.\n","fields": [1263,1264,1265,1266]},{"file": 5,"line": 230,"col": 8,"docs": " Prefer calling realloc to shrink if you can tolerate failure, such as\n in an ArrayList data structure with a storage capacity.\n Shrink always succeeds, and `new_n` must be <= `old_mem.len`.\n Returned slice has same alignment as old_mem.\n Shrinking to 0 is the same as calling `free`.\n","fields": [1267,1268,1269]},{"file": 5,"line": 16,"col": 8},{"file": 5,"line": 241,"col": 8,"docs": " This is the same as `shrink`, except caller may additionally request\n a new alignment, which must be smaller or the same as the old\n allocation.\n","fields": [1270,1271,1272,1273]},{"file": 5,"line": 146,"col": 8,"fields": [1274,1275,1276,1277]},{"file": 5,"line": 103,"col": 8,"docs": " Allocates an array of `n` items of type `T` and sets all the\n items to `undefined`. Depending on the Allocator\n implementation, it may be required to call `free` once the\n memory is no longer needed, to avoid a resource leak. If the\n `Allocator` implementation is unknown, then correct code will\n call `free` when done.\n\n For allocating a single item, see `create`.\n","fields": [1278,1279,1280]},{"file": 5,"line": 198,"col": 8,"docs": " This is the same as `realloc`, except caller may additionally request\n a new alignment, which can be larger, smaller, or the same as the old\n allocation.\n","fields": [1281,1282,1283,1284]},{"file": 5,"line": 283,"col": 8,"docs": " Copies `m` to newly allocated memory. Caller owns the memory.\n","fields": [1285,1286,1287]},{"file": 5,"line": 290,"col": 8,"docs": " Copies `m` to newly allocated memory, with a null-terminated element. Caller owns the memory.\n","fields": [1288,1289,1290]},{"file": 5,"line": 271,"col": 8,"docs": " Free an array allocated with `alloc`. To free a single item,\n see `destroy`.\n","fields": [1291,1292]},{"file": 5,"line": 107,"col": 8,"fields": [1293,1294,1295,1296,1297]},{"file": 5,"line": 79,"col": 8,"docs": " Returns a pointer to undefined memory.\n Call `destroy` with the result to free the memory.\n","fields": [1298,1299]},{"file": 5,"line": 124,"col": 4,"fields": [1300,1301,1302]},{"file": 4,"line": 553,"col": 0},{"file": 4,"line": 552,"col": 0},{"file": 10,"line": 17,"col": 12},{"file": 10,"line": 105,"col": 12},{"file": 10,"line": 76,"col": 12,"docs": " Based on NTDDI version constants from\n https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt\n"},{"file": 10,"line": 135,"col": 12,"docs": " The version ranges here represent the minimum OS version to be supported\n and the maximum OS version to be supported. The default values represent\n the range that the Zig Standard Library bases its abstractions on.\n\n The minimum version of the range is the main setting to tweak for a target.\n Usually, the maximum target OS version will remain the default, which is\n the latest released version of the OS.\n\n To test at compile time if the target is guaranteed to support a given OS feature,\n one should check that the minimum version of the range is greater than or equal to\n the version the feature was introduced in.\n\n To test at compile time if the target certainly will not support a given OS feature,\n one should check that the maximum version of the range is less than the version the\n feature was introduced in.\n\n If neither of these cases apply, a runtime check should be used to determine if the\n target supports a given OS feature.\n\n Binaries built with a given maximum version will continue to function on newer operating system\n versions. However, such a binary may not take full advantage of the newer operating system APIs.\n"},{"file": 10,"line": 250,"col": 12,"fields": [1303]},{"file": 10,"line": 243,"col": 12,"fields": [1304]},{"file": 4,"line": 464,"col": 8},{"file": 4,"line": 404,"col": 8},{"file": 4,"line": 434,"col": 8,"fields": [1305,1306,1307,1308]},{"file": 4,"line": 425,"col": 8,"fields": [1309]},{"file": 4,"line": 415,"col": 8,"fields": [1310,1311]},{"file": 4,"line": 235,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 205,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 249,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 179,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 267,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 218,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 332,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 292,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 263,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 243,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 274,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 325,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 173,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 284,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 226,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 319,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 256,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 309,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 301,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 166,"col": 8,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 10,"line": 826,"col": 16,"docs": " Returns a name that matches the lib/std/target/* directory name.\n","fields": [1312]},{"file": 10,"line": 605,"col": 16,"fields": [1313]},{"file": 10,"line": 848,"col": 16,"docs": " All CPU features Zig is aware of, sorted lexicographically by name.\n","fields": [1314]},{"file": 10,"line": 764,"col": 16,"fields": [1315]},{"file": 10,"line": 705,"col": 16,"fields": [1316]},{"file": 10,"line": 612,"col": 16,"fields": [1317]},{"file": 10,"line": 640,"col": 16,"fields": [1318,1319]},{"file": 10,"line": 871,"col": 16,"docs": " All processors Zig is aware of, sorted lexicographically by name.\n","fields": [1320]},{"file": 10,"line": 649,"col": 16,"fields": [1321]},{"file": 10,"line": 626,"col": 16,"fields": [1322]},{"file": 10,"line": 619,"col": 16,"fields": [1323]},{"file": 10,"line": 633,"col": 16,"fields": [1324]},{"file": 5,"line": 656,"col": 4},{"file": 5,"line": 749,"col": 4,"docs": " Same as `span`, except when there is both a sentinel and an array\n length or slice length, scans the memory for the sentinel value\n rather than using the length.\n","fields": [1325]},{"file": 5,"line": 343,"col": 4,"fields": [1326,1327,1328]},{"file": 5,"line": 1219,"col": 4,"docs": " Writes a twos-complement big-endian integer to memory.\n Asserts that buffer.len >= T.bit_count / 8.\n The bit count of T must be divisible by 8.\n Any extra bytes in buffer before writing the integer are set to zero. To\n avoid the branch to check for extra buffer bytes, use writeIntBig instead.\n","fields": [1329,1330,1331]},{"file": 5,"line": 1760,"col": 4,"docs": " In-place order reversal of a slice\n","fields": [1332,1333]},{"file": 5,"line": 1076,"col": 4,"docs": " Asserts that bytes.len >= T.bit_count / 8. Reads the integer starting from index 0\n and ignores extra bytes.\n The bit count of T must be evenly divisible by 8.\n Assumes the endianness of memory is native. This means the function can\n simply pointer cast memory.\n","fields": [1334,1335]},{"file": 5,"line": 1897,"col": 4,"docs": "Given any value, returns a copy of its bytes in an array.\n","fields": [1336]},{"file": 5,"line": 1777,"col": 4,"docs": " In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1)\n Assumes 0 <= amount <= items.len\n","fields": [1337,1338,1339]},{"file": 5,"line": 778,"col": 4,"docs": " Takes a pointer to an array, an array, a vector, a sentinel-terminated pointer,\n or a slice, and returns the length.\n In the case of a sentinel-terminated array, it uses the array length.\n For C pointers it assumes it is a pointer-to-many with a 0 sentinel.\n","fields": [1340]},{"file": 5,"line": 2082,"col": 4,"fields": [1341]},{"file": 5,"line": 1975,"col": 4,"docs": "Given a pointer to an array of bytes, returns a value of the specified type backed by a\n copy of those bytes.\n","fields": [1342,1343]},{"file": 5,"line": 1168,"col": 4,"docs": " Writes an integer to memory, storing it in twos-complement.\n This function always succeeds, has defined behavior for all inputs, but\n the integer bit width must be divisible by 8.\n This function stores in foreign endian, which means it does a @byteSwap first.\n","fields": [1344,1345,1346]},{"file": 5,"line": 655,"col": 4},{"file": 5,"line": 1374,"col": 4},{"file": 5,"line": 895,"col": 4,"docs": " Deprecated, use `Allocator.dupeZ`.\n","fields": [1347,1348,1349]},{"file": 5,"line": 1465,"col": 4},{"file": 5,"line": 1741,"col": 4,"fields": [1350,1351]},{"file": 5,"line": 1408,"col": 4,"fields": [1352,1353,1354]},{"file": 5,"line": 2003,"col": 4,"fields": [1355,1356]},{"file": 5,"line": 944,"col": 4,"fields": [1357,1358,1359,1360]},{"file": 5,"line": 1236,"col": 4},{"file": 5,"line": 977,"col": 4,"fields": [1361,1362,1363]},{"file": 5,"line": 1185,"col": 4,"docs": " Writes an integer to memory, storing it in twos-complement.\n This function always succeeds, has defined behavior for all inputs, but\n the integer bit width must be divisible by 8.\n","fields": [1364,1365,1366,1367]},{"file": 5,"line": 2173,"col": 4,"docs": " Round an address up to the nearest aligned address\n The alignment must be a power of 2 and greater than 0.\n","fields": [1368,1369,1370]},{"file": 5,"line": 1753,"col": 4,"fields": [1371,1372,1373]},{"file": 5,"line": 935,"col": 4,"docs": " Linear search for the last index of a scalar value inside a slice.\n","fields": [1374,1375,1376]},{"file": 5,"line": 1199,"col": 4,"docs": " Writes a twos-complement little-endian integer to memory.\n Asserts that buf.len >= T.bit_count / 8.\n The bit count of T must be divisible by 8.\n Any extra bytes in buffer after writing the integer are set to zero. To\n avoid the branch to check for extra buffer bytes, use writeIntLittle\n instead.\n","fields": [1377,1378,1379]},{"file": 5,"line": 1729,"col": 4,"fields": [1380,1381]},{"file": 5,"line": 1049,"col": 4,"docs": " Reads an integer from memory with bit count specified by T.\n The bit count of T must be evenly divisible by 8.\n This function cannot fail and cannot cause undefined behavior.\n Assumes the endianness of memory is native. This means the function can\n simply pointer cast memory.\n","fields": [1382,1383]},{"file": 5,"line": 967,"col": 4,"fields": [1384,1385,1386,1387]},{"file": 5,"line": 1095,"col": 4},{"file": 5,"line": 1172,"col": 4},{"file": 5,"line": 826,"col": 4,"docs": " Takes a pointer to an array, an array, a sentinel-terminated pointer,\n or a slice, and returns the length.\n In the case of a sentinel-terminated array, it scans the array\n for a sentinel and uses that for the length, rather than using the array length.\n For C pointers it assumes it is a pointer-to-many with a 0 sentinel.\n","fields": [1388]},{"file": 5,"line": 900,"col": 4,"docs": " Remove values from the beginning of a slice.\n","fields": [1389,1390,1391]},{"file": 5,"line": 2200,"col": 4,"docs": " Round an address up to the previous aligned address\n The alignment must be a power of 2 and greater than 0.\n","fields": [1392,1393,1394]},{"file": 5,"line": 1857,"col": 4,"docs": " Given a pointer to a single item, returns a slice of the underlying bytes, preserving constness.\n","fields": [1395]},{"file": 5,"line": 1026,"col": 4,"docs": " Reads an integer from memory with size equal to bytes.len.\n T specifies the return type, which must be large enough to store\n the result.\n","fields": [1396,1397,1398]},{"file": 5,"line": 2210,"col": 4,"docs": " Given an address and an alignment, return true if the address is a multiple of the alignment\n The alignment must be a power of 2 and greater than 0.\n","fields": [1399,1400]},{"file": 5,"line": 1252,"col": 4,"docs": " Writes a twos-complement integer to memory, with the specified endianness.\n Asserts that buf.len >= T.bit_count / 8.\n The bit count of T must be evenly divisible by 8.\n Any extra bytes in buffer not part of the integer are set to zero, with\n respect to endianness. To avoid the branch to check for extra buffer bytes,\n use writeInt instead.\n","fields": [1401,1402,1403,1404]},{"file": 5,"line": 890,"col": 4,"docs": " Deprecated, use `Allocator.dupe`.\n","fields": [1405,1406,1407]},{"file": 5,"line": 1493,"col": 4,"docs": " Naively combines a series of slices with a separator.\n Allocates memory for the result, which must be freed by the caller.\n","fields": [1408,1409,1410]},{"file": 5,"line": 1538,"col": 4,"docs": " Copies each T from slices into a new slice that exactly holds all the elements.\n","fields": [1411,1412,1413]},{"file": 5,"line": 1932,"col": 4,"docs": "Given a pointer to an array of bytes, returns a pointer to a value of the specified type\n backed by those bytes, preserving constness.\n","fields": [1414,1415]},{"file": 5,"line": 1807,"col": 4,"docs": " Converts an integer from specified endianness to host endianness.\n","fields": [1416,1417,1418]},{"file": 5,"line": 995,"col": 4,"fields": [1419,1420,1421,1422]},{"file": 5,"line": 1823,"col": 4,"docs": " Converts an integer which has host endianness to little endian.\n","fields": [1423,1424]},{"file": 5,"line": 2194,"col": 4,"docs": " Round an address up to the previous aligned address\n The alignment must be a power of 2 and greater than 0.\n","fields": [1425,1426]},{"file": 5,"line": 1114,"col": 4,"docs": " Asserts that bytes.len >= T.bit_count / 8. Reads the integer starting from index 0\n and ignores extra bytes.\n The bit count of T must be evenly divisible by 8.\n","fields": [1427,1428,1429]},{"file": 5,"line": 1815,"col": 4,"docs": " Converts an integer which has host endianness to the desired endianness.\n","fields": [1430,1431,1432]},{"file": 5,"line": 873,"col": 4,"fields": [1433,1434,1435]},{"file": 5,"line": 354,"col": 4,"docs": " Generally, Zig users are encouraged to explicitly initialize all fields of a struct explicitly rather than using this function.\n However, it is recognized that there are sometimes use cases for initializing all fields to a \"zero\" value. For example, when\n interfacing with a C API where this practice is more common and relied upon. If you are performing code review and see this\n function used, examine closely - it may be a code smell.\n Zero initializes the type.\n This can be used to zero initialize a any type for which it makes sense. Structs will be initialized recursively.\n","fields": [1436]},{"file": 5,"line": 956,"col": 4,"fields": [1437,1438,1439]},{"file": 5,"line": 592,"col": 4,"fields": [1440,1441,1442]},{"file": 5,"line": 1426,"col": 4},{"file": 5,"line": 1791,"col": 4,"docs": " Converts a little-endian integer to host endianness.\n","fields": [1443,1444]},{"file": 5,"line": 1799,"col": 4,"docs": " Converts a big-endian integer to host endianness.\n","fields": [1445,1446]},{"file": 5,"line": 2167,"col": 4,"docs": " Round an address up to the nearest aligned address\n The alignment must be a power of 2 and greater than 0.\n","fields": [1447,1448]},{"file": 5,"line": 930,"col": 4,"docs": " Linear search for the index of a scalar value inside a slice.\n","fields": [1449,1450,1451]},{"file": 5,"line": 1831,"col": 4,"docs": " Converts an integer which has host endianness to big endian.\n","fields": [1452,1453]},{"file": 5,"line": 1160,"col": 4,"docs": " Writes an integer to memory, storing it in twos-complement.\n This function always succeeds, has defined behavior for all inputs, and\n accepts any integer bit width.\n This function stores in native endian, which means it is implemented as a simple\n memory store.\n","fields": [1454,1455,1456]},{"file": 5,"line": 15,"col": 4},{"file": 5,"line": 952,"col": 4,"fields": [1457,1458,1459]},{"file": 5,"line": 1066,"col": 4},{"file": 5,"line": 721,"col": 4,"docs": " Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and\n returns a slice. If there is a sentinel on the input type, there will be a\n sentinel on the output type. The constness of the output type matches\n the constness of the input type.\n\n When there is both a sentinel and an array length or slice length, the\n length value is used instead of the sentinel.\n","fields": [1460]},{"file": 5,"line": 614,"col": 4,"docs": " Returns true if lhs < rhs, false otherwise\n","fields": [1461,1462,1463]},{"file": 5,"line": 1417,"col": 4,"fields": [1464,1465,1466]},{"file": 5,"line": 914,"col": 4,"docs": " Remove values from the beginning and end of a slice.\n","fields": [1467,1468,1469]},{"file": 5,"line": 1305,"col": 4,"docs": " Returns an iterator that iterates over the slices of `buffer` that are not\n any of the bytes in `delimiter_bytes`.\n tokenize(\" abc def ghi \", \" \")\n Will return slices for \"abc\", \"def\", \"ghi\", null, in that order.\n If `buffer` is empty, the iterator will return null.\n If `delimiter_bytes` does not exist in buffer,\n the iterator will return `buffer`, null, in that order.\n See also the related function `split`.\n","fields": [1470,1471]},{"file": 5,"line": 638,"col": 4,"docs": " Compares two slices and returns the index of the first inequality.\n Returns null if the slices are equal.\n","fields": [1472,1473,1474]},{"file": 5,"line": 1057,"col": 4,"docs": " Reads an integer from memory with bit count specified by T.\n The bit count of T must be evenly divisible by 8.\n This function cannot fail and cannot cause undefined behavior.\n Assumes the endianness of memory is foreign, so it must byte-swap.\n","fields": [1475,1476]},{"file": 5,"line": 1241,"col": 4},{"file": 5,"line": 1090,"col": 4},{"file": 5,"line": 2214,"col": 4,"fields": [1477,1478,1479]},{"file": 5,"line": 907,"col": 4,"docs": " Remove values from the end of a slice.\n","fields": [1480,1481,1482]},{"file": 5,"line": 500,"col": 4,"fields": [1483,1484]},{"file": 5,"line": 1177,"col": 4},{"file": 5,"line": 521,"col": 4,"docs": " Initializes all fields of the struct with their default value, or zero values if no default value is present.\n If the field is present in the provided initial values, it will have that value instead.\n Structs are initialized recursively.\n","fields": [1485,1486]},{"file": 5,"line": 663,"col": 4,"docs": " Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and\n returns a slice. If there is a sentinel on the input type, there will be a\n sentinel on the output type. The constness of the output type matches\n the constness of the input type. `[*c]` pointers are assumed to be 0-terminated,\n and assumed to not allow null.\n","fields": [1487]},{"file": 5,"line": 1365,"col": 4,"docs": " Returns an iterator that iterates over the slices of `buffer` that\n are separated by bytes in `delimiter`.\n split(\"abc|def||ghi\", \"|\")\n will return slices for \"abc\", \"def\", \"\", \"ghi\", null, in that order.\n If `delimiter` does not exist in buffer,\n the iterator will return `buffer`, null, in that order.\n The delimiter length must not be zero.\n See also the related function `tokenize`.\n","fields": [1488,1489]},{"file": 5,"line": 10,"col": 4},{"file": 5,"line": 984,"col": 4,"docs": " Find the index in a slice of a sub-slice, searching from the end backwards.\n To start looking at a different index, slice the haystack first.\n TODO is there even a better algorithm for this?\n","fields": [1490,1491,1492]},{"file": 5,"line": 1061,"col": 4},{"file": 5,"line": 1086,"col": 4,"docs": " Asserts that bytes.len >= T.bit_count / 8. Reads the integer starting from index 0\n and ignores extra bytes.\n The bit count of T must be evenly divisible by 8.\n Assumes the endianness of memory is foreign, so it must byte-swap.\n","fields": [1493,1494]},{"file": 5,"line": 330,"col": 4,"docs": " Copy all of source into dest at position 0.\n dest.len must be >= source.len.\n dest.ptr must be >= src.ptr.\n","fields": [1495,1496,1497]},{"file": 5,"line": 882,"col": 4,"docs": " Returns true if all elements in a slice are equal to the scalar value provided\n","fields": [1498,1499,1500]},{"file": 5,"line": 627,"col": 4,"docs": " Compares two slices and returns whether they are equal.\n","fields": [1501,1502,1503]},{"file": 5,"line": 1103,"col": 4,"docs": " Reads an integer from memory with bit count specified by T.\n The bit count of T must be evenly divisible by 8.\n This function cannot fail and cannot cause undefined behavior.\n","fields": [1504,1505,1506]},{"file": 5,"line": 298,"col": 0},{"file": 5,"line": 302,"col": 0,"fields": [1507,1508,1509,1510,1511]},{"file": 5,"line": 1989,"col": 0,"fields": [1512,1513]},{"file": 5,"line": 1915,"col": 0,"fields": [1514,1515]},{"file": 5,"line": 1641,"col": 0,"fields": []},{"file": 5,"line": 6,"col": 0},{"file": 5,"line": 2,"col": 0},{"file": 5,"line": 4,"col": 0},{"file": 5,"line": 1838,"col": 0,"fields": [1516]},{"file": 5,"line": 3,"col": 0},{"file": 5,"line": 1,"col": 0},{"file": 5,"line": 8,"col": 0},{"file": 5,"line": 2072,"col": 0,"fields": [1517]},{"file": 5,"line": 7,"col": 0},{"file": 5,"line": 1590,"col": 0,"fields": []},{"file": 5,"line": 305,"col": 0,"fields": [1518,1519,1520,1521,1522]},{"file": 5,"line": 0,"col": 0},{"file": 5,"line": 5,"col": 0},{"file": 6,"line": 153,"col": 4},{"file": 6,"line": 150,"col": 4},{"file": 6,"line": 151,"col": 4},{"file": 6,"line": 194,"col": 4},{"file": 6,"line": 154,"col": 4},{"file": 6,"line": 87,"col": 4},{"file": 6,"line": 162,"col": 4},{"file": 6,"line": 179,"col": 4},{"file": 6,"line": 66,"col": 4},{"file": 6,"line": 560,"col": 4},{"file": 6,"line": 42,"col": 4},{"file": 6,"line": 416,"col": 4,"docs": " Rotates right. Only unsigned values can be rotated.\n Negative shift values results in shift modulo the bit count.\n","fields": [1523,1524,1525]},{"file": 6,"line": 686,"col": 4,"docs": " Returns the absolute value of the integer parameter.\n Result is an unsigned integer.\n","fields": [1526]},{"file": 6,"line": 174,"col": 4},{"file": 6,"line": 82,"col": 4},{"file": 6,"line": 979,"col": 4,"docs": " See also `CompareOperator`.\n"},{"file": 6,"line": 156,"col": 4},{"file": 6,"line": 70,"col": 4},{"file": 6,"line": 592,"col": 4,"fields": [1527,1528,1529]},{"file": 6,"line": 822,"col": 4,"docs": " Returns the next power of two (if the value is not already a power of two).\n Only unsigned integers can be used. Zero is not an allowed input.\n If the value doesn't fit, returns an error.\n","fields": [1530,1531]},{"file": 6,"line": 967,"col": 4,"fields": [1532,1533,1534]},{"file": 6,"line": 193,"col": 4},{"file": 6,"line": 75,"col": 4},{"file": 6,"line": 388,"col": 4,"docs": " Shifts right. Overflowed bits are truncated.\n A negative shift amount results in a left shift.\n","fields": [1535,1536,1537]},{"file": 6,"line": 190,"col": 4},{"file": 6,"line": 197,"col": 4},{"file": 6,"line": 46,"col": 4},{"file": 6,"line": 744,"col": 4,"docs": " Cast an integer to a different integer type. If the value doesn't fit,\n return an error.\n","fields": [1538,1539]},{"file": 6,"line": 35,"col": 4},{"file": 6,"line": 26,"col": 4,"docs": " 2/sqrt(π)\n"},{"file": 6,"line": 191,"col": 4},{"file": 6,"line": 158,"col": 4},{"file": 6,"line": 201,"col": 4},{"file": 6,"line": 138,"col": 4,"fields": []},{"file": 6,"line": 94,"col": 4},{"file": 6,"line": 98,"col": 4},{"file": 6,"line": 341,"col": 4,"fields": [1540,1541,1542]},{"file": 6,"line": 192,"col": 4},{"file": 6,"line": 894,"col": 4,"fields": [1543,1544]},{"file": 6,"line": 160,"col": 4},{"file": 6,"line": 638,"col": 4,"fields": [1545,1546,1547]},{"file": 6,"line": 50,"col": 4},{"file": 6,"line": 32,"col": 4,"docs": " 1/sqrt(2)\n"},{"file": 6,"line": 1028,"col": 4,"docs": " Given two numbers, this function returns the order they are with respect to each other.\n","fields": [1548,1549]},{"file": 6,"line": 198,"col": 4},{"file": 6,"line": 183,"col": 4},{"file": 6,"line": 196,"col": 4},{"file": 6,"line": 45,"col": 4},{"file": 6,"line": 84,"col": 4},{"file": 6,"line": 176,"col": 4},{"file": 6,"line": 60,"col": 4},{"file": 6,"line": 76,"col": 4},{"file": 6,"line": 48,"col": 4},{"file": 6,"line": 152,"col": 4},{"file": 6,"line": 200,"col": 4},{"file": 6,"line": 315,"col": 4,"fields": [1550,1551,1552]},{"file": 6,"line": 177,"col": 4},{"file": 6,"line": 146,"col": 4,"fields": []},{"file": 6,"line": 97,"col": 4},{"file": 6,"line": 54,"col": 4},{"file": 6,"line": 167,"col": 4},{"file": 6,"line": 17,"col": 4,"docs": " log10(e)\n"},{"file": 6,"line": 52,"col": 4},{"file": 6,"line": 171,"col": 4},{"file": 6,"line": 186,"col": 4},{"file": 6,"line": 85,"col": 4},{"file": 6,"line": 873,"col": 4,"fields": [1553,1554]},{"file": 6,"line": 170,"col": 4},{"file": 6,"line": 81,"col": 4},{"file": 6,"line": 5,"col": 4,"docs": " Euler's number (e)\n"},{"file": 6,"line": 810,"col": 4,"docs": " Returns the next power of two (if the value is not already a power of two).\n Only unsigned integers can be used. Zero is not an allowed input.\n Result is a type with 1 more bit than the input type.\n","fields": [1555,1556]},{"file": 6,"line": 55,"col": 4},{"file": 6,"line": 182,"col": 4},{"file": 6,"line": 169,"col": 4},{"file": 6,"line": 355,"col": 4,"fields": [1557,1558,1559]},{"file": 6,"line": 88,"col": 4},{"file": 6,"line": 157,"col": 4},{"file": 6,"line": 73,"col": 4},{"file": 6,"line": 63,"col": 4},{"file": 6,"line": 49,"col": 4},{"file": 6,"line": 159,"col": 4},{"file": 6,"line": 1041,"col": 4,"docs": " See also `Order`.\n"},{"file": 6,"line": 57,"col": 4},{"file": 6,"line": 661,"col": 4,"fields": [1560,1561,1562]},{"file": 6,"line": 72,"col": 4},{"file": 6,"line": 23,"col": 4,"docs": " ln(10)\n"},{"file": 6,"line": 90,"col": 4},{"file": 6,"line": 346,"col": 4,"fields": [1563,1564,1565]},{"file": 6,"line": 209,"col": 4,"fields": [1566]},{"file": 6,"line": 69,"col": 4},{"file": 6,"line": 175,"col": 4},{"file": 6,"line": 56,"col": 4},{"file": 6,"line": 782,"col": 4,"fields": [1567,1568]},{"file": 6,"line": 180,"col": 4},{"file": 6,"line": 64,"col": 4},{"file": 6,"line": 43,"col": 4},{"file": 6,"line": 187,"col": 4},{"file": 6,"line": 61,"col": 4},{"file": 6,"line": 39,"col": 4},{"file": 6,"line": 463,"col": 4,"fields": [1569,1570]},{"file": 6,"line": 78,"col": 4},{"file": 6,"line": 435,"col": 4,"docs": " Rotates left. Only unsigned values can be rotated.\n Negative shift values results in shift modulo the bit count.\n","fields": [1571,1572,1573]},{"file": 6,"line": 29,"col": 4,"docs": " sqrt(2)\n"},{"file": 6,"line": 185,"col": 4},{"file": 6,"line": 134,"col": 4,"fields": []},{"file": 6,"line": 917,"col": 4,"fields": [1574]},{"file": 6,"line": 351,"col": 4,"fields": [1575]},{"file": 6,"line": 91,"col": 4},{"file": 6,"line": 769,"col": 4,"docs": " Align cast a pointer but return an error if it's the wrong alignment\n","fields": [1576,1577]},{"file": 6,"line": 58,"col": 4},{"file": 6,"line": 165,"col": 4},{"file": 6,"line": 161,"col": 4},{"file": 6,"line": 38,"col": 4},{"file": 6,"line": 336,"col": 4,"fields": [1578,1579,1580]},{"file": 6,"line": 36,"col": 4},{"file": 6,"line": 613,"col": 4,"fields": [1581,1582,1583]},{"file": 6,"line": 721,"col": 4,"docs": " Returns the negation of the integer parameter.\n Result is a signed integer.\n","fields": [1584]},{"file": 6,"line": 164,"col": 4},{"file": 6,"line": 79,"col": 4},{"file": 6,"line": 37,"col": 4},{"file": 6,"line": 51,"col": 4},{"file": 6,"line": 106,"col": 4,"fields": [1585]},{"file": 6,"line": 168,"col": 4},{"file": 6,"line": 130,"col": 4,"fields": []},{"file": 6,"line": 1064,"col": 4,"docs": " This function does the same thing as comparison operators, however the\n operator is a runtime-known enum value. Works on any operands that\n support comparison operators.\n","fields": [1586,1587,1588]},{"file": 6,"line": 362,"col": 4,"docs": " Shifts left. Overflowed bits are truncated.\n A negative shift amount results in a right shift.\n","fields": [1589,1590,1591]},{"file": 6,"line": 20,"col": 4,"docs": " ln(2)\n"},{"file": 6,"line": 203,"col": 4},{"file": 6,"line": 44,"col": 4},{"file": 6,"line": 67,"col": 4},{"file": 6,"line": 96,"col": 4},{"file": 6,"line": 142,"col": 4,"fields": []},{"file": 6,"line": 93,"col": 4},{"file": 6,"line": 163,"col": 4},{"file": 6,"line": 189,"col": 4},{"file": 6,"line": 166,"col": 4},{"file": 6,"line": 173,"col": 4},{"file": 6,"line": 195,"col": 4},{"file": 6,"line": 100,"col": 4,"fields": [1592,1593,1594,1595]},{"file": 6,"line": 155,"col": 4},{"file": 6,"line": 222,"col": 4,"fields": [1596]},{"file": 6,"line": 11,"col": 4,"docs": " Circle constant (τ)\n"},{"file": 6,"line": 181,"col": 4},{"file": 6,"line": 188,"col": 4},{"file": 6,"line": 766,"col": 4},{"file": 6,"line": 8,"col": 4,"docs": " Archimedes' constant (π)\n"},{"file": 6,"line": 14,"col": 4,"docs": " log2(e)\n"},{"file": 6,"line": 172,"col": 4},{"file": 6,"line": 538,"col": 4,"fields": [1597]},{"file": 6,"line": 571,"col": 4,"fields": [1598,1599,1600]},{"file": 6,"line": 178,"col": 4},{"file": 6,"line": 184,"col": 4},{"file": 6,"line": 566,"col": 0,"fields": []},{"file": 6,"line": 603,"col": 0,"fields": []},{"file": 6,"line": 856,"col": 0,"fields": []},{"file": 6,"line": 1,"col": 0},{"file": 6,"line": 649,"col": 0,"fields": []},{"file": 6,"line": 839,"col": 0,"fields": []},{"file": 6,"line": 672,"col": 0,"fields": []},{"file": 6,"line": 798,"col": 0,"fields": []},{"file": 6,"line": 531,"col": 0,"fields": []},{"file": 6,"line": 626,"col": 0,"fields": []},{"file": 6,"line": 2,"col": 0},{"file": 6,"line": 0,"col": 0},{"file": 6,"line": 555,"col": 0,"fields": []},{"file": 6,"line": 582,"col": 0,"fields": []},{"file": 7,"line": 40,"col": 4},{"file": 7,"line": 431,"col": 4},{"file": 7,"line": 1715,"col": 4,"docs": " Attaches a global SIGSEGV handler which calls @panic(\"segmentation fault\");\n","fields": []},{"file": 7,"line": 160,"col": 4,"docs": " Returns a slice with the same pointer as addresses, with a potentially smaller len.\n On Windows, when first_address is not null, we ask for at least 32 stack frames,\n and then try to find the first address. If addresses.len is more than 32, we\n capture that many stack frames exactly, and then look for the first address,\n chopping off the irrelevant frames and shifting so that the returned addresses pointer\n equals the passed in addresses pointer.\n","fields": [1601,1602]},{"file": 7,"line": 411,"col": 4,"fields": [1603,1604,1605,1606]},{"file": 7,"line": 113,"col": 4,"docs": " Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned.\n TODO multithreaded awareness\n","fields": [1607]},{"file": 7,"line": 67,"col": 4,"fields": []},{"file": 7,"line": 1696,"col": 4,"docs": " Whether or not the current target can print useful debug information when a segfault occurs.\n"},{"file": 7,"line": 95,"col": 4,"fields": []},{"file": 7,"line": 396,"col": 4,"fields": [1608,1609,1610,1611]},{"file": 7,"line": 204,"col": 4,"docs": " Tries to print a stack trace to stderr, unbuffered, and ignores any error returned.\n TODO multithreaded awareness\n","fields": [1612]},{"file": 7,"line": 1087,"col": 4},{"file": 7,"line": 1701,"col": 4},{"file": 7,"line": 317,"col": 4,"fields": [1613,1614,1615,1616,1617]},{"file": 7,"line": 19,"col": 4},{"file": 7,"line": 1329,"col": 4},{"file": 7,"line": 86,"col": 4,"fields": []},{"file": 7,"line": 236,"col": 4,"fields": [1618,1619]},{"file": 7,"line": 567,"col": 4,"docs": " TODO resources https://github.com/ziglang/zig/issues/4353\n","fields": [1620,1621,1622,1623]},{"file": 7,"line": 337,"col": 4},{"file": 7,"line": 859,"col": 4,"docs": " This takes ownership of elf_file: users of this function should not close\n it themselves, even on error.\n TODO resources https://github.com/ziglang/zig/issues/4353\n TODO it's weird to take ownership even on error, rework this code.\n","fields": [1624,1625]},{"file": 7,"line": 645,"col": 4},{"file": 7,"line": 254,"col": 4,"fields": [1626,1627,1628,1629]},{"file": 7,"line": 1706,"col": 4,"fields": []},{"file": 7,"line": 24,"col": 4},{"file": 7,"line": 134,"col": 4,"docs": " Tries to print the stack trace starting from the supplied base pointer to stderr,\n unbuffered, and ignores any error returned.\n TODO multithreaded awareness\n","fields": [1630,1631]},{"file": 7,"line": 1838,"col": 4,"fields": [1632]},{"file": 7,"line": 79,"col": 4,"fields": []},{"file": 7,"line": 22,"col": 4},{"file": 7,"line": 652,"col": 4,"docs": " TODO resources https://github.com/ziglang/zig/issues/4353\n","fields": [1633]},{"file": 7,"line": 60,"col": 4,"fields": [1634,1635]},{"file": 7,"line": 21,"col": 4},{"file": 7,"line": 313,"col": 0},{"file": 7,"line": 248,"col": 0},{"file": 7,"line": 1804,"col": 0,"fields": [1636]},{"file": 7,"line": 9,"col": 0},{"file": 7,"line": 245,"col": 0,"docs": " Non-zero whenever the program triggered a panic.\n The counter is incremented/decremented atomically.\n"},{"file": 7,"line": 5,"col": 0},{"file": 7,"line": 931,"col": 0,"docs": " TODO resources https://github.com/ziglang/zig/issues/4353\n This takes ownership of coff_file: users of this function should not close\n it themselves, even on error.\n TODO it's weird to take ownership even on error, rework this code.\n","fields": [1637,1638]},{"file": 7,"line": 832,"col": 0,"fields": [1639,1640]},{"file": 7,"line": 315,"col": 0},{"file": 7,"line": 8,"col": 0},{"file": 7,"line": 1050,"col": 0},{"file": 7,"line": 1317,"col": 0},{"file": 7,"line": 1068,"col": 0,"docs": " `file` is expected to have been opened with .intended_io_mode == .blocking.\n Takes ownership of file, even on error.\n TODO it's weird to take ownership even on error, rework this code.\n","fields": [1641]},{"file": 7,"line": 4,"col": 0},{"file": 7,"line": 312,"col": 0},{"file": 7,"line": 14,"col": 0},{"file": 7,"line": 15,"col": 0},{"file": 7,"line": 11,"col": 0},{"file": 7,"line": 314,"col": 0},{"file": 7,"line": 311,"col": 0},{"file": 7,"line": 6,"col": 0},{"file": 7,"line": 16,"col": 0},{"file": 7,"line": 1016,"col": 0,"fields": [1642,1643]},{"file": 7,"line": 252,"col": 12,"docs": " Counts how many times the panic handler is invoked by this thread.\n This is used to catch and handle panics triggered by the panic handler.\n"},{"file": 7,"line": 597,"col": 0,"fields": [1644,1645,1646,1647,1648,1649,1650]},{"file": 7,"line": 7,"col": 0},{"file": 7,"line": 10,"col": 0},{"file": 7,"line": 1687,"col": 0,"fields": []},{"file": 7,"line": 1,"col": 0},{"file": 7,"line": 1712,"col": 0},{"file": 7,"line": 1685,"col": 0,"docs": " TODO multithreaded awareness\n"},{"file": 7,"line": 2,"col": 0},{"file": 7,"line": 1815,"col": 0,"fields": [1651,1652,1653]},{"file": 7,"line": 54,"col": 0,"docs": " Tries to write to stderr, unbuffered, and ignores any error returned.\n Does not append a newline.\n"},{"file": 7,"line": 29,"col": 0},{"file": 7,"line": 1734,"col": 0,"fields": []},{"file": 7,"line": 57,"col": 0},{"file": 7,"line": 58,"col": 0},{"file": 7,"line": 12,"col": 0},{"file": 7,"line": 0,"col": 0},{"file": 7,"line": 849,"col": 0,"fields": [1654,1655,1656]},{"file": 7,"line": 548,"col": 0,"fields": [1657,1658]},{"file": 7,"line": 1752,"col": 0,"fields": [1659,1660,1661]},{"file": 7,"line": 17,"col": 0},{"file": 7,"line": 55,"col": 0},{"file": 7,"line": 84,"col": 0,"docs": " TODO multithreaded awareness\n"},{"file": 7,"line": 676,"col": 0,"docs": " This takes ownership of coff_file: users of this function should not close\n it themselves, even on error.\n TODO resources https://github.com/ziglang/zig/issues/4353\n TODO it's weird to take ownership even on error, rework this code.\n","fields": [1662,1663]},{"file": 7,"line": 13,"col": 0},{"file": 7,"line": 1686,"col": 0},{"file": 7,"line": 310,"col": 0},{"file": 7,"line": 3,"col": 0},{"file": 7,"line": 502,"col": 0,"docs": " TODO resources https://github.com/ziglang/zig/issues/4353\n","fields": [1664,1665]},{"file": 8,"line": 482,"col": 4,"docs": " Compares two of any type for equality. Containers are compared on a field-by-field basis,\n where possible. Pointers are not followed.\n","fields": [1666,1667]},{"file": 8,"line": 126,"col": 4,"fields": [1668]},{"file": 8,"line": 98,"col": 4,"fields": [1669]},{"file": 8,"line": 252,"col": 4,"fields": [1670]},{"file": 8,"line": 641,"col": 4,"docs": " Given a type and a name, return the field index according to source order.\n Returns `null` if the field is not found.\n","fields": [1671,1672]},{"file": 8,"line": 650,"col": 4,"docs": " Given a type, reference all the declarations inside, so that the semantic analyzer sees them.\n","fields": [1673]},{"file": 8,"line": 627,"col": 4},{"file": 8,"line": 112,"col": 4,"fields": [1674]},{"file": 8,"line": 676,"col": 4,"docs": " Deprecated: use Int\n"},{"file": 8,"line": 687,"col": 4,"fields": [1675,1676]},{"file": 8,"line": 369,"col": 4,"fields": [1677,1678]},{"file": 8,"line": 432,"col": 4,"docs": "Returns the active tag of a tagged union\n","fields": [1679]},{"file": 8,"line": 288,"col": 4,"fields": [1680,1681]},{"file": 8,"line": 658,"col": 4,"docs": " Returns a slice of pointers to public declarations of a namespace.\n","fields": [1682,1683]},{"file": 8,"line": 7,"col": 4},{"file": 8,"line": 409,"col": 4,"fields": [1684]},{"file": 8,"line": 174,"col": 4,"docs": " Given a type which can have a sentinel e.g. `[:0]u8`, returns the sentinel value,\n or `null` if there is not one.\n Types which cannot possibly have a sentinel will be a compile error.\n","fields": [1685]},{"file": 8,"line": 209,"col": 4,"fields": [1686]},{"file": 8,"line": 11,"col": 4,"fields": [1687]},{"file": 8,"line": 145,"col": 4,"docs": " Given a \"memory span\" type, returns the \"element type\".\n","fields": [1688]},{"file": 8,"line": 629,"col": 4,"fields": [1689,1690]},{"file": 8,"line": 457,"col": 4,"docs": "Given a tagged union type, and an enum, return the type of the union\n field corresponding to the enum tag.\n","fields": [1691,1692]},{"file": 8,"line": 324,"col": 4,"fields": [1693]},{"file": 8,"line": 54,"col": 4,"fields": [1694,1695]},{"file": 8,"line": 3,"col": 0},{"file": 8,"line": 1,"col": 0},{"file": 8,"line": 4,"col": 0},{"file": 8,"line": 0,"col": 0},{"file": 8,"line": 2,"col": 0},{"file": 8,"line": 5,"col": 0},{"file": 8,"line": 197,"col": 0,"fields": []},{"file": 8,"line": 9,"col": 0},{"file": 9,"line": 235,"col": 4,"fields": []},{"file": 9,"line": 4,"col": 0},{"file": 9,"line": 226,"col": 0,"fields": [1696]},{"file": 9,"line": 60,"col": 0,"fields": [1697,1698]},{"file": 9,"line": 2,"col": 0},{"file": 9,"line": 6,"col": 0},{"file": 9,"line": 190,"col": 0,"fields": [1699,1700,1701]},{"file": 9,"line": 181,"col": 0,"fields": [1702,1703,1704]},{"file": 9,"line": 10,"col": 0},{"file": 9,"line": 125,"col": 0,"fields": []},{"file": 9,"line": 137,"col": 0,"fields": []},{"file": 9,"line": 38,"col": 0,"fields": [1705,1706,1707]},{"file": 9,"line": 3,"col": 0},{"file": 9,"line": 8,"col": 0},{"file": 9,"line": 54,"col": 0,"fields": []},{"file": 9,"line": 202,"col": 0,"fields": []},{"file": 9,"line": 5,"col": 0},{"file": 9,"line": 198,"col": 0},{"file": 9,"line": 82,"col": 0,"fields": []},{"file": 10,"line": 997,"col": 8,"fields": [1708]},{"file": 10,"line": 310,"col": 8},{"file": 10,"line": 297,"col": 8},{"file": 10,"line": 1045,"col": 8,"fields": [1709]},{"file": 10,"line": 969,"col": 8,"fields": [1710,1711]},{"file": 10,"line": 967,"col": 8},{"file": 10,"line": 1094,"col": 8,"fields": [1712]},{"file": 10,"line": 1057,"col": 8,"fields": [1713]},{"file": 10,"line": 308,"col": 8},{"file": 10,"line": 1072,"col": 8,"fields": [1714]},{"file": 10,"line": 1049,"col": 8,"fields": [1715]},{"file": 10,"line": 973,"col": 8,"fields": [1716,1717,1718,1719]},{"file": 10,"line": 1011,"col": 8,"fields": [1720]},{"file": 10,"line": 1001,"col": 8,"fields": [1721,1722]},{"file": 10,"line": 981,"col": 8,"fields": [1723]},{"file": 10,"line": 1033,"col": 8,"fields": [1724,1725]},{"file": 10,"line": 1019,"col": 8,"fields": [1726,1727]},{"file": 10,"line": 1053,"col": 8,"fields": [1728]},{"file": 10,"line": 425,"col": 8},{"file": 10,"line": 306,"col": 8},{"file": 10,"line": 1104,"col": 8,"fields": [1729]},{"file": 10,"line": 1123,"col": 8},{"file": 10,"line": 305,"col": 8},{"file": 10,"line": 1015,"col": 8,"fields": [1730]},{"file": 10,"line": 298,"col": 8},{"file": 10,"line": 1156,"col": 8,"fields": [1731]},{"file": 10,"line": 13,"col": 8},{"file": 10,"line": 1084,"col": 8,"fields": [1732]},{"file": 10,"line": 312,"col": 8},{"file": 10,"line": 985,"col": 8,"fields": [1733,1734]},{"file": 10,"line": 300,"col": 8},{"file": 10,"line": 309,"col": 8},{"file": 10,"line": 977,"col": 8,"fields": [1735,1736]},{"file": 10,"line": 302,"col": 8},{"file": 10,"line": 307,"col": 8},{"file": 10,"line": 299,"col": 8},{"file": 10,"line": 1076,"col": 8,"fields": [1737,1738]},{"file": 10,"line": 405,"col": 8},{"file": 10,"line": 1088,"col": 8},{"file": 10,"line": 961,"col": 8},{"file": 10,"line": 301,"col": 8},{"file": 10,"line": 1061,"col": 8,"fields": [1739]},{"file": 10,"line": 1080,"col": 8,"fields": [1740]},{"file": 10,"line": 1029,"col": 8,"fields": [1741]},{"file": 10,"line": 414,"col": 8},{"file": 10,"line": 303,"col": 8},{"file": 10,"line": 296,"col": 8},{"file": 10,"line": 304,"col": 8},{"file": 10,"line": 1068,"col": 8,"fields": [1742]},{"file": 10,"line": 8,"col": 4,"docs": " TODO Nearly all the functions in this namespace would be\n better off if https://github.com/ziglang/zig/issues/425\n was solved.\n"},{"file": 10,"line": 2,"col": 0},{"file": 10,"line": 0,"col": 0},{"file": 10,"line": 3,"col": 0},{"file": 10,"line": 1,"col": 0},{"file": 10,"line": 63,"col": 16,"fields": [1743]},{"file": 10,"line": 56,"col": 16,"fields": [1744]},{"file": 10,"line": 109,"col": 16,"fields": [1745,1746]},{"file": 10,"line": 95,"col": 16},{"file": 10,"line": 143,"col": 16,"docs": " The default `VersionRange` represents the range that the Zig Standard Library\n bases its abstractions on.\n","fields": [1747]},{"file": 4,"line": 408,"col": 12,"fields": [1748,1749]},{"file": 4,"line": 195,"col": 12,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 4,"line": 339,"col": 12,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 10,"line": 552,"col": 12},{"file": 10,"line": 894,"col": 12},{"file": 10,"line": 956,"col": 12,"docs": " The \"default\" set of CPU features for cross-compiling. A conservative set\n of features that is expected to be supported on most available hardware.\n","fields": [1750]},{"file": 10,"line": 436,"col": 12},{"file": 10,"line": 390,"col": 12,"fields": [1751]},{"file": 10,"line": 397,"col": 12,"fields": [1752]},{"file": 10,"line": 334,"col": 12,"fields": [1753,1754]},{"file": 10,"line": 383,"col": 12,"fields": [1755]},{"file": 10,"line": 99,"col": 20,"fields": [1756,1757]},{"file": 4,"line": 346,"col": 16,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 10,"line": 941,"col": 16,"fields": [1758]},{"file": 10,"line": 909,"col": 16,"fields": [1759]},{"file": 10,"line": 899,"col": 16,"fields": [1760,1761]},{"file": 10,"line": 534,"col": 16,"fields": [1762]},{"file": 10,"line": 456,"col": 16,"docs": " A bit set of all the features.\n"},{"file": 10,"line": 459,"col": 20},{"file": 10,"line": 490,"col": 20,"docs": " Adds the specified feature set but not its dependencies.\n","fields": [1763,1764]},{"file": 10,"line": 503,"col": 20,"docs": " Removes the specified feature but not its dependents.\n","fields": [1765,1766]},{"file": 10,"line": 496,"col": 20,"docs": " Removes the specified feature but not its dependents.\n","fields": [1767,1768]},{"file": 10,"line": 463,"col": 20},{"file": 10,"line": 462,"col": 20},{"file": 10,"line": 525,"col": 20,"fields": [1769]},{"file": 10,"line": 476,"col": 20,"fields": [1770,1771]},{"file": 10,"line": 465,"col": 20},{"file": 10,"line": 460,"col": 20},{"file": 10,"line": 461,"col": 20},{"file": 10,"line": 483,"col": 20,"docs": " Adds the specified feature but not its dependencies.\n","fields": [1772,1773]},{"file": 10,"line": 466,"col": 20,"fields": []},{"file": 10,"line": 529,"col": 20,"fields": [1774,1775]},{"file": 10,"line": 470,"col": 20,"fields": [1776]},{"file": 10,"line": 508,"col": 20,"fields": [1777,1778]},{"file": 4,"line": 358,"col": 20,"docs": " This data structure is used by the Zig language code generation and\n therefore must be kept in sync with the compiler implementation.\n"},{"file": 5,"line": 16,"col": 28},{"file": 3,"line": 154,"col": 32},{"file": 4,"line": 525,"col": 21,"name": "msg"},{"file": 4,"line": 525,"col": 38,"name": "error_return_trace"},{"file": 7,"line": 232,"col": 14,"name": "ok"},{"file": 3,"line": 234,"col": 20,"name": "backing_allocator"},{"file": 3,"line": 485,"col": 23,"name": "allocator"},{"file": 3,"line": 485,"col": 46,"name": "old_mem"},{"file": 3,"line": 485,"col": 61,"name": "old_align"},{"file": 3,"line": 485,"col": 77,"name": "new_size"},{"file": 3,"line": 485,"col": 94,"name": "new_align"},{"file": 3,"line": 392,"col": 19,"name": "allocator"},{"file": 3,"line": 392,"col": 42,"name": "old_mem"},{"file": 3,"line": 392,"col": 57,"name": "old_align"},{"file": 3,"line": 392,"col": 73,"name": "new_size"},{"file": 3,"line": 392,"col": 90,"name": "new_align"},{"file": 3,"line": 430,"col": 18,"name": "allocator"},{"file": 3,"line": 430,"col": 41,"name": "old_mem"},{"file": 3,"line": 430,"col": 56,"name": "old_align"},{"file": 3,"line": 430,"col": 72,"name": "new_size"},{"file": 3,"line": 430,"col": 89,"name": "new_align"},{"file": 3,"line": 518,"col": 22,"name": "size"},{"file": 3,"line": 526,"col": 22,"name": "num_elements"},{"file": 3,"line": 526,"col": 43,"name": "element_size"},{"file": 3,"line": 535,"col": 23,"name": "c_ptr"},{"file": 3,"line": 535,"col": 40,"name": "new_size"},{"file": 3,"line": 549,"col": 20,"name": "c_ptr"},{"file": 3,"line": 470,"col": 12,"name": "run_assert","comptime": true},{"file": 3,"line": 470,"col": 39,"name": "ok"},{"file": 3,"line": 145,"col": 34,"name": "payload"},{"file": 3,"line": 169,"col": 31,"name": "self"},{"file": 3,"line": 174,"col": 32,"name": "self"},{"file": 3,"line": 174,"col": 46,"name": "start"},{"file": 3,"line": 174,"col": 60,"name": "end"},{"file": 3,"line": 245,"col": 24,"name": "self"},{"file": 3,"line": 245,"col": 37,"name": "memsize"},{"file": 3,"line": 238,"col": 21,"name": "self"},{"file": 3,"line": 238,"col": 34,"name": "memsize"},{"file": 3,"line": 351,"col": 30,"name": "size"},{"file": 3,"line": 130,"col": 24,"name": "raw_bytes"},{"file": 3,"line": 165,"col": 33,"name": "self"},{"file": 3,"line": 290,"col": 20,"name": "self"},{"file": 3,"line": 290,"col": 33,"name": "node"},{"file": 3,"line": 290,"col": 47,"name": "target_size"},{"file": 5,"line": 317,"col": 12,"name": "T","comptime": true},{"file": 5,"line": 317,"col": 30,"name": "dest"},{"file": 5,"line": 317,"col": 41,"name": "source"},{"file": 3,"line": 311,"col": 16,"name": "self"},{"file": 3,"line": 311,"col": 29,"name": "target"},{"file": 3,"line": 161,"col": 31,"name": "self"},{"file": 3,"line": 97,"col": 26,"name": "self","comptime": true},{"file": 3,"line": 97,"col": 53,"name": "ok"},{"file": 3,"line": 152,"col": 28,"name": "self"},{"file": 3,"line": 126,"col": 29,"name": "memsize"},{"file": 3,"line": 92,"col": 26,"name": "self","comptime": true},{"file": 3,"line": 92,"col": 53,"name": "ok"},{"file": 3,"line": 357,"col": 26,"name": "self"},{"file": 3,"line": 357,"col": 39,"name": "memsize"},{"file": 3,"line": 378,"col": 25,"name": "self"},{"file": 3,"line": 378,"col": 38,"name": "frame_size"},{"file": 3,"line": 190,"col": 24,"name": "self"},{"file": 3,"line": 215,"col": 31,"name": "self"},{"file": 3,"line": 215,"col": 48,"name": "ref"},{"file": 3,"line": 372,"col": 26,"name": "self"},{"file": 3,"line": 372,"col": 39,"name": "frame_size"},{"file": 3,"line": 198,"col": 27,"name": "self"},{"file": 3,"line": 198,"col": 44,"name": "node"},{"file": 6,"line": 777,"col": 20,"name": "v"},{"file": 6,"line": 307,"col": 11,"name": "x"},{"file": 6,"line": 307,"col": 19,"name": "y"},{"file": 3,"line": 338,"col": 32,"name": "T","comptime": true},{"file": 3,"line": 338,"col": 50,"name": "value"},{"file": 6,"line": 256,"col": 11,"name": "x"},{"file": 6,"line": 256,"col": 19,"name": "y"},{"file": 3,"line": 345,"col": 25,"name": "T","comptime": true},{"file": 3,"line": 345,"col": 43,"name": "x"},{"file": 6,"line": 452,"col": 15,"name": "T","comptime": true},{"file": 6,"line": 910,"col": 14,"name": "T","comptime": true},{"file": 8,"line": 678,"col": 11,"name": "is_signed","comptime": true},{"file": 8,"line": 678,"col": 37,"name": "bit_count","comptime": true},{"file": 3,"line": 84,"col": 23,"name": "self","comptime": true},{"file": 3,"line": 104,"col": 16,"name": "conf","comptime": true},{"file": 3,"line": 516,"col": 15,"name": "conf","comptime": true},{"file": 6,"line": 237,"col": 11,"name": "A","comptime": true},{"file": 6,"line": 237,"col": 29,"name": "B","comptime": true},{"file": 3,"line": 77,"col": 23,"name": "self","comptime": true},{"file": 6,"line": 868,"col": 16,"name": "T","comptime": true},{"file": 6,"line": 868,"col": 34,"name": "x"},{"file": 3,"line": 69,"col": 8,"docs": " Enable all validations, including library internals\n","name": "Dev"},{"file": 3,"line": 72,"col": 8,"docs": " Only validate external boundaries — e.g. `realloc` or `free`\n","name": "External"},{"file": 3,"line": 75,"col": 8,"docs": " Turn off all validations — pretend this library is `--release-small`\n","name": "Unsafe"},{"file": 3,"line": 226,"col": 8,"name": "backing_allocator"},{"file": 3,"line": 228,"col": 8,"name": "free_lists"},{"file": 3,"line": 229,"col": 8,"name": "allocator"},{"file": 3,"line": 16,"col": 4,"docs": " ZeeAlloc will request a multiple of `page_size` from the backing allocator.\n **Must** be a power of two.\n","name": "page_size"},{"file": 3,"line": 17,"col": 4,"name": "validation"},{"file": 3,"line": 19,"col": 4,"name": "jumbo_match_strategy"},{"file": 3,"line": 20,"col": 4,"name": "buddy_strategy"},{"file": 3,"line": 21,"col": 4,"name": "shrink_strategy"},{"file": 3,"line": 510,"col": 4,"name": "allocator"},{"file": 3,"line": 511,"col": 4,"name": "malloc"},{"file": 3,"line": 512,"col": 4,"name": "free"},{"file": 3,"line": 513,"col": 4,"name": "calloc"},{"file": 3,"line": 514,"col": 4,"name": "realloc"},{"file": 3,"line": 184,"col": 12,"name": "first"},{"file": 3,"line": 121,"col": 12,"name": "next"},{"file": 3,"line": 122,"col": 12,"name": "frame_size"},{"file": 3,"line": 124,"col": 12,"name": "payload"},{"file": 5,"line": 39,"col": 4,"docs": " Realloc is used to modify the size or alignment of an existing allocation,\n as well as to provide the allocator with an opportunity to move an allocation\n to a better location.\n When the size/alignment is greater than the previous allocation, this function\n returns `error.OutOfMemory` when the requested new allocation could not be granted.\n When the size/alignment is less than or equal to the previous allocation,\n this function returns `error.OutOfMemory` when the allocator decides the client\n would be better off keeping the extra alignment/size. Clients will call\n `shrinkFn` when they require the allocator to track a new alignment/size,\n and so this function should only return success when the allocator considers\n the reallocation desirable from the allocator's perspective.\n As an example, `std.ArrayList` tracks a \"capacity\", and therefore can handle\n reallocation failure, even when `new_n` <= `old_mem.len`. A `FixedBufferAllocator`\n would always return `error.OutOfMemory` for `reallocFn` when the size/alignment\n is less than or equal to the old allocation, because it cannot reclaim the memory,\n and thus the `std.ArrayList` would be better off retaining its capacity.\n When `reallocFn` returns,\n `return_value[0..min(old_mem.len, new_byte_count)]` must be the same\n as `old_mem` was when `reallocFn` is called. The bytes of\n `return_value[old_mem.len..]` have undefined values.\n The returned slice must have its pointer aligned at least to `new_alignment` bytes.\n","name": "reallocFn"},{"file": 5,"line": 62,"col": 4,"docs": " This function deallocates memory. It must succeed.\n","name": "shrinkFn"},{"file": 3,"line": 26,"col": 8,"docs": " Use the frame that wastes the least space\n Scans the entire jumbo freelist, which is slower but keeps memory pretty tidy\n","name": "Closest"},{"file": 3,"line": 31,"col": 8,"docs": " Use only exact matches\n -75 bytes vs `.Closest`\n Similar performance to Closest if allocation sizes are consistent throughout lifetime\n","name": "Exact"},{"file": 3,"line": 36,"col": 8,"docs": " Use the first frame that fits\n -75 bytes vs `.Closest`\n Initially faster to allocate but causes major fragmentation issues\n","name": "First"},{"file": 3,"line": 54,"col": 8,"docs": " Return a smaller view into the same frame\n Faster because it ignores shrink, but never reclaims space until freed\n","name": "Defer"},{"file": 3,"line": 59,"col": 8,"docs": " Split the frame into smallest usable chunk\n +112 bytes vs `.Defer`\n Better at reclaiming non-jumbo memory, but never reclaims jumbo until freed\n","name": "Chunkify"},{"file": 3,"line": 64,"col": 8,"docs": " Find and swap a replacement frame\n +295 bytes vs `.Defer`\n Reclaims all memory, but generally slower\n","name": "Swap"},{"file": 3,"line": 43,"col": 8,"docs": " Return the raw free frame immediately\n Generally faster because it does not recombine or resplit frames,\n but it also requires more underlying memory\n","name": "Fast"},{"file": 3,"line": 48,"col": 8,"docs": " Recombine with free buddies to reclaim storage\n +153 bytes vs `.Fast`\n More efficient use of existing memory at the cost of cycles and bytes\n","name": "Coalesce"},{"file": 4,"line": 385,"col": 4,"name": "Exe"},{"file": 4,"line": 386,"col": 4,"name": "Lib"},{"file": 4,"line": 387,"col": 4,"name": "Obj"},{"file": 4,"line": 108,"col": 4,"name": "Debug"},{"file": 4,"line": 109,"col": 4,"name": "ReleaseSafe"},{"file": 4,"line": 110,"col": 4,"name": "ReleaseFast"},{"file": 4,"line": 111,"col": 4,"name": "ReleaseSmall"},{"file": 10,"line": 14,"col": 8,"name": "tag"},{"file": 10,"line": 15,"col": 8,"name": "version_range"},{"file": 4,"line": 52,"col": 4,"name": "index"},{"file": 4,"line": 53,"col": 4,"name": "instruction_addresses"},{"file": 4,"line": 117,"col": 4,"name": "Unspecified"},{"file": 4,"line": 118,"col": 4,"name": "C"},{"file": 4,"line": 119,"col": 4,"name": "Cold"},{"file": 4,"line": 120,"col": 4,"name": "Naked"},{"file": 4,"line": 121,"col": 4,"name": "Async"},{"file": 4,"line": 122,"col": 4,"name": "Interrupt"},{"file": 4,"line": 123,"col": 4,"name": "Signal"},{"file": 4,"line": 124,"col": 4,"name": "Stdcall"},{"file": 4,"line": 125,"col": 4,"name": "Fastcall"},{"file": 4,"line": 126,"col": 4,"name": "Vectorcall"},{"file": 4,"line": 127,"col": 4,"name": "Thiscall"},{"file": 4,"line": 128,"col": 4,"name": "APCS"},{"file": 4,"line": 129,"col": 4,"name": "AAPCS"},{"file": 4,"line": 130,"col": 4,"name": "AAPCSVFP"},{"file": 4,"line": 459,"col": 4,"name": "modifier"},{"file": 4,"line": 462,"col": 4,"docs": " Only valid when `Modifier` is `Modifier.async_kw`.\n","name": "stack"},{"file": 4,"line": 400,"col": 4,"name": "major"},{"file": 4,"line": 401,"col": 4,"name": "minor"},{"file": 4,"line": 402,"col": 4,"name": "patch"},{"file": 4,"line": 59,"col": 4,"name": "Internal"},{"file": 4,"line": 60,"col": 4,"name": "Strong"},{"file": 4,"line": 61,"col": 4,"name": "Weak"},{"file": 4,"line": 62,"col": 4,"name": "LinkOnce"},{"file": 4,"line": 138,"col": 4,"name": "Type"},{"file": 4,"line": 139,"col": 4,"name": "Void"},{"file": 4,"line": 140,"col": 4,"name": "Bool"},{"file": 4,"line": 141,"col": 4,"name": "NoReturn"},{"file": 4,"line": 142,"col": 4,"name": "Int"},{"file": 4,"line": 143,"col": 4,"name": "Float"},{"file": 4,"line": 144,"col": 4,"name": "Pointer"},{"file": 4,"line": 145,"col": 4,"name": "Array"},{"file": 4,"line": 146,"col": 4,"name": "Struct"},{"file": 4,"line": 147,"col": 4,"name": "ComptimeFloat"},{"file": 4,"line": 148,"col": 4,"name": "ComptimeInt"},{"file": 4,"line": 149,"col": 4,"name": "Undefined"},{"file": 4,"line": 150,"col": 4,"name": "Null"},{"file": 4,"line": 151,"col": 4,"name": "Optional"},{"file": 4,"line": 152,"col": 4,"name": "ErrorUnion"},{"file": 4,"line": 153,"col": 4,"name": "ErrorSet"},{"file": 4,"line": 154,"col": 4,"name": "Enum"},{"file": 4,"line": 155,"col": 4,"name": "Union"},{"file": 4,"line": 156,"col": 4,"name": "Fn"},{"file": 4,"line": 157,"col": 4,"name": "BoundFn"},{"file": 4,"line": 158,"col": 4,"name": "Opaque"},{"file": 4,"line": 159,"col": 4,"name": "Frame"},{"file": 4,"line": 160,"col": 4,"name": "AnyFrame"},{"file": 4,"line": 161,"col": 4,"name": "Vector"},{"file": 4,"line": 162,"col": 4,"name": "EnumLiteral"},{"file": 4,"line": 393,"col": 4,"name": "Static"},{"file": 4,"line": 394,"col": 4,"name": "Dynamic"},{"file": 4,"line": 502,"col": 4,"name": "name"},{"file": 4,"line": 503,"col": 4,"name": "linkage"},{"file": 4,"line": 504,"col": 4,"name": "section"},{"file": 10,"line": 553,"col": 12,"name": "arm"},{"file": 10,"line": 554,"col": 12,"name": "armeb"},{"file": 10,"line": 555,"col": 12,"name": "aarch64"},{"file": 10,"line": 556,"col": 12,"name": "aarch64_be"},{"file": 10,"line": 557,"col": 12,"name": "aarch64_32"},{"file": 10,"line": 558,"col": 12,"name": "arc"},{"file": 10,"line": 559,"col": 12,"name": "avr"},{"file": 10,"line": 560,"col": 12,"name": "bpfel"},{"file": 10,"line": 561,"col": 12,"name": "bpfeb"},{"file": 10,"line": 562,"col": 12,"name": "hexagon"},{"file": 10,"line": 563,"col": 12,"name": "mips"},{"file": 10,"line": 564,"col": 12,"name": "mipsel"},{"file": 10,"line": 565,"col": 12,"name": "mips64"},{"file": 10,"line": 566,"col": 12,"name": "mips64el"},{"file": 10,"line": 567,"col": 12,"name": "msp430"},{"file": 10,"line": 568,"col": 12,"name": "powerpc"},{"file": 10,"line": 569,"col": 12,"name": "powerpc64"},{"file": 10,"line": 570,"col": 12,"name": "powerpc64le"},{"file": 10,"line": 571,"col": 12,"name": "r600"},{"file": 10,"line": 572,"col": 12,"name": "amdgcn"},{"file": 10,"line": 573,"col": 12,"name": "riscv32"},{"file": 10,"line": 574,"col": 12,"name": "riscv64"},{"file": 10,"line": 575,"col": 12,"name": "sparc"},{"file": 10,"line": 576,"col": 12,"name": "sparcv9"},{"file": 10,"line": 577,"col": 12,"name": "sparcel"},{"file": 10,"line": 578,"col": 12,"name": "s390x"},{"file": 10,"line": 579,"col": 12,"name": "tce"},{"file": 10,"line": 580,"col": 12,"name": "tcele"},{"file": 10,"line": 581,"col": 12,"name": "thumb"},{"file": 10,"line": 582,"col": 12,"name": "thumbeb"},{"file": 10,"line": 583,"col": 12,"name": "i386"},{"file": 10,"line": 584,"col": 12,"name": "x86_64"},{"file": 10,"line": 585,"col": 12,"name": "xcore"},{"file": 10,"line": 586,"col": 12,"name": "nvptx"},{"file": 10,"line": 587,"col": 12,"name": "nvptx64"},{"file": 10,"line": 588,"col": 12,"name": "le32"},{"file": 10,"line": 589,"col": 12,"name": "le64"},{"file": 10,"line": 590,"col": 12,"name": "amdil"},{"file": 10,"line": 591,"col": 12,"name": "amdil64"},{"file": 10,"line": 592,"col": 12,"name": "hsail"},{"file": 10,"line": 593,"col": 12,"name": "hsail64"},{"file": 10,"line": 594,"col": 12,"name": "spir"},{"file": 10,"line": 595,"col": 12,"name": "spir64"},{"file": 10,"line": 596,"col": 12,"name": "kalimba"},{"file": 10,"line": 597,"col": 12,"name": "shave"},{"file": 10,"line": 598,"col": 12,"name": "lanai"},{"file": 10,"line": 599,"col": 12,"name": "wasm32"},{"file": 10,"line": 600,"col": 12,"name": "wasm64"},{"file": 10,"line": 601,"col": 12,"name": "renderscript32"},{"file": 10,"line": 602,"col": 12,"name": "renderscript64"},{"file": 10,"line": 603,"col": 12,"name": "ve"},{"file": 10,"line": 9,"col": 4,"name": "cpu"},{"file": 10,"line": 10,"col": 4,"name": "os"},{"file": 10,"line": 11,"col": 4,"name": "abi"},{"file": 10,"line": 18,"col": 12,"name": "freestanding"},{"file": 10,"line": 19,"col": 12,"name": "ananas"},{"file": 10,"line": 20,"col": 12,"name": "cloudabi"},{"file": 10,"line": 21,"col": 12,"name": "dragonfly"},{"file": 10,"line": 22,"col": 12,"name": "freebsd"},{"file": 10,"line": 23,"col": 12,"name": "fuchsia"},{"file": 10,"line": 24,"col": 12,"name": "ios"},{"file": 10,"line": 25,"col": 12,"name": "kfreebsd"},{"file": 10,"line": 26,"col": 12,"name": "linux"},{"file": 10,"line": 27,"col": 12,"name": "lv2"},{"file": 10,"line": 28,"col": 12,"name": "macosx"},{"file": 10,"line": 29,"col": 12,"name": "netbsd"},{"file": 10,"line": 30,"col": 12,"name": "openbsd"},{"file": 10,"line": 31,"col": 12,"name": "solaris"},{"file": 10,"line": 32,"col": 12,"name": "windows"},{"file": 10,"line": 33,"col": 12,"name": "haiku"},{"file": 10,"line": 34,"col": 12,"name": "minix"},{"file": 10,"line": 35,"col": 12,"name": "rtems"},{"file": 10,"line": 36,"col": 12,"name": "nacl"},{"file": 10,"line": 37,"col": 12,"name": "cnk"},{"file": 10,"line": 38,"col": 12,"name": "aix"},{"file": 10,"line": 39,"col": 12,"name": "cuda"},{"file": 10,"line": 40,"col": 12,"name": "nvcl"},{"file": 10,"line": 41,"col": 12,"name": "amdhsa"},{"file": 10,"line": 42,"col": 12,"name": "ps4"},{"file": 10,"line": 43,"col": 12,"name": "elfiamcu"},{"file": 10,"line": 44,"col": 12,"name": "tvos"},{"file": 10,"line": 45,"col": 12,"name": "watchos"},{"file": 10,"line": 46,"col": 12,"name": "mesa3d"},{"file": 10,"line": 47,"col": 12,"name": "contiki"},{"file": 10,"line": 48,"col": 12,"name": "amdpal"},{"file": 10,"line": 49,"col": 12,"name": "hermit"},{"file": 10,"line": 50,"col": 12,"name": "hurd"},{"file": 10,"line": 51,"col": 12,"name": "wasi"},{"file": 10,"line": 52,"col": 12,"name": "emscripten"},{"file": 10,"line": 53,"col": 12,"name": "uefi"},{"file": 10,"line": 54,"col": 12,"name": "other"},{"file": 10,"line": 106,"col": 12,"name": "range"},{"file": 10,"line": 107,"col": 12,"name": "glibc"},{"file": 10,"line": 77,"col": 12,"name": "nt4"},{"file": 10,"line": 78,"col": 12,"name": "win2k"},{"file": 10,"line": 79,"col": 12,"name": "xp"},{"file": 10,"line": 80,"col": 12,"name": "ws2003"},{"file": 10,"line": 81,"col": 12,"name": "vista"},{"file": 10,"line": 82,"col": 12,"name": "win7"},{"file": 10,"line": 83,"col": 12,"name": "win8"},{"file": 10,"line": 84,"col": 12,"name": "win8_1"},{"file": 10,"line": 85,"col": 12,"name": "win10"},{"file": 10,"line": 86,"col": 12,"name": "win10_th2"},{"file": 10,"line": 87,"col": 12,"name": "win10_rs1"},{"file": 10,"line": 88,"col": 12,"name": "win10_rs2"},{"file": 10,"line": 89,"col": 12,"name": "win10_rs3"},{"file": 10,"line": 90,"col": 12,"name": "win10_rs4"},{"file": 10,"line": 91,"col": 12,"name": "win10_rs5"},{"file": 10,"line": 92,"col": 12,"name": "win10_19h1"},{"file": 10,"line": 93,"col": 12,"name": "_"},{"file": 10,"line": 136,"col": 12,"name": "none"},{"file": 10,"line": 137,"col": 12,"name": "semver"},{"file": 10,"line": 138,"col": 12,"name": "linux"},{"file": 10,"line": 139,"col": 12,"name": "windows"},{"file": 4,"line": 466,"col": 8,"docs": " Equivalent to function call syntax.\n","name": "auto"},{"file": 4,"line": 469,"col": 8,"docs": " Equivalent to async keyword used with function call syntax.\n","name": "async_kw"},{"file": 4,"line": 475,"col": 8,"docs": " Prevents tail call optimization. This guarantees that the return\n address will point to the callsite, as opposed to the callsite's\n callsite. If the call is otherwise required to be tail-called\n or inlined, a compile error is emitted instead.\n","name": "never_tail"},{"file": 4,"line": 479,"col": 8,"docs": " Guarantees that the call will not be inlined. If the call is\n otherwise required to be inlined, a compile error is emitted instead.\n","name": "never_inline"},{"file": 4,"line": 483,"col": 8,"docs": " Asserts that the function call will not suspend. This allows a\n non-async function to call an async function.\n","name": "no_async"},{"file": 4,"line": 487,"col": 8,"docs": " Guarantees that the call will be generated with tail call optimization.\n If this is not possible, a compile error is emitted instead.\n","name": "always_tail"},{"file": 4,"line": 491,"col": 8,"docs": " Guarantees that the call will inlined at the callsite.\n If this is not possible, a compile error is emitted instead.\n","name": "always_inline"},{"file": 4,"line": 495,"col": 8,"docs": " Evaluates the call at compile-time. If the call cannot be completed at\n compile-time, a compile error is emitted instead.\n","name": "compile_time"},{"file": 4,"line": 405,"col": 8,"name": "min"},{"file": 4,"line": 406,"col": 8,"name": "max"},{"file": 4,"line": 236,"col": 8,"name": "layout"},{"file": 4,"line": 237,"col": 8,"name": "fields"},{"file": 4,"line": 238,"col": 8,"name": "decls"},{"file": 4,"line": 206,"col": 8,"name": "len"},{"file": 4,"line": 207,"col": 8,"name": "child"},{"file": 4,"line": 213,"col": 8,"docs": " This field is an optional type.\n The type of the sentinel is the element type of the array, which is\n the value of the `child` field in this struct. However there is no way\n to refer to that type here, so we use `var`.\n","name": "sentinel"},{"file": 4,"line": 250,"col": 8,"name": "error_set"},{"file": 4,"line": 251,"col": 8,"name": "payload"},{"file": 4,"line": 180,"col": 8,"name": "size"},{"file": 4,"line": 181,"col": 8,"name": "is_const"},{"file": 4,"line": 182,"col": 8,"name": "is_volatile"},{"file": 4,"line": 183,"col": 8,"name": "alignment"},{"file": 4,"line": 184,"col": 8,"name": "child"},{"file": 4,"line": 185,"col": 8,"name": "is_allowzero"},{"file": 4,"line": 191,"col": 8,"docs": " This field is an optional type.\n The type of the sentinel is the element type of the pointer, which is\n the value of the `child` field in this struct. However there is no way\n to refer to that type here, so we use `var`.\n","name": "sentinel"},{"file": 4,"line": 268,"col": 8,"name": "name"},{"file": 4,"line": 269,"col": 8,"name": "value"},{"file": 4,"line": 219,"col": 8,"name": "Auto"},{"file": 4,"line": 220,"col": 8,"name": "Extern"},{"file": 4,"line": 221,"col": 8,"name": "Packed"},{"file": 4,"line": 333,"col": 8,"name": "name"},{"file": 4,"line": 334,"col": 8,"name": "is_pub"},{"file": 4,"line": 335,"col": 8,"name": "data"},{"file": 4,"line": 293,"col": 8,"name": "layout"},{"file": 4,"line": 294,"col": 8,"name": "tag_type"},{"file": 4,"line": 295,"col": 8,"name": "fields"},{"file": 4,"line": 296,"col": 8,"name": "decls"},{"file": 4,"line": 244,"col": 8,"name": "child"},{"file": 4,"line": 275,"col": 8,"name": "layout"},{"file": 4,"line": 276,"col": 8,"name": "tag_type"},{"file": 4,"line": 277,"col": 8,"name": "fields"},{"file": 4,"line": 278,"col": 8,"name": "decls"},{"file": 4,"line": 279,"col": 8,"name": "is_exhaustive"},{"file": 4,"line": 326,"col": 8,"name": "len"},{"file": 4,"line": 327,"col": 8,"name": "child"},{"file": 4,"line": 174,"col": 8,"name": "bits"},{"file": 4,"line": 285,"col": 8,"name": "name"},{"file": 4,"line": 286,"col": 8,"name": "enum_field"},{"file": 4,"line": 287,"col": 8,"name": "field_type"},{"file": 4,"line": 227,"col": 8,"name": "name"},{"file": 4,"line": 228,"col": 8,"name": "offset"},{"file": 4,"line": 229,"col": 8,"name": "field_type"},{"file": 4,"line": 230,"col": 8,"name": "default_value"},{"file": 4,"line": 320,"col": 8,"name": "child"},{"file": 4,"line": 257,"col": 8,"name": "name"},{"file": 4,"line": 258,"col": 8,"name": "value"},{"file": 4,"line": 310,"col": 8,"name": "calling_convention"},{"file": 4,"line": 311,"col": 8,"name": "is_generic"},{"file": 4,"line": 312,"col": 8,"name": "is_var_args"},{"file": 4,"line": 313,"col": 8,"name": "return_type"},{"file": 4,"line": 314,"col": 8,"name": "args"},{"file": 4,"line": 302,"col": 8,"name": "is_generic"},{"file": 4,"line": 303,"col": 8,"name": "is_noalias"},{"file": 4,"line": 304,"col": 8,"name": "arg_type"},{"file": 4,"line": 167,"col": 8,"name": "is_signed"},{"file": 4,"line": 168,"col": 8,"name": "bits"},{"file": 10,"line": 427,"col": 8,"docs": " Architecture\n","name": "arch"},{"file": 10,"line": 431,"col": 8,"docs": " The CPU model to target. It has a set of features\n which are overridden with the `features` field.\n","name": "model"},{"file": 10,"line": 434,"col": 8,"docs": " An explicit list of the entire CPU feature set. It may differ from the specific CPU model's features.\n","name": "features"},{"file": 10,"line": 313,"col": 8,"name": "none"},{"file": 10,"line": 314,"col": 8,"name": "gnu"},{"file": 10,"line": 315,"col": 8,"name": "gnuabin32"},{"file": 10,"line": 316,"col": 8,"name": "gnuabi64"},{"file": 10,"line": 317,"col": 8,"name": "gnueabi"},{"file": 10,"line": 318,"col": 8,"name": "gnueabihf"},{"file": 10,"line": 319,"col": 8,"name": "gnux32"},{"file": 10,"line": 320,"col": 8,"name": "code16"},{"file": 10,"line": 321,"col": 8,"name": "eabi"},{"file": 10,"line": 322,"col": 8,"name": "eabihf"},{"file": 10,"line": 323,"col": 8,"name": "android"},{"file": 10,"line": 324,"col": 8,"name": "musl"},{"file": 10,"line": 325,"col": 8,"name": "musleabi"},{"file": 10,"line": 326,"col": 8,"name": "musleabihf"},{"file": 10,"line": 327,"col": 8,"name": "msvc"},{"file": 10,"line": 328,"col": 8,"name": "itanium"},{"file": 10,"line": 329,"col": 8,"name": "cygnus"},{"file": 10,"line": 330,"col": 8,"name": "coreclr"},{"file": 10,"line": 331,"col": 8,"name": "simulator"},{"file": 10,"line": 332,"col": 8,"name": "macabi"},{"file": 10,"line": 96,"col": 16,"name": "min"},{"file": 10,"line": 97,"col": 16,"name": "max"},{"file": 4,"line": 196,"col": 12,"name": "One"},{"file": 4,"line": 197,"col": 12,"name": "Many"},{"file": 4,"line": 198,"col": 12,"name": "Slice"},{"file": 4,"line": 199,"col": 12,"name": "C"},{"file": 4,"line": 340,"col": 12,"name": "Type"},{"file": 4,"line": 341,"col": 12,"name": "Var"},{"file": 4,"line": 342,"col": 12,"name": "Fn"},{"file": 10,"line": 895,"col": 12,"name": "name"},{"file": 10,"line": 896,"col": 12,"name": "llvm_name"},{"file": 10,"line": 897,"col": 12,"name": "features"},{"file": 10,"line": 439,"col": 12,"docs": " The bit index into `Set`. Has a default value of `undefined` because the canonical\n structures are populated via comptime logic.\n","name": "index"},{"file": 10,"line": 443,"col": 12,"docs": " Has a default value of `undefined` because the canonical\n structures are populated via comptime logic.\n","name": "name"},{"file": 10,"line": 447,"col": 12,"docs": " If this corresponds to an LLVM-recognized feature, this will be populated;\n otherwise null.\n","name": "llvm_name"},{"file": 10,"line": 450,"col": 12,"docs": " Human-friendly UTF-8 text.\n","name": "description"},{"file": 10,"line": 453,"col": 12,"docs": " Sparse `Set` of features this depends on.\n","name": "dependencies"},{"file": 10,"line": 457,"col": 16,"name": "ints"},{"file": 4,"line": 347,"col": 16,"name": "fn_type"},{"file": 4,"line": 348,"col": 16,"name": "inline_type"},{"file": 4,"line": 349,"col": 16,"name": "is_var_args"},{"file": 4,"line": 350,"col": 16,"name": "is_extern"},{"file": 4,"line": 351,"col": 16,"name": "is_export"},{"file": 4,"line": 352,"col": 16,"name": "lib_name"},{"file": 4,"line": 353,"col": 16,"name": "return_type"},{"file": 4,"line": 354,"col": 16,"name": "arg_names"},{"file": 4,"line": 359,"col": 20,"name": "Auto"},{"file": 4,"line": 360,"col": 20,"name": "Always"},{"file": 4,"line": 361,"col": 20,"name": "Never"},{"file": 3,"line": 454,"col": 25,"name": "self"},{"file": 3,"line": 445,"col": 22,"name": "self"},{"file": 3,"line": 445,"col": 35,"name": "index"},{"file": 3,"line": 462,"col": 21,"name": "self"},{"file": 3,"line": 203,"col": 26,"name": "self"},{"file": 3,"line": 203,"col": 43,"name": "target"},{"file": 3,"line": 689,"col": 24,"name": "allocator"},{"file": 3,"line": 689,"col": 47,"name": "alignment","comptime": true},{"file": 3,"line": 746,"col": 30,"name": "allocator"},{"file": 3,"line": 661,"col": 17,"name": "allocator"},{"file": 3,"line": 713,"col": 31,"name": "allocator"},{"file": 3,"line": 476,"col": 39},{"file": 3,"line": 476,"col": 44},{"file": 3,"line": 138,"col": 31,"name": "addr"},{"file": 5,"line": 87,"col": 19,"name": "self"},{"file": 5,"line": 87,"col": 37,"name": "ptr"},{"file": 5,"line": 187,"col": 19,"name": "self"},{"file": 5,"line": 187,"col": 37,"name": "old_mem"},{"file": 5,"line": 187,"col": 51,"name": "new_n"},{"file": 5,"line": 142,"col": 25,"name": "self"},{"file": 5,"line": 142,"col": 43,"name": "Elem","comptime": true},{"file": 5,"line": 142,"col": 64,"name": "n"},{"file": 5,"line": 142,"col": 74,"name": "sentinel","comptime": true},{"file": 5,"line": 230,"col": 18,"name": "self"},{"file": 5,"line": 230,"col": 36,"name": "old_mem"},{"file": 5,"line": 230,"col": 50,"name": "new_n"},{"file": 5,"line": 242,"col": 8,"name": "self"},{"file": 5,"line": 243,"col": 8,"name": "old_mem"},{"file": 5,"line": 244,"col": 8,"name": "new_alignment","comptime": true},{"file": 5,"line": 245,"col": 8,"name": "new_n"},{"file": 5,"line": 147,"col": 8,"name": "self"},{"file": 5,"line": 148,"col": 8,"name": "T","comptime": true},{"file": 5,"line": 150,"col": 8,"docs": " null means naturally aligned\n","name": "alignment","comptime": true},{"file": 5,"line": 151,"col": 8,"name": "n"},{"file": 5,"line": 103,"col": 17,"name": "self"},{"file": 5,"line": 103,"col": 35,"name": "T","comptime": true},{"file": 5,"line": 103,"col": 53,"name": "n"},{"file": 5,"line": 199,"col": 8,"name": "self"},{"file": 5,"line": 200,"col": 8,"name": "old_mem"},{"file": 5,"line": 201,"col": 8,"name": "new_alignment","comptime": true},{"file": 5,"line": 202,"col": 8,"name": "new_n"},{"file": 5,"line": 283,"col": 16,"name": "allocator"},{"file": 5,"line": 283,"col": 39,"name": "T","comptime": true},{"file": 5,"line": 283,"col": 57,"name": "m"},{"file": 5,"line": 290,"col": 17,"name": "allocator"},{"file": 5,"line": 290,"col": 40,"name": "T","comptime": true},{"file": 5,"line": 290,"col": 58,"name": "m"},{"file": 5,"line": 271,"col": 16,"name": "self"},{"file": 5,"line": 271,"col": 34,"name": "memory"},{"file": 5,"line": 108,"col": 8,"name": "self"},{"file": 5,"line": 109,"col": 8,"name": "Elem","comptime": true},{"file": 5,"line": 110,"col": 8,"name": "n"},{"file": 5,"line": 112,"col": 8,"docs": " null means naturally aligned\n","name": "optional_alignment","comptime": true},{"file": 5,"line": 113,"col": 8,"name": "optional_sentinel","comptime": true},{"file": 5,"line": 79,"col": 18,"name": "self"},{"file": 5,"line": 79,"col": 36,"name": "T","comptime": true},{"file": 5,"line": 124,"col": 31,"name": "Elem","comptime": true},{"file": 5,"line": 124,"col": 52,"name": "alignment","comptime": true},{"file": 5,"line": 124,"col": 78,"name": "sentinel","comptime": true},{"file": 10,"line": 250,"col": 28,"name": "os"},{"file": 10,"line": 243,"col": 35,"name": "tag"},{"file": 4,"line": 435,"col": 8,"name": "self"},{"file": 4,"line": 436,"col": 8,"name": "fmt","comptime": true},{"file": 4,"line": 437,"col": 8,"name": "options"},{"file": 4,"line": 438,"col": 8,"name": "out_stream"},{"file": 4,"line": 425,"col": 17,"name": "text"},{"file": 4,"line": 415,"col": 17,"name": "lhs"},{"file": 4,"line": 415,"col": 31,"name": "rhs"},{"file": 10,"line": 826,"col": 31,"name": "arch"},{"file": 10,"line": 605,"col": 25,"name": "arch"},{"file": 10,"line": 848,"col": 35,"name": "arch"},{"file": 10,"line": 764,"col": 31,"name": "arch"},{"file": 10,"line": 705,"col": 26,"name": "arch"},{"file": 10,"line": 612,"col": 27,"name": "arch"},{"file": 10,"line": 640,"col": 33,"name": "arch"},{"file": 10,"line": 640,"col": 45,"name": "cpu_name"},{"file": 10,"line": 871,"col": 32,"name": "arch"},{"file": 10,"line": 649,"col": 32,"name": "arch"},{"file": 10,"line": 626,"col": 27,"name": "arch"},{"file": 10,"line": 619,"col": 26,"name": "arch"},{"file": 10,"line": 633,"col": 26,"name": "arch"},{"file": 5,"line": 749,"col": 13,"name": "ptr"},{"file": 5,"line": 343,"col": 11,"name": "T","comptime": true},{"file": 5,"line": 343,"col": 29,"name": "dest"},{"file": 5,"line": 343,"col": 40,"name": "value"},{"file": 5,"line": 1219,"col": 24,"name": "T","comptime": true},{"file": 5,"line": 1219,"col": 42,"name": "buffer"},{"file": 5,"line": 1219,"col": 56,"name": "value"},{"file": 5,"line": 1760,"col": 15,"name": "T","comptime": true},{"file": 5,"line": 1760,"col": 33,"name": "items"},{"file": 5,"line": 1076,"col": 26,"name": "T","comptime": true},{"file": 5,"line": 1076,"col": 44,"name": "bytes"},{"file": 5,"line": 1897,"col": 15,"name": "value"},{"file": 5,"line": 1777,"col": 14,"name": "T","comptime": true},{"file": 5,"line": 1777,"col": 32,"name": "items"},{"file": 5,"line": 1777,"col": 44,"name": "amount"},{"file": 5,"line": 778,"col": 11,"name": "value"},{"file": 5,"line": 2082,"col": 20,"name": "slice"},{"file": 5,"line": 1975,"col": 20,"name": "T","comptime": true},{"file": 5,"line": 1975,"col": 38,"name": "bytes"},{"file": 5,"line": 1168,"col": 23,"name": "T","comptime": true},{"file": 5,"line": 1168,"col": 41,"name": "buf"},{"file": 5,"line": 1168,"col": 78,"name": "value"},{"file": 5,"line": 895,"col": 13,"name": "allocator"},{"file": 5,"line": 895,"col": 36,"name": "T","comptime": true},{"file": 5,"line": 895,"col": 54,"name": "m"},{"file": 5,"line": 1741,"col": 11,"name": "T","comptime": true},{"file": 5,"line": 1741,"col": 29,"name": "slice"},{"file": 5,"line": 1408,"col": 18,"name": "T","comptime": true},{"file": 5,"line": 1408,"col": 36,"name": "haystack"},{"file": 5,"line": 1408,"col": 57,"name": "needle"},{"file": 5,"line": 2003,"col": 20,"name": "T","comptime": true},{"file": 5,"line": 2003,"col": 38,"name": "bytes"},{"file": 5,"line": 944,"col": 24,"name": "T","comptime": true},{"file": 5,"line": 944,"col": 42,"name": "slice"},{"file": 5,"line": 944,"col": 60,"name": "start_index"},{"file": 5,"line": 944,"col": 80,"name": "value"},{"file": 5,"line": 977,"col": 15,"name": "T","comptime": true},{"file": 5,"line": 977,"col": 33,"name": "haystack"},{"file": 5,"line": 977,"col": 54,"name": "needle"},{"file": 5,"line": 1185,"col": 16,"name": "T","comptime": true},{"file": 5,"line": 1185,"col": 34,"name": "buffer"},{"file": 5,"line": 1185,"col": 74,"name": "value"},{"file": 5,"line": 1185,"col": 84,"name": "endian"},{"file": 5,"line": 2173,"col": 27,"name": "T","comptime": true},{"file": 5,"line": 2173,"col": 45,"name": "addr"},{"file": 5,"line": 2173,"col": 54,"name": "alignment"},{"file": 5,"line": 1753,"col": 12,"name": "T","comptime": true},{"file": 5,"line": 1753,"col": 30,"name": "a"},{"file": 5,"line": 1753,"col": 37,"name": "b"},{"file": 5,"line": 935,"col": 25,"name": "T","comptime": true},{"file": 5,"line": 935,"col": 43,"name": "slice"},{"file": 5,"line": 935,"col": 61,"name": "value"},{"file": 5,"line": 1199,"col": 27,"name": "T","comptime": true},{"file": 5,"line": 1199,"col": 45,"name": "buffer"},{"file": 5,"line": 1199,"col": 59,"name": "value"},{"file": 5,"line": 1729,"col": 11,"name": "T","comptime": true},{"file": 5,"line": 1729,"col": 29,"name": "slice"},{"file": 5,"line": 1049,"col": 21,"name": "T","comptime": true},{"file": 5,"line": 1049,"col": 39,"name": "bytes"},{"file": 5,"line": 967,"col": 21,"name": "T","comptime": true},{"file": 5,"line": 967,"col": 39,"name": "slice"},{"file": 5,"line": 967,"col": 57,"name": "start_index"},{"file": 5,"line": 967,"col": 77,"name": "values"},{"file": 5,"line": 826,"col": 12,"name": "ptr"},{"file": 5,"line": 900,"col": 16,"name": "T","comptime": true},{"file": 5,"line": 900,"col": 34,"name": "slice"},{"file": 5,"line": 900,"col": 52,"name": "values_to_strip"},{"file": 5,"line": 2200,"col": 28,"name": "T","comptime": true},{"file": 5,"line": 2200,"col": 46,"name": "addr"},{"file": 5,"line": 2200,"col": 55,"name": "alignment"},{"file": 5,"line": 1857,"col": 15,"name": "ptr"},{"file": 5,"line": 1026,"col": 18,"name": "ReturnType","comptime": true},{"file": 5,"line": 1026,"col": 45,"name": "bytes"},{"file": 5,"line": 1026,"col": 64,"name": "endian"},{"file": 5,"line": 2210,"col": 17,"name": "addr"},{"file": 5,"line": 2210,"col": 30,"name": "alignment"},{"file": 5,"line": 1252,"col": 21,"name": "T","comptime": true},{"file": 5,"line": 1252,"col": 39,"name": "buffer"},{"file": 5,"line": 1252,"col": 53,"name": "value"},{"file": 5,"line": 1252,"col": 63,"name": "endian"},{"file": 5,"line": 890,"col": 12,"name": "allocator"},{"file": 5,"line": 890,"col": 35,"name": "T","comptime": true},{"file": 5,"line": 890,"col": 53,"name": "m"},{"file": 5,"line": 1493,"col": 12,"name": "allocator"},{"file": 5,"line": 1493,"col": 35,"name": "separator"},{"file": 5,"line": 1493,"col": 58,"name": "slices"},{"file": 5,"line": 1538,"col": 14,"name": "allocator"},{"file": 5,"line": 1538,"col": 37,"name": "T","comptime": true},{"file": 5,"line": 1538,"col": 55,"name": "slices"},{"file": 5,"line": 1932,"col": 20,"name": "T","comptime": true},{"file": 5,"line": 1932,"col": 38,"name": "bytes"},{"file": 5,"line": 1807,"col": 16,"name": "T","comptime": true},{"file": 5,"line": 1807,"col": 34,"name": "x"},{"file": 5,"line": 1807,"col": 40,"name": "endianness_of_x"},{"file": 5,"line": 995,"col": 18,"name": "T","comptime": true},{"file": 5,"line": 995,"col": 36,"name": "haystack"},{"file": 5,"line": 995,"col": 57,"name": "start_index"},{"file": 5,"line": 995,"col": 77,"name": "needle"},{"file": 5,"line": 1823,"col": 22,"name": "T","comptime": true},{"file": 5,"line": 1823,"col": 40,"name": "x"},{"file": 5,"line": 2194,"col": 21,"name": "addr"},{"file": 5,"line": 2194,"col": 34,"name": "alignment"},{"file": 5,"line": 1114,"col": 20,"name": "T","comptime": true},{"file": 5,"line": 1114,"col": 38,"name": "bytes"},{"file": 5,"line": 1114,"col": 57,"name": "endian"},{"file": 5,"line": 1815,"col": 16,"name": "T","comptime": true},{"file": 5,"line": 1815,"col": 34,"name": "x"},{"file": 5,"line": 1815,"col": 40,"name": "desired_endianness"},{"file": 5,"line": 873,"col": 23,"name": "Elem","comptime": true},{"file": 5,"line": 873,"col": 44,"name": "sentinel","comptime": true},{"file": 5,"line": 873,"col": 69,"name": "ptr"},{"file": 5,"line": 354,"col": 14,"name": "T","comptime": true},{"file": 5,"line": 956,"col": 22,"name": "T","comptime": true},{"file": 5,"line": 956,"col": 40,"name": "slice"},{"file": 5,"line": 956,"col": 58,"name": "values"},{"file": 5,"line": 592,"col": 13,"name": "T","comptime": true},{"file": 5,"line": 592,"col": 31,"name": "lhs"},{"file": 5,"line": 592,"col": 47,"name": "rhs"},{"file": 5,"line": 1791,"col": 22,"name": "T","comptime": true},{"file": 5,"line": 1791,"col": 40,"name": "x"},{"file": 5,"line": 1799,"col": 19,"name": "T","comptime": true},{"file": 5,"line": 1799,"col": 37,"name": "x"},{"file": 5,"line": 2167,"col": 20,"name": "addr"},{"file": 5,"line": 2167,"col": 33,"name": "alignment"},{"file": 5,"line": 930,"col": 21,"name": "T","comptime": true},{"file": 5,"line": 930,"col": 39,"name": "slice"},{"file": 5,"line": 930,"col": 57,"name": "value"},{"file": 5,"line": 1831,"col": 19,"name": "T","comptime": true},{"file": 5,"line": 1831,"col": 37,"name": "x"},{"file": 5,"line": 1160,"col": 22,"name": "T","comptime": true},{"file": 5,"line": 1160,"col": 40,"name": "buf"},{"file": 5,"line": 1160,"col": 73,"name": "value"},{"file": 5,"line": 952,"col": 18,"name": "T","comptime": true},{"file": 5,"line": 952,"col": 36,"name": "slice"},{"file": 5,"line": 952,"col": 54,"name": "values"},{"file": 5,"line": 721,"col": 12,"name": "ptr"},{"file": 5,"line": 614,"col": 16,"name": "T","comptime": true},{"file": 5,"line": 614,"col": 34,"name": "lhs"},{"file": 5,"line": 614,"col": 50,"name": "rhs"},{"file": 5,"line": 1417,"col": 16,"name": "T","comptime": true},{"file": 5,"line": 1417,"col": 34,"name": "haystack"},{"file": 5,"line": 1417,"col": 55,"name": "needle"},{"file": 5,"line": 914,"col": 12,"name": "T","comptime": true},{"file": 5,"line": 914,"col": 30,"name": "slice"},{"file": 5,"line": 914,"col": 48,"name": "values_to_strip"},{"file": 5,"line": 1305,"col": 16,"name": "buffer"},{"file": 5,"line": 1305,"col": 36,"name": "delimiter_bytes"},{"file": 5,"line": 638,"col": 19,"name": "T","comptime": true},{"file": 5,"line": 638,"col": 37,"name": "a"},{"file": 5,"line": 638,"col": 51,"name": "b"},{"file": 5,"line": 1057,"col": 22,"name": "T","comptime": true},{"file": 5,"line": 1057,"col": 40,"name": "bytes"},{"file": 5,"line": 2214,"col": 24,"name": "T","comptime": true},{"file": 5,"line": 2214,"col": 42,"name": "addr"},{"file": 5,"line": 2214,"col": 51,"name": "alignment"},{"file": 5,"line": 907,"col": 17,"name": "T","comptime": true},{"file": 5,"line": 907,"col": 35,"name": "slice"},{"file": 5,"line": 907,"col": 53,"name": "values_to_strip"},{"file": 5,"line": 500,"col": 18,"name": "T","comptime": true},{"file": 5,"line": 500,"col": 36,"name": "s"},{"file": 5,"line": 521,"col": 16,"name": "T","comptime": true},{"file": 5,"line": 521,"col": 34,"name": "init"},{"file": 5,"line": 663,"col": 12,"name": "T","comptime": true},{"file": 5,"line": 1365,"col": 13,"name": "buffer"},{"file": 5,"line": 1365,"col": 33,"name": "delimiter"},{"file": 5,"line": 984,"col": 19,"name": "T","comptime": true},{"file": 5,"line": 984,"col": 37,"name": "haystack"},{"file": 5,"line": 984,"col": 58,"name": "needle"},{"file": 5,"line": 1086,"col": 27,"name": "T","comptime": true},{"file": 5,"line": 1086,"col": 45,"name": "bytes"},{"file": 5,"line": 330,"col": 21,"name": "T","comptime": true},{"file": 5,"line": 330,"col": 39,"name": "dest"},{"file": 5,"line": 330,"col": 50,"name": "source"},{"file": 5,"line": 882,"col": 16,"name": "T","comptime": true},{"file": 5,"line": 882,"col": 34,"name": "slice"},{"file": 5,"line": 882,"col": 52,"name": "scalar"},{"file": 5,"line": 627,"col": 11,"name": "T","comptime": true},{"file": 5,"line": 627,"col": 29,"name": "a"},{"file": 5,"line": 627,"col": 43,"name": "b"},{"file": 5,"line": 1103,"col": 15,"name": "T","comptime": true},{"file": 5,"line": 1103,"col": 33,"name": "bytes"},{"file": 5,"line": 1103,"col": 78,"name": "endian"},{"file": 5,"line": 302,"col": 24,"name": "self"},{"file": 5,"line": 302,"col": 42,"name": "old_mem"},{"file": 5,"line": 302,"col": 57,"name": "old_align"},{"file": 5,"line": 302,"col": 73,"name": "new_size"},{"file": 5,"line": 302,"col": 90,"name": "new_align"},{"file": 5,"line": 1989,"col": 26,"name": "T","comptime": true},{"file": 5,"line": 1989,"col": 44,"name": "bytesType","comptime": true},{"file": 5,"line": 1915,"col": 26,"name": "T","comptime": true},{"file": 5,"line": 1915,"col": 44,"name": "B","comptime": true},{"file": 5,"line": 1838,"col": 21,"name": "P","comptime": true},{"file": 5,"line": 2072,"col": 26,"name": "sliceType","comptime": true},{"file": 5,"line": 305,"col": 23,"name": "self"},{"file": 5,"line": 305,"col": 41,"name": "old_mem"},{"file": 5,"line": 305,"col": 56,"name": "old_align"},{"file": 5,"line": 305,"col": 72,"name": "new_size"},{"file": 5,"line": 305,"col": 89,"name": "new_align"},{"file": 6,"line": 416,"col": 12,"name": "T","comptime": true},{"file": 6,"line": 416,"col": 30,"name": "x"},{"file": 6,"line": 416,"col": 36,"name": "r"},{"file": 6,"line": 686,"col": 15,"name": "x"},{"file": 6,"line": 592,"col": 16,"name": "T","comptime": true},{"file": 6,"line": 592,"col": 34,"name": "numerator"},{"file": 6,"line": 592,"col": 48,"name": "denominator"},{"file": 6,"line": 822,"col": 22,"name": "T","comptime": true},{"file": 6,"line": 822,"col": 40,"name": "value"},{"file": 6,"line": 967,"col": 15,"name": "T","comptime": true},{"file": 6,"line": 967,"col": 33,"name": "a"},{"file": 6,"line": 967,"col": 39,"name": "b"},{"file": 6,"line": 388,"col": 11,"name": "T","comptime": true},{"file": 6,"line": 388,"col": 29,"name": "a"},{"file": 6,"line": 388,"col": 35,"name": "shift_amt"},{"file": 6,"line": 744,"col": 12,"name": "T","comptime": true},{"file": 6,"line": 744,"col": 30,"name": "x"},{"file": 6,"line": 341,"col": 11,"name": "T","comptime": true},{"file": 6,"line": 341,"col": 29,"name": "a"},{"file": 6,"line": 341,"col": 35,"name": "b"},{"file": 6,"line": 894,"col": 17,"name": "T","comptime": true},{"file": 6,"line": 894,"col": 35,"name": "value"},{"file": 6,"line": 638,"col": 11,"name": "T","comptime": true},{"file": 6,"line": 638,"col": 29,"name": "numerator"},{"file": 6,"line": 638,"col": 43,"name": "denominator"},{"file": 6,"line": 1028,"col": 13,"name": "a"},{"file": 6,"line": 1028,"col": 21,"name": "b"},{"file": 6,"line": 315,"col": 13,"name": "val"},{"file": 6,"line": 315,"col": 23,"name": "lower"},{"file": 6,"line": 315,"col": 35,"name": "upper"},{"file": 6,"line": 873,"col": 21,"name": "T","comptime": true},{"file": 6,"line": 873,"col": 39,"name": "x"},{"file": 6,"line": 810,"col": 29,"name": "T","comptime": true},{"file": 6,"line": 810,"col": 47,"name": "value"},{"file": 6,"line": 355,"col": 16,"name": "T","comptime": true},{"file": 6,"line": 355,"col": 34,"name": "a"},{"file": 6,"line": 355,"col": 40,"name": "shift_amt"},{"file": 6,"line": 661,"col": 11,"name": "T","comptime": true},{"file": 6,"line": 661,"col": 29,"name": "numerator"},{"file": 6,"line": 661,"col": 43,"name": "denominator"},{"file": 6,"line": 346,"col": 11,"name": "T","comptime": true},{"file": 6,"line": 346,"col": 29,"name": "a"},{"file": 6,"line": 346,"col": 35,"name": "b"},{"file": 6,"line": 209,"col": 25,"name": "T","comptime": true},{"file": 6,"line": 782,"col": 23,"name": "T","comptime": true},{"file": 6,"line": 782,"col": 41,"name": "value"},{"file": 6,"line": 463,"col": 23,"name": "from","comptime": true},{"file": 6,"line": 463,"col": 52,"name": "to","comptime": true},{"file": 6,"line": 435,"col": 12,"name": "T","comptime": true},{"file": 6,"line": 435,"col": 30,"name": "x"},{"file": 6,"line": 435,"col": 36,"name": "r"},{"file": 6,"line": 917,"col": 14,"name": "T","comptime": true},{"file": 6,"line": 351,"col": 14,"name": "x"},{"file": 6,"line": 769,"col": 17,"name": "alignment","comptime": true},{"file": 6,"line": 769,"col": 42,"name": "ptr"},{"file": 6,"line": 336,"col": 11,"name": "T","comptime": true},{"file": 6,"line": 336,"col": 29,"name": "a"},{"file": 6,"line": 336,"col": 35,"name": "b"},{"file": 6,"line": 613,"col": 16,"name": "T","comptime": true},{"file": 6,"line": 613,"col": 34,"name": "numerator"},{"file": 6,"line": 613,"col": 48,"name": "denominator"},{"file": 6,"line": 721,"col": 18,"name": "x"},{"file": 6,"line": 106,"col": 17,"name": "value"},{"file": 6,"line": 1064,"col": 15,"name": "a"},{"file": 6,"line": 1064,"col": 23,"name": "op"},{"file": 6,"line": 1064,"col": 44,"name": "b"},{"file": 6,"line": 362,"col": 11,"name": "T","comptime": true},{"file": 6,"line": 362,"col": 29,"name": "a"},{"file": 6,"line": 362,"col": 35,"name": "shift_amt"},{"file": 6,"line": 100,"col": 16,"name": "T","comptime": true},{"file": 6,"line": 100,"col": 34,"name": "x"},{"file": 6,"line": 100,"col": 40,"name": "y"},{"file": 6,"line": 100,"col": 46,"name": "epsilon"},{"file": 6,"line": 222,"col": 25,"name": "T","comptime": true},{"file": 6,"line": 538,"col": 14,"name": "x"},{"file": 6,"line": 571,"col": 16,"name": "T","comptime": true},{"file": 6,"line": 571,"col": 34,"name": "numerator"},{"file": 6,"line": 571,"col": 48,"name": "denominator"},{"file": 7,"line": 160,"col": 25,"name": "first_address"},{"file": 7,"line": 160,"col": 48,"name": "stack_trace"},{"file": 7,"line": 412,"col": 4,"name": "out_stream"},{"file": 7,"line": 413,"col": 4,"name": "debug_info"},{"file": 7,"line": 414,"col": 4,"name": "tty_config"},{"file": 7,"line": 415,"col": 4,"name": "start_addr"},{"file": 7,"line": 113,"col": 29,"name": "start_addr"},{"file": 7,"line": 397,"col": 4,"name": "out_stream"},{"file": 7,"line": 398,"col": 4,"name": "debug_info"},{"file": 7,"line": 399,"col": 4,"name": "tty_config"},{"file": 7,"line": 400,"col": 4,"name": "start_addr"},{"file": 7,"line": 204,"col": 22,"name": "stack_trace"},{"file": 7,"line": 318,"col": 4,"name": "stack_trace"},{"file": 7,"line": 319,"col": 4,"name": "out_stream"},{"file": 7,"line": 320,"col": 4,"name": "allocator"},{"file": 7,"line": 321,"col": 4,"name": "debug_info"},{"file": 7,"line": 322,"col": 4,"name": "tty_config"},{"file": 7,"line": 236,"col": 13,"name": "format","comptime": true},{"file": 7,"line": 236,"col": 42,"name": "args"},{"file": 7,"line": 567,"col": 28,"name": "debug_info"},{"file": 7,"line": 567,"col": 52,"name": "out_stream"},{"file": 7,"line": 567,"col": 69,"name": "address"},{"file": 7,"line": 567,"col": 85,"name": "tty_config"},{"file": 7,"line": 859,"col": 24,"name": "allocator"},{"file": 7,"line": 859,"col": 51,"name": "elf_file"},{"file": 7,"line": 254,"col": 18,"name": "trace"},{"file": 7,"line": 254,"col": 53,"name": "first_trace_addr"},{"file": 7,"line": 254,"col": 79,"name": "format","comptime": true},{"file": 7,"line": 254,"col": 108,"name": "args"},{"file": 7,"line": 134,"col": 30,"name": "bp"},{"file": 7,"line": 134,"col": 41,"name": "ip"},{"file": 7,"line": 1838,"col": 28,"name": "prefix"},{"file": 7,"line": 652,"col": 25,"name": "allocator"},{"file": 7,"line": 60,"col": 12,"name": "fmt","comptime": true},{"file": 7,"line": 60,"col": 38,"name": "args"},{"file": 7,"line": 1804,"col": 25,"name": "info"},{"file": 7,"line": 931,"col": 22,"name": "allocator"},{"file": 7,"line": 931,"col": 49,"name": "macho_file"},{"file": 7,"line": 832,"col": 23,"name": "stream"},{"file": 7,"line": 832,"col": 36,"name": "allocator"},{"file": 7,"line": 1068,"col": 16,"name": "file"},{"file": 7,"line": 1016,"col": 26,"name": "out_stream"},{"file": 7,"line": 1016,"col": 43,"name": "line_info"},{"file": 7,"line": 598,"col": 4,"name": "out_stream"},{"file": 7,"line": 599,"col": 4,"name": "line_info"},{"file": 7,"line": 600,"col": 4,"name": "address"},{"file": 7,"line": 601,"col": 4,"name": "symbol_name"},{"file": 7,"line": 602,"col": 4,"name": "compile_unit_name"},{"file": 7,"line": 603,"col": 4,"name": "tty_config"},{"file": 7,"line": 604,"col": 4,"name": "printLineFromFile","comptime": true},{"file": 7,"line": 1815,"col": 30,"name": "info"},{"file": 7,"line": 1815,"col": 65,"name": "msg","comptime": true},{"file": 7,"line": 1815,"col": 83,"name": "format","comptime": true},{"file": 7,"line": 849,"col": 13,"name": "ptr"},{"file": 7,"line": 849,"col": 30,"name": "offset"},{"file": 7,"line": 849,"col": 43,"name": "size"},{"file": 7,"line": 548,"col": 22,"name": "symbols"},{"file": 7,"line": 548,"col": 52,"name": "address"},{"file": 7,"line": 1752,"col": 23,"name": "sig"},{"file": 7,"line": 1752,"col": 33,"name": "info"},{"file": 7,"line": 1752,"col": 60,"name": "ctx_ptr"},{"file": 7,"line": 676,"col": 21,"name": "allocator"},{"file": 7,"line": 676,"col": 48,"name": "coff_file"},{"file": 7,"line": 502,"col": 18,"name": "di"},{"file": 7,"line": 502,"col": 40,"name": "mod"},{"file": 8,"line": 482,"col": 11,"name": "a"},{"file": 8,"line": 482,"col": 19,"name": "b"},{"file": 8,"line": 126,"col": 13,"name": "T","comptime": true},{"file": 8,"line": 98,"col": 16,"name": "T","comptime": true},{"file": 8,"line": 252,"col": 20,"name": "T","comptime": true},{"file": 8,"line": 641,"col": 18,"name": "T","comptime": true},{"file": 8,"line": 641,"col": 36,"name": "name","comptime": true},{"file": 8,"line": 650,"col": 19,"name": "T","comptime": true},{"file": 8,"line": 112,"col": 17,"name": "T","comptime": true},{"file": 8,"line": 687,"col": 14,"name": "len","comptime": true},{"file": 8,"line": 687,"col": 33,"name": "child","comptime": true},{"file": 8,"line": 369,"col": 17,"name": "T","comptime": true},{"file": 8,"line": 369,"col": 35,"name": "field_name","comptime": true},{"file": 8,"line": 432,"col": 17,"name": "u"},{"file": 8,"line": 288,"col": 23,"name": "T","comptime": true},{"file": 8,"line": 288,"col": 41,"name": "decl_name","comptime": true},{"file": 8,"line": 658,"col": 16,"name": "Namespace","comptime": true},{"file": 8,"line": 658,"col": 42,"name": "Decl","comptime": true},{"file": 8,"line": 409,"col": 15,"name": "T","comptime": true},{"file": 8,"line": 174,"col": 16,"name": "T","comptime": true},{"file": 8,"line": 209,"col": 23,"name": "T","comptime": true},{"file": 8,"line": 11,"col": 15,"name": "v"},{"file": 8,"line": 145,"col": 12,"name": "T","comptime": true},{"file": 8,"line": 629,"col": 17,"name": "Tag","comptime": true},{"file": 8,"line": 629,"col": 37,"name": "tag_int"},{"file": 8,"line": 457,"col": 22,"name": "U","comptime": true},{"file": 8,"line": 457,"col": 40,"name": "tag"},{"file": 8,"line": 324,"col": 14,"name": "T","comptime": true},{"file": 8,"line": 54,"col": 20,"name": "T","comptime": true},{"file": 8,"line": 54,"col": 38,"name": "str"},{"file": 9,"line": 226,"col": 17,"name": "loop"},{"file": 9,"line": 60,"col": 11,"name": "handle"},{"file": 9,"line": 60,"col": 32,"name": "system_table"},{"file": 9,"line": 190,"col": 8,"name": "c_argc"},{"file": 9,"line": 190,"col": 21,"name": "c_argv"},{"file": 9,"line": 190,"col": 41,"name": "c_envp"},{"file": 9,"line": 181,"col": 20,"name": "argc"},{"file": 9,"line": 181,"col": 33,"name": "argv"},{"file": 9,"line": 181,"col": 51,"name": "envp"},{"file": 9,"line": 39,"col": 4,"name": "hinstDLL"},{"file": 9,"line": 40,"col": 4,"name": "fdwReason"},{"file": 9,"line": 41,"col": 4,"name": "lpReserved"},{"file": 10,"line": 997,"col": 22,"name": "self"},{"file": 10,"line": 1045,"col": 27,"name": "self"},{"file": 10,"line": 969,"col": 21,"name": "self"},{"file": 10,"line": 969,"col": 35,"name": "allocator"},{"file": 10,"line": 1094,"col": 23,"name": "self"},{"file": 10,"line": 1057,"col": 18,"name": "self"},{"file": 10,"line": 1072,"col": 20,"name": "self"},{"file": 10,"line": 1049,"col": 19,"name": "self"},{"file": 10,"line": 973,"col": 29,"name": "allocator"},{"file": 10,"line": 973,"col": 56,"name": "cpu_arch"},{"file": 10,"line": 973,"col": 76,"name": "os_tag"},{"file": 10,"line": 973,"col": 92,"name": "abi"},{"file": 10,"line": 1011,"col": 27,"name": "self"},{"file": 10,"line": 1001,"col": 40,"name": "cpu_arch"},{"file": 10,"line": 1001,"col": 60,"name": "abi"},{"file": 10,"line": 981,"col": 20,"name": "self"},{"file": 10,"line": 1033,"col": 33,"name": "os_tag"},{"file": 10,"line": 1033,"col": 49,"name": "cpu_arch"},{"file": 10,"line": 1019,"col": 34,"name": "cpu_arch"},{"file": 10,"line": 1019,"col": 54,"name": "abi"},{"file": 10,"line": 1053,"col": 17,"name": "self"},{"file": 10,"line": 1104,"col": 28,"name": "self"},{"file": 10,"line": 1015,"col": 28,"name": "self"},{"file": 10,"line": 1156,"col": 37,"name": "self"},{"file": 10,"line": 1084,"col": 32,"name": "self"},{"file": 10,"line": 985,"col": 28,"name": "cpu_arch"},{"file": 10,"line": 985,"col": 48,"name": "os_tag"},{"file": 10,"line": 977,"col": 23,"name": "self"},{"file": 10,"line": 977,"col": 37,"name": "allocator"},{"file": 10,"line": 1076,"col": 32,"name": "os_tag"},{"file": 10,"line": 1076,"col": 48,"name": "abi"},{"file": 10,"line": 1061,"col": 21,"name": "self"},{"file": 10,"line": 1080,"col": 21,"name": "self"},{"file": 10,"line": 1029,"col": 21,"name": "self"},{"file": 10,"line": 1068,"col": 18,"name": "self"},{"file": 10,"line": 63,"col": 36,"name": "tag"},{"file": 10,"line": 56,"col": 28,"name": "tag"},{"file": 10,"line": 109,"col": 35,"name": "self"},{"file": 10,"line": 109,"col": 60,"name": "ver"},{"file": 10,"line": 143,"col": 27,"name": "tag"},{"file": 4,"line": 408,"col": 31,"name": "self"},{"file": 4,"line": 408,"col": 44,"name": "ver"},{"file": 10,"line": 956,"col": 24,"name": "arch"},{"file": 10,"line": 390,"col": 22,"name": "abi"},{"file": 10,"line": 397,"col": 24,"name": "abi"},{"file": 10,"line": 334,"col": 23,"name": "arch"},{"file": 10,"line": 334,"col": 39,"name": "target_os"},{"file": 10,"line": 383,"col": 21,"name": "abi"},{"file": 10,"line": 99,"col": 39,"name": "self"},{"file": 10,"line": 99,"col": 52,"name": "ver"},{"file": 10,"line": 941,"col": 28,"name": "arch"},{"file": 10,"line": 909,"col": 27,"name": "arch"},{"file": 10,"line": 899,"col": 25,"name": "model"},{"file": 10,"line": 899,"col": 46,"name": "arch"},{"file": 10,"line": 534,"col": 35,"name": "F","comptime": true},{"file": 10,"line": 490,"col": 37,"name": "set"},{"file": 10,"line": 490,"col": 48,"name": "other_set"},{"file": 10,"line": 503,"col": 40,"name": "set"},{"file": 10,"line": 503,"col": 51,"name": "other_set"},{"file": 10,"line": 496,"col": 37,"name": "set"},{"file": 10,"line": 496,"col": 48,"name": "arch_feature_index"},{"file": 10,"line": 525,"col": 31,"name": "set"},{"file": 10,"line": 476,"col": 33,"name": "set"},{"file": 10,"line": 476,"col": 43,"name": "arch_feature_index"},{"file": 10,"line": 483,"col": 34,"name": "set"},{"file": 10,"line": 483,"col": 45,"name": "arch_feature_index"},{"file": 10,"line": 529,"col": 27,"name": "set"},{"file": 10,"line": 529,"col": 37,"name": "other"},{"file": 10,"line": 470,"col": 31,"name": "set"},{"file": 10,"line": 508,"col": 44,"name": "set"},{"file": 10,"line": 508,"col": 55,"name": "all_features_list"}],"files": ["/Users/benjamin.feng/projects/zee_alloc/src/wasm_exports.zig","/Users/benjamin.feng/Library/Application Support/zig/stage1/builtin/HQhB3wxyAtWkNQDB9A1GhZ3VBfaNpwZgn7zo0j9C16hr6spKk7t805ZSNPacpXYU/builtin.zig","/Users/benjamin.feng/projects/zig/lib/std/std.zig","/Users/benjamin.feng/projects/zee_alloc/src/main.zig","/Users/benjamin.feng/projects/zig/lib/std/builtin.zig","/Users/benjamin.feng/projects/zig/lib/std/mem.zig","/Users/benjamin.feng/projects/zig/lib/std/math.zig","/Users/benjamin.feng/projects/zig/lib/std/debug.zig","/Users/benjamin.feng/projects/zig/lib/std/meta.zig","/Users/benjamin.feng/projects/zig/lib/std/start.zig","/Users/benjamin.feng/projects/zig/lib/std/target.zig"]};
0
repos/zee_alloc
repos/zee_alloc/docs/main.js
(function() { var domStatus = document.getElementById("status"); var domSectNav = document.getElementById("sectNav"); var domListNav = document.getElementById("listNav"); var domSectPkgs = document.getElementById("sectPkgs"); var domListPkgs = document.getElementById("listPkgs"); var domSectTypes = document.getElementById("sectTypes"); var domListTypes = document.getElementById("listTypes"); var domSectNamespaces = document.getElementById("sectNamespaces"); var domListNamespaces = document.getElementById("listNamespaces"); var domSectErrSets = document.getElementById("sectErrSets"); var domListErrSets = document.getElementById("listErrSets"); var domSectFns = document.getElementById("sectFns"); var domListFns = document.getElementById("listFns"); var domSectFields = document.getElementById("sectFields"); var domListFields = document.getElementById("listFields"); var domSectGlobalVars = document.getElementById("sectGlobalVars"); var domListGlobalVars = document.getElementById("listGlobalVars"); var domSectValues = document.getElementById("sectValues"); var domListValues = document.getElementById("listValues"); var domFnProto = document.getElementById("fnProto"); var domFnProtoCode = document.getElementById("fnProtoCode"); var domSectParams = document.getElementById("sectParams"); var domListParams = document.getElementById("listParams"); var domTldDocs = document.getElementById("tldDocs"); var domSectFnErrors = document.getElementById("sectFnErrors"); var domListFnErrors = document.getElementById("listFnErrors"); var domTableFnErrors = document.getElementById("tableFnErrors"); var domFnErrorsAnyError = document.getElementById("fnErrorsAnyError"); var domFnExamples = document.getElementById("fnExamples"); var domListFnExamples = document.getElementById("listFnExamples"); var domFnNoExamples = document.getElementById("fnNoExamples"); var domDeclNoRef = document.getElementById("declNoRef"); var domSearch = document.getElementById("search"); var domSectSearchResults = document.getElementById("sectSearchResults"); var domListSearchResults = document.getElementById("listSearchResults"); var domSectSearchNoResults = document.getElementById("sectSearchNoResults"); var domSectSearchAllResultsLink = document.getElementById("sectSearchAllResultsLink"); var domSectInfo = document.getElementById("sectInfo"); var domTdTarget = document.getElementById("tdTarget"); var domTdZigVer = document.getElementById("tdZigVer"); var domHdrName = document.getElementById("hdrName"); var domHelpModal = document.getElementById("helpDialog"); var searchTimer = null; var searchTrimResults = true; var escapeHtmlReplacements = { "&": "&amp;", '"': "&quot;", "<": "&lt;", ">": "&gt;" }; var typeKinds = indexTypeKinds(); var typeTypeId = findTypeTypeId(); var pointerSizeEnum = { One: 0, Many: 1, Slice: 2, C: 3 }; var tokenKinds = { Keyword: 'tok-kw', String: 'tok-str', Builtin: 'tok-builtin', Comment: 'tok-comment', Function: 'tok-fn', Null: 'tok-null', Number: 'tok-number', Type: 'tok-type', }; // for each package, is an array with packages to get to this one var canonPkgPaths = computeCanonicalPackagePaths(); // for each decl, is an array with {declNames, pkgNames} to get to this one var canonDeclPaths = null; // lazy; use getCanonDeclPath // for each type, is an array with {declNames, pkgNames} to get to this one var canonTypeDecls = null; // lazy; use getCanonTypeDecl var curNav = { // each element is a package name, e.g. @import("a") then within there @import("b") // starting implicitly from root package pkgNames: [], // same as above except actual packages, not names pkgObjs: [], // Each element is a decl name, `a.b.c`, a is 0, b is 1, c is 2, etc. // empty array means refers to the package itself declNames: [], // these will be all types, except the last one may be a type or a decl declObjs: [], // (a, b, c, d) comptime call; result is the value the docs refer to callName: null, }; var curNavSearch = ""; var curSearchIndex = -1; var imFeelingLucky = false; var rootIsStd = detectRootIsStd(); // map of decl index to list of non-generic fn indexes var nodesToFnsMap = indexNodesToFns(); // map of decl index to list of comptime fn calls var nodesToCallsMap = indexNodesToCalls(); domSearch.addEventListener('keydown', onSearchKeyDown, false); domSectSearchAllResultsLink.addEventListener('click', onClickSearchShowAllResults, false); window.addEventListener('hashchange', onHashChange, false); window.addEventListener('keydown', onWindowKeyDown, false); onHashChange(); function renderTitle() { var list = curNav.pkgNames.concat(curNav.declNames); var suffix = " - Zig"; if (list.length === 0) { if (rootIsStd) { document.title = "std" + suffix; } else { document.title = zigAnalysis.params.rootName + suffix; } } else { document.title = list.join('.') + suffix; } } function render() { domStatus.classList.add("hidden"); domFnProto.classList.add("hidden"); domSectParams.classList.add("hidden"); domTldDocs.classList.add("hidden"); domSectPkgs.classList.add("hidden"); domSectTypes.classList.add("hidden"); domSectNamespaces.classList.add("hidden"); domSectErrSets.classList.add("hidden"); domSectFns.classList.add("hidden"); domSectFields.classList.add("hidden"); domSectSearchResults.classList.add("hidden"); domSectSearchNoResults.classList.add("hidden"); domSectSearchAllResultsLink.classList.add("hidden"); domSectInfo.classList.add("hidden"); domHdrName.classList.add("hidden"); domSectNav.classList.add("hidden"); domSectFnErrors.classList.add("hidden"); domFnExamples.classList.add("hidden"); domFnNoExamples.classList.add("hidden"); domDeclNoRef.classList.add("hidden"); domFnErrorsAnyError.classList.add("hidden"); domTableFnErrors.classList.add("hidden"); domSectGlobalVars.classList.add("hidden"); domSectValues.classList.add("hidden"); renderTitle(); renderInfo(); renderPkgList(); if (curNavSearch !== "") { return renderSearch(); } var rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg]; var pkg = rootPkg; curNav.pkgObjs = [pkg]; for (var i = 0; i < curNav.pkgNames.length; i += 1) { var childPkg = zigAnalysis.packages[pkg.table[curNav.pkgNames[i]]]; if (childPkg == null) { return render404(); } pkg = childPkg; curNav.pkgObjs.push(pkg); } var decl = zigAnalysis.types[pkg.main]; curNav.declObjs = [decl]; for (var i = 0; i < curNav.declNames.length; i += 1) { var childDecl = findSubDecl(decl, curNav.declNames[i]); if (childDecl == null) { return render404(); } var container = getDeclContainerType(childDecl); if (container == null) { if (i + 1 === curNav.declNames.length) { curNav.declObjs.push(childDecl); break; } else { return render404(); } } decl = container; curNav.declObjs.push(decl); } renderNav(); var lastDecl = curNav.declObjs[curNav.declObjs.length - 1]; if (lastDecl.pubDecls != null) { renderContainer(lastDecl); } if (lastDecl.kind == null) { return renderUnknownDecl(lastDecl); } else if (lastDecl.kind === 'var') { return renderVar(lastDecl); } else if (lastDecl.kind === 'const' && lastDecl.type != null) { var typeObj = zigAnalysis.types[lastDecl.type]; if (typeObj.kind === typeKinds.Fn) { return renderFn(lastDecl); } else { return renderValue(lastDecl); } } else { renderType(lastDecl); } } function renderUnknownDecl(decl) { domDeclNoRef.classList.remove("hidden"); var docs = zigAnalysis.astNodes[decl.src].docs; if (docs != null) { domTldDocs.innerHTML = markdown(docs); } else { domTldDocs.innerHTML = '<p>There are no doc comments for this declaration.</p>'; } domTldDocs.classList.remove("hidden"); } function typeIsErrSet(typeIndex) { var typeObj = zigAnalysis.types[typeIndex]; return typeObj.kind === typeKinds.ErrorSet; } function typeIsStructWithNoFields(typeIndex) { var typeObj = zigAnalysis.types[typeIndex]; if (typeObj.kind !== typeKinds.Struct) return false; return typeObj.fields == null || typeObj.fields.length === 0; } function typeIsGenericFn(typeIndex) { var typeObj = zigAnalysis.types[typeIndex]; if (typeObj.kind !== typeKinds.Fn) { return false; } return typeObj.generic; } function renderFn(fnDecl) { domFnProtoCode.innerHTML = typeIndexName(fnDecl.type, true, true, fnDecl); var docsSource = null; var srcNode = zigAnalysis.astNodes[fnDecl.src]; if (srcNode.docs != null) { docsSource = srcNode.docs; } var typeObj = zigAnalysis.types[fnDecl.type]; renderFnParamDocs(fnDecl, typeObj); var errSetTypeIndex = null; if (typeObj.ret != null) { var retType = zigAnalysis.types[typeObj.ret]; if (retType.kind === typeKinds.ErrorSet) { errSetTypeIndex = typeObj.ret; } else if (retType.kind === typeKinds.ErrorUnion) { errSetTypeIndex = retType.err; } } if (errSetTypeIndex != null) { var errSetType = zigAnalysis.types[errSetTypeIndex]; renderErrorSet(errSetType); } var fnObj = zigAnalysis.fns[fnDecl.value]; var protoSrcIndex = fnObj.src; if (typeIsGenericFn(fnDecl.type)) { var instantiations = nodesToFnsMap[protoSrcIndex]; var calls = nodesToCallsMap[protoSrcIndex]; if (instantiations == null && calls == null) { domFnNoExamples.classList.remove("hidden"); } else if (calls != null) { if (fnObj.combined === undefined) fnObj.combined = allCompTimeFnCallsResult(calls); if (fnObj.combined != null) renderContainer(fnObj.combined); var domListFnExamplesFragment = createDomListFragment(calls.length, '<li></li>'); for (var callI = 0; callI < calls.length; callI += 1) { var liDom = domListFnExamplesFragment.children[callI]; liDom.innerHTML = getCallHtml(fnDecl, calls[callI]); } domListFnExamples.innerHTML = ""; domListFnExamples.appendChild(domListFnExamplesFragment); domFnExamples.classList.remove("hidden"); } else if (instantiations != null) { // TODO } } else { domFnExamples.classList.add("hidden"); domFnNoExamples.classList.add("hidden"); } var protoSrcNode = zigAnalysis.astNodes[protoSrcIndex]; if (docsSource == null && protoSrcNode != null && protoSrcNode.docs != null) { docsSource = protoSrcNode.docs; } if (docsSource != null) { domTldDocs.innerHTML = markdown(docsSource); domTldDocs.classList.remove("hidden"); } domFnProto.classList.remove("hidden"); } function renderFnParamDocs(fnDecl, typeObj) { var docCount = 0; var fnObj = zigAnalysis.fns[fnDecl.value]; var fnNode = zigAnalysis.astNodes[fnObj.src]; var fields = fnNode.fields; var isVarArgs = fnNode.varArgs; for (var i = 0; i < fields.length; i += 1) { var field = fields[i]; var fieldNode = zigAnalysis.astNodes[field]; if (fieldNode.docs != null) { docCount += 1; } } if (docCount == 0) { return; } var domListParamsFragment = createDomListFragment(docCount, '<div></div>'); var domIndex = 0; for (var i = 0; i < fields.length; i += 1) { var field = fields[i]; var fieldNode = zigAnalysis.astNodes[field]; if (fieldNode.docs == null) { continue; } var divDom = domListParamsFragment.children[domIndex]; domIndex += 1; var argTypeIndex = typeObj.args[i]; var html = '<pre>' + escapeHtml(fieldNode.name) + ": "; if (isVarArgs && i === typeObj.args.length - 1) { html += '...'; } else if (argTypeIndex != null) { html += typeIndexName(argTypeIndex, true, true); } else { html += '<span class="tok-kw">var</span>'; } html += ',</pre>'; var docs = fieldNode.docs; if (docs != null) { html += markdown(docs); } divDom.innerHTML = html; } domListParams.innerHTML = ""; domListParams.appendChild(domListParamsFragment); domSectParams.classList.remove("hidden"); } function renderNav() { var len = curNav.pkgNames.length + curNav.declNames.length; var domListNavFragment = createDomListFragment(len, '<li><a href="#"></a></li>'); var list = []; var hrefPkgNames = []; var hrefDeclNames = []; for (var i = 0; i < curNav.pkgNames.length; i += 1) { hrefPkgNames.push(curNav.pkgNames[i]); list.push({ name: curNav.pkgNames[i], link: navLink(hrefPkgNames, hrefDeclNames), }); } for (var i = 0; i < curNav.declNames.length; i += 1) { hrefDeclNames.push(curNav.declNames[i]); list.push({ name: curNav.declNames[i], link: navLink(hrefPkgNames, hrefDeclNames), }); } for (var i = 0; i < list.length; i += 1) { var liDom = domListNavFragment.children[i]; var aDom = liDom.children[0]; aDom.textContent = list[i].name; aDom.setAttribute('href', list[i].link); if (i + 1 == list.length) { aDom.classList.add("active"); } else { aDom.classList.remove("active"); } } domListNav.innerHTML = ""; domListNav.appendChild(domListNavFragment); domSectNav.classList.remove("hidden"); } function renderInfo() { domTdZigVer.textContent = zigAnalysis.params.zigVersion; domTdTarget.textContent = zigAnalysis.params.builds[0].target; domSectInfo.classList.remove("hidden"); } function render404() { domStatus.textContent = "404 Not Found"; domStatus.classList.remove("hidden"); } function renderPkgList() { var rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg]; var list = []; for (var key in rootPkg.table) { if (key === "root" && rootIsStd) continue; var pkgIndex = rootPkg.table[key]; if (zigAnalysis.packages[pkgIndex] == null) continue; list.push({ name: key, pkg: pkgIndex, }); } list.sort(function(a, b) { return operatorCompare(a.name.toLowerCase(), b.name.toLowerCase()); }); if (list.length !== 0) { var domListPkgsFragment = createDomListFragment(list.length, '<li><a href="#"></a></li>'); for (var i = 0; i < list.length; i += 1) { var liDom = domListPkgsFragment.children[i]; var aDom = liDom.children[0]; aDom.textContent = list[i].name; aDom.setAttribute('href', navLinkPkg(list[i].pkg)); if (list[i].name === curNav.pkgNames[0]) { aDom.classList.add("active"); } else { aDom.classList.remove("active"); } } domListPkgs.innerHTML = ""; domListPkgs.appendChild(domListPkgsFragment); domSectPkgs.classList.remove("hidden"); } } function navLink(pkgNames, declNames, callName) { if (pkgNames.length === 0 && declNames.length === 0) { return '#'; } else if (declNames.length === 0 && callName == null) { return '#' + pkgNames.join('.'); } else if (callName == null) { return '#' + pkgNames.join('.') + ';' + declNames.join('.'); } else { return '#' + pkgNames.join('.') + ';' + declNames.join('.') + ';' + callName; } } function navLinkPkg(pkgIndex) { return navLink(canonPkgPaths[pkgIndex], []); } function navLinkDecl(childName) { return navLink(curNav.pkgNames, curNav.declNames.concat([childName])); } function navLinkCall(callObj) { var declNamesCopy = curNav.declNames.concat([]); var callName = declNamesCopy.pop(); callName += '('; for (var arg_i = 0; arg_i < callObj.args.length; arg_i += 1) { if (arg_i !== 0) callName += ','; var argObj = callObj.args[arg_i]; callName += getValueText(argObj.type, argObj.value, false, false); } callName += ')'; declNamesCopy.push(callName); return navLink(curNav.pkgNames, declNamesCopy); } function createDomListFragment(desiredLen, templateHtml) { var domTemplate = document.createElement("template"); domTemplate.innerHTML = templateHtml.repeat(desiredLen); return domTemplate.content; } function typeIndexName(typeIndex, wantHtml, wantLink, fnDecl, linkFnNameDecl) { var typeObj = zigAnalysis.types[typeIndex]; var declNameOk = declCanRepresentTypeKind(typeObj.kind); if (wantLink) { var declIndex = getCanonTypeDecl(typeIndex); var declPath = getCanonDeclPath(declIndex); if (declPath == null) { return typeName(typeObj, wantHtml, wantLink, fnDecl, linkFnNameDecl); } var name = (wantLink && declCanRepresentTypeKind(typeObj.kind)) ? declPath.declNames[declPath.declNames.length - 1] : typeName(typeObj, wantHtml, false, fnDecl, linkFnNameDecl); if (wantLink && wantHtml) { return '<a href="' + navLink(declPath.pkgNames, declPath.declNames) + '">' + name + '</a>'; } else { return name; } } else { return typeName(typeObj, wantHtml, false, fnDecl, linkFnNameDecl); } } function shouldSkipParamName(typeIndex, paramName) { var typeObj = zigAnalysis.types[typeIndex]; if (typeObj.kind === typeKinds.Pointer && getPtrSize(typeObj) === pointerSizeEnum.One) { typeIndex = typeObj.elem; } return typeIndexName(typeIndex, false, true).toLowerCase() === paramName; } function getPtrSize(typeObj) { return (typeObj.len == null) ? pointerSizeEnum.One : typeObj.len; } function getCallHtml(fnDecl, callIndex) { var callObj = zigAnalysis.calls[callIndex]; // TODO make these links work //var html = '<a href="' + navLinkCall(callObj) + '">' + escapeHtml(fnDecl.name) + '</a>('; var html = escapeHtml(fnDecl.name) + '('; for (var arg_i = 0; arg_i < callObj.args.length; arg_i += 1) { if (arg_i !== 0) html += ', '; var argObj = callObj.args[arg_i]; html += getValueText(argObj.type, argObj.value, true, true); } html += ')'; return html; } function getValueText(typeIndex, value, wantHtml, wantLink) { var typeObj = zigAnalysis.types[typeIndex]; switch (typeObj.kind) { case typeKinds.Type: return typeIndexName(value, wantHtml, wantLink); case typeKinds.Fn: var fnObj = zigAnalysis.fns[value]; return typeIndexName(fnObj.type, wantHtml, wantLink); case typeKinds.Int: return token(value, tokenKinds.Number, wantHtml); case typeKinds.Optional: if(value === 'null'){ return token(value, tokenKinds.Null, wantHtml); } else { console.trace("TODO non-null optional value printing"); return "TODO"; } default: console.trace("TODO implement getValueText for this type:", zigAnalysis.typeKinds[typeObj.kind]); return "TODO"; } } function typeName(typeObj, wantHtml, wantSubLink, fnDecl, linkFnNameDecl) { switch (typeObj.kind) { case typeKinds.Array: var name = "["; name += token(typeObj.len, tokenKinds.Number, wantHtml); name += "]"; name += typeIndexName(typeObj.elem, wantHtml, wantSubLink, null); return name; case typeKinds.Optional: return "?" + typeIndexName(typeObj.child, wantHtml, wantSubLink, fnDecl, linkFnNameDecl); case typeKinds.Pointer: var name = ""; switch (typeObj.len) { case pointerSizeEnum.One: default: name += "*"; break; case pointerSizeEnum.Many: name += "[*]"; break; case pointerSizeEnum.Slice: name += "[]"; break; case pointerSizeEnum.C: name += "[*c]"; break; } if (typeObj['const']) { name += token('const', tokenKinds.Keyword, wantHtml) + ' '; } if (typeObj['volatile']) { name += token('volatile', tokenKinds.Keyword, wantHtml) + ' '; } if (typeObj.align != null) { name += token('align', tokenKinds.Keyword, wantHtml) + '('; name += token(typeObj.align, tokenKinds.Number, wantHtml); if (typeObj.hostIntBytes != null) { name += ":"; name += token(typeObj.bitOffsetInHost, tokenKinds.Number, wantHtml); name += ":"; name += token(typeObj.hostIntBytes, tokenKinds.Number, wantHtml); } name += ") "; } name += typeIndexName(typeObj.elem, wantHtml, wantSubLink, null); return name; case typeKinds.Float: return token('f' + typeObj.bits, tokenKinds.Type, wantHtml); case typeKinds.Int: var signed = (typeObj.i != null) ? 'i' : 'u'; var bits = typeObj[signed]; return token(signed + bits, tokenKinds.Type, wantHtml); case typeKinds.ComptimeInt: return token('comptime_int', tokenKinds.Type, wantHtml); case typeKinds.ComptimeFloat: return token('comptime_float', tokenKinds.Type, wantHtml); case typeKinds.Type: return token('type', tokenKinds.Type, wantHtml); case typeKinds.Bool: return token('bool', tokenKinds.Type, wantHtml); case typeKinds.Void: return token('void', tokenKinds.Type, wantHtml); case typeKinds.EnumLiteral: return token('(enum literal)', tokenKinds.Type, wantHtml); case typeKinds.NoReturn: return token('noreturn', tokenKinds.Type, wantHtml); case typeKinds.ErrorSet: if (typeObj.errors == null) { return token('anyerror', tokenKinds.Type, wantHtml); } else { if (wantHtml) { return escapeHtml(typeObj.name); } else { return typeObj.name; } } case typeKinds.ErrorUnion: var errSetTypeObj = zigAnalysis.types[typeObj.err]; var payloadHtml = typeIndexName(typeObj.payload, wantHtml, wantSubLink, null); if (fnDecl != null && errSetTypeObj.fn === fnDecl.value) { // function index parameter supplied and this is the inferred error set of it return "!" + payloadHtml; } else { return typeIndexName(typeObj.err, wantHtml, wantSubLink, null) + "!" + payloadHtml; } case typeKinds.Fn: var payloadHtml = ""; if (wantHtml) { payloadHtml += '<span class="tok-kw">fn</span>'; if (fnDecl != null) { payloadHtml += ' <span class="tok-fn">'; if (linkFnNameDecl != null) { payloadHtml += '<a href="' + linkFnNameDecl + '">' + escapeHtml(fnDecl.name) + '</a>'; } else { payloadHtml += escapeHtml(fnDecl.name); } payloadHtml += '</span>'; } } else { payloadHtml += 'fn' } payloadHtml += '('; if (typeObj.args != null) { var fields = null; var isVarArgs = false; if (fnDecl != null) { var fnObj = zigAnalysis.fns[fnDecl.value]; var fnNode = zigAnalysis.astNodes[fnObj.src]; fields = fnNode.fields; isVarArgs = fnNode.varArgs; } for (var i = 0; i < typeObj.args.length; i += 1) { if (i != 0) { payloadHtml += ', '; } var argTypeIndex = typeObj.args[i]; if (fields != null) { var paramNode = zigAnalysis.astNodes[fields[i]]; if (paramNode.varArgs) { payloadHtml += '...'; continue; } if (paramNode.noalias) { payloadHtml += token('noalias', tokenKinds.Keyword, wantHtml) + ' '; } if (paramNode.comptime) { payloadHtml += token('comptime', tokenKinds.Keyword, wantHtml) + ' '; } var paramName = paramNode.name; if (paramName != null) { // skip if it matches the type name if (argTypeIndex == null || !shouldSkipParamName(argTypeIndex, paramName)) { payloadHtml += paramName + ': '; } } } if (isVarArgs && i === typeObj.args.length - 1) { payloadHtml += '...'; } else if (argTypeIndex != null) { payloadHtml += typeIndexName(argTypeIndex, wantHtml, wantSubLink); } else { payloadHtml += token('var', tokenKinds.Keyword, wantHtml); } } } payloadHtml += ') '; if (typeObj.ret != null) { payloadHtml += typeIndexName(typeObj.ret, wantHtml, wantSubLink, fnDecl); } else { payloadHtml += token('var', tokenKinds.Keyword, wantHtml); } return payloadHtml; default: if (wantHtml) { return escapeHtml(typeObj.name); } else { return typeObj.name; } } } function renderType(typeObj) { var name; if (rootIsStd && typeObj === zigAnalysis.types[zigAnalysis.packages[zigAnalysis.rootPkg].main]) { name = "std"; } else { name = typeName(typeObj, false, false); } if (name != null && name != "") { domHdrName.innerText = name + " (" + zigAnalysis.typeKinds[typeObj.kind] + ")"; domHdrName.classList.remove("hidden"); } if (typeObj.kind == typeKinds.ErrorSet) { renderErrorSet(typeObj); } } function renderErrorSet(errSetType) { if (errSetType.errors == null) { domFnErrorsAnyError.classList.remove("hidden"); } else { var errorList = []; for (var i = 0; i < errSetType.errors.length; i += 1) { var errObj = zigAnalysis.errors[errSetType.errors[i]]; var srcObj = zigAnalysis.astNodes[errObj.src]; errorList.push({ err: errObj, docs: srcObj.docs, }); } errorList.sort(function(a, b) { return operatorCompare(a.err.name.toLowerCase(), b.err.name.toLowerCase()); }); var domListFnErrorsFragment = createDomListFragment(errorList.length, "<dt></dt><dd></dd>"); for (var i = 0; i < errorList.length; i += 1) { var nameTdDom = domListFnErrorsFragment.children[i * 2 + 0]; var descTdDom = domListFnErrorsFragment.children[i * 2 + 1]; nameTdDom.textContent = errorList[i].err.name; var docs = errorList[i].docs; if (docs != null) { descTdDom.innerHTML = markdown(docs); } else { descTdDom.textContent = ""; } } domListFnErrors.innerHTML = ""; domListFnErrors.appendChild(domListFnErrorsFragment); domTableFnErrors.classList.remove("hidden"); } domSectFnErrors.classList.remove("hidden"); } function allCompTimeFnCallsHaveTypeResult(typeIndex, value) { var srcIndex = zigAnalysis.fns[value].src; var calls = nodesToCallsMap[srcIndex]; if (calls == null) return false; for (var i = 0; i < calls.length; i += 1) { var call = zigAnalysis.calls[calls[i]]; if (call.result.type !== typeTypeId) return false; } return true; } function allCompTimeFnCallsResult(calls) { var firstTypeObj = null; var containerObj = { privDecls: [], }; for (var callI = 0; callI < calls.length; callI += 1) { var call = zigAnalysis.calls[calls[callI]]; if (call.result.type !== typeTypeId) return null; var typeObj = zigAnalysis.types[call.result.value]; if (!typeKindIsContainer(typeObj.kind)) return null; if (firstTypeObj == null) { firstTypeObj = typeObj; containerObj.src = typeObj.src; } else if (firstTypeObj.src !== typeObj.src) { return null; } if (containerObj.fields == null) { containerObj.fields = (typeObj.fields || []).concat([]); } else for (var fieldI = 0; fieldI < typeObj.fields.length; fieldI += 1) { var prev = containerObj.fields[fieldI]; var next = typeObj.fields[fieldI]; if (prev === next) continue; if (typeof(prev) === 'object') { if (prev[next] == null) prev[next] = typeObj; } else { containerObj.fields[fieldI] = {}; containerObj.fields[fieldI][prev] = firstTypeObj; containerObj.fields[fieldI][next] = typeObj; } } if (containerObj.pubDecls == null) { containerObj.pubDecls = (typeObj.pubDecls || []).concat([]); } else for (var declI = 0; declI < typeObj.pubDecls.length; declI += 1) { var prev = containerObj.pubDecls[declI]; var next = typeObj.pubDecls[declI]; if (prev === next) continue; // TODO instead of showing "examples" as the public declarations, // do logic like this: //if (typeof(prev) !== 'object') { // var newDeclId = zigAnalysis.decls.length; // prev = clone(zigAnalysis.decls[prev]); // prev.id = newDeclId; // zigAnalysis.decls.push(prev); // containerObj.pubDecls[declI] = prev; //} //mergeDecls(prev, next, firstTypeObj, typeObj); } } for (var declI = 0; declI < containerObj.pubDecls.length; declI += 1) { var decl = containerObj.pubDecls[declI]; if (typeof(decl) === 'object') { containerObj.pubDecls[declI] = containerObj.pubDecls[declI].id; } } return containerObj; } function mergeDecls(declObj, nextDeclIndex, firstTypeObj, typeObj) { var nextDeclObj = zigAnalysis.decls[nextDeclIndex]; if (declObj.type != null && nextDeclObj.type != null && declObj.type !== nextDeclObj.type) { if (typeof(declObj.type) !== 'object') { var prevType = declObj.type; declObj.type = {}; declObj.type[prevType] = firstTypeObj; declObj.value = null; } declObj.type[nextDeclObj.type] = typeObj; } else if (declObj.type == null && nextDeclObj != null) { declObj.type = nextDeclObj.type; } if (declObj.value != null && nextDeclObj.value != null && declObj.value !== nextDeclObj.value) { if (typeof(declObj.value) !== 'object') { var prevValue = declObj.value; declObj.value = {}; declObj.value[prevValue] = firstTypeObj; } declObj.value[nextDeclObj.value] = typeObj; } else if (declObj.value == null && nextDeclObj.value != null) { declObj.value = nextDeclObj.value; } } function renderValue(decl) { domFnProtoCode.innerHTML = '<span class="tok-kw">const</span> ' + escapeHtml(decl.name) + ': ' + typeIndexName(decl.type, true, true); var docs = zigAnalysis.astNodes[decl.src].docs; if (docs != null) { domTldDocs.innerHTML = markdown(docs); domTldDocs.classList.remove("hidden"); } domFnProto.classList.remove("hidden"); } function renderVar(decl) { domFnProtoCode.innerHTML = '<span class="tok-kw">var</span> ' + escapeHtml(decl.name) + ': ' + typeIndexName(decl.type, true, true); var docs = zigAnalysis.astNodes[decl.src].docs; if (docs != null) { domTldDocs.innerHTML = markdown(docs); domTldDocs.classList.remove("hidden"); } domFnProto.classList.remove("hidden"); } function renderContainer(container) { var typesList = []; var namespacesList = []; var errSetsList = []; var fnsList = []; var varsList = []; var valsList = []; for (var i = 0; i < container.pubDecls.length; i += 1) { var decl = zigAnalysis.decls[container.pubDecls[i]]; if (decl.kind === 'var') { varsList.push(decl); continue; } else if (decl.kind === 'const' && decl.type != null) { if (decl.type === typeTypeId) { if (typeIsErrSet(decl.value)) { errSetsList.push(decl); } else if (typeIsStructWithNoFields(decl.value)) { namespacesList.push(decl); } else { typesList.push(decl); } } else { var typeKind = zigAnalysis.types[decl.type].kind; if (typeKind === typeKinds.Fn) { if (allCompTimeFnCallsHaveTypeResult(decl.type, decl.value)) { typesList.push(decl); } else { fnsList.push(decl); } } else { valsList.push(decl); } } } } typesList.sort(byNameProperty); namespacesList.sort(byNameProperty); errSetsList.sort(byNameProperty); fnsList.sort(byNameProperty); varsList.sort(byNameProperty); valsList.sort(byNameProperty); if (container.src != null) { var docs = zigAnalysis.astNodes[container.src].docs; if (docs != null) { domTldDocs.innerHTML = markdown(docs); domTldDocs.classList.remove("hidden"); } } if (typesList.length !== 0) { var domListTypesFragment = createDomListFragment(typesList.length, '<li><a href="#"></a></li>'); for (var i = 0; i < typesList.length; i += 1) { var liDom = domListTypesFragment.children[i]; var aDom = liDom.children[0]; var decl = typesList[i]; aDom.textContent = decl.name; aDom.setAttribute('href', navLinkDecl(decl.name)); } domListTypes.innerHTML = ""; domListTypes.appendChild(domListTypesFragment); domSectTypes.classList.remove("hidden"); } if (namespacesList.length !== 0) { var domListNamespacesFragment = createDomListFragment(namespacesList.length, '<li><a href="#"></a></li>'); for (var i = 0; i < namespacesList.length; i += 1) { var liDom = domListNamespacesFragment.children[i]; var aDom = liDom.children[0]; var decl = namespacesList[i]; aDom.textContent = decl.name; aDom.setAttribute('href', navLinkDecl(decl.name)); } domListNamespaces.innerHTML = ""; domListNamespaces.appendChild(domListNamespacesFragment); domSectNamespaces.classList.remove("hidden"); } if (errSetsList.length !== 0) { var domListErrSetsFragment = createDomListFragment(errSetsList.length, '<li><a href="#"></a></li>'); for (var i = 0; i < errSetsList.length; i += 1) { var liDom = domListErrSetsFragment.children[i]; var aDom = liDom.children[0]; var decl = errSetsList[i]; aDom.textContent = decl.name; aDom.setAttribute('href', navLinkDecl(decl.name)); } domListErrSets.innerHTML = ""; domListErrSets.appendChild(domListErrSetsFragment); domSectErrSets.classList.remove("hidden"); } if (fnsList.length !== 0) { var domListFnsFragment = createDomListFragment(fnsList.length, '<tr><td></td><td></td></tr>'); for (var i = 0; i < fnsList.length; i += 1) { var decl = fnsList[i]; var trDom = domListFnsFragment.children[i]; var tdFnCode = trDom.children[0]; var tdDesc = trDom.children[1]; tdFnCode.innerHTML = typeIndexName(decl.type, true, true, decl, navLinkDecl(decl.name)); var docs = zigAnalysis.astNodes[decl.src].docs; if (docs != null) { tdDesc.innerHTML = shortDescMarkdown(docs); } else { tdDesc.textContent = ""; } } domListFns.innerHTML = ""; domListFns.appendChild(domListFnsFragment); domSectFns.classList.remove("hidden"); } if (container.fields != null && container.fields.length !== 0) { var domListFieldsFragment = createDomListFragment(container.fields.length, '<div></div>'); var containerNode = zigAnalysis.astNodes[container.src]; for (var i = 0; i < container.fields.length; i += 1) { var field = container.fields[i]; var fieldNode = zigAnalysis.astNodes[containerNode.fields[i]]; var divDom = domListFieldsFragment.children[i]; var html = '<div class="mobile-scroll-container"><pre class="scroll-item">' + escapeHtml(fieldNode.name); if (container.kind === typeKinds.Enum) { html += ' = <span class="tok-number">' + field + '</span>'; } else { html += ": "; if (typeof(field) === 'object') { html += '<span class="tok-kw">var</span>'; } else { html += typeIndexName(field, true, true); } } html += ',</pre></div>'; var docs = fieldNode.docs; if (docs != null) { html += markdown(docs); } divDom.innerHTML = html; } domListFields.innerHTML = ""; domListFields.appendChild(domListFieldsFragment); domSectFields.classList.remove("hidden"); } if (varsList.length !== 0) { var domListGlobalVarsFragment = createDomListFragment(varsList.length, '<tr><td><a href="#"></a></td><td></td><td></td></tr>'); for (var i = 0; i < varsList.length; i += 1) { var decl = varsList[i]; var trDom = domListGlobalVarsFragment.children[i]; var tdName = trDom.children[0]; var tdNameA = tdName.children[0]; var tdType = trDom.children[1]; var tdDesc = trDom.children[2]; tdNameA.setAttribute('href', navLinkDecl(decl.name)); tdNameA.textContent = decl.name; tdType.innerHTML = typeIndexName(decl.type, true, true); var docs = zigAnalysis.astNodes[decl.src].docs; if (docs != null) { tdDesc.innerHTML = shortDescMarkdown(docs); } else { tdDesc.textContent = ""; } } domListGlobalVars.innerHTML = ""; domListGlobalVars.appendChild(domListGlobalVarsFragment); domSectGlobalVars.classList.remove("hidden"); } if (valsList.length !== 0) { var domListValuesFragment = createDomListFragment(valsList.length, '<tr><td><a href="#"></a></td><td></td><td></td></tr>'); for (var i = 0; i < valsList.length; i += 1) { var decl = valsList[i]; var trDom = domListValuesFragment.children[i]; var tdName = trDom.children[0]; var tdNameA = tdName.children[0]; var tdType = trDom.children[1]; var tdDesc = trDom.children[2]; tdNameA.setAttribute('href', navLinkDecl(decl.name)); tdNameA.textContent = decl.name; tdType.innerHTML = typeIndexName(decl.type, true, true); var docs = zigAnalysis.astNodes[decl.src].docs; if (docs != null) { tdDesc.innerHTML = shortDescMarkdown(docs); } else { tdDesc.textContent = ""; } } domListValues.innerHTML = ""; domListValues.appendChild(domListValuesFragment); domSectValues.classList.remove("hidden"); } } function operatorCompare(a, b) { if (a === b) { return 0; } else if (a < b) { return -1; } else { return 1; } } function detectRootIsStd() { var rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg]; if (rootPkg.table["std"] == null) { // no std mapped into the root package return false; } var stdPkg = zigAnalysis.packages[rootPkg.table["std"]]; if (stdPkg == null) return false; return rootPkg.file === stdPkg.file; } function indexTypeKinds() { var map = {}; for (var i = 0; i < zigAnalysis.typeKinds.length; i += 1) { map[zigAnalysis.typeKinds[i]] = i; } // This is just for debugging purposes, not needed to function var assertList = ["Type","Void","Bool","NoReturn","Int","Float","Pointer","Array","Struct", "ComptimeFloat","ComptimeInt","Undefined","Null","Optional","ErrorUnion","ErrorSet","Enum", "Union","Fn","BoundFn","Opaque","Frame","AnyFrame","Vector","EnumLiteral"]; for (var i = 0; i < assertList.length; i += 1) { if (map[assertList[i]] == null) throw new Error("No type kind '" + assertList[i] + "' found"); } return map; } function findTypeTypeId() { for (var i = 0; i < zigAnalysis.types.length; i += 1) { if (zigAnalysis.types[i].kind == typeKinds.Type) { return i; } } throw new Error("No type 'type' found"); } function updateCurNav() { curNav = { pkgNames: [], pkgObjs: [], declNames: [], declObjs: [], }; curNavSearch = ""; if (location.hash[0] === '#' && location.hash.length > 1) { var query = location.hash.substring(1); var qpos = query.indexOf("?"); if (qpos === -1) { nonSearchPart = query; } else { nonSearchPart = query.substring(0, qpos); curNavSearch = decodeURIComponent(query.substring(qpos + 1)); } var parts = nonSearchPart.split(";"); curNav.pkgNames = decodeURIComponent(parts[0]).split("."); if (parts[1] != null) { curNav.declNames = decodeURIComponent(parts[1]).split("."); } } if (curNav.pkgNames.length === 0 && rootIsStd) { curNav.pkgNames = ["std"]; } } function onHashChange() { updateCurNav(); if (domSearch.value !== curNavSearch) { domSearch.value = curNavSearch; } render(); if (imFeelingLucky) { imFeelingLucky = false; activateSelectedResult(); } } function findSubDecl(parentType, childName) { if (parentType.pubDecls == null) throw new Error("parent object has no public decls"); for (var i = 0; i < parentType.pubDecls.length; i += 1) { var declIndex = parentType.pubDecls[i]; var childDecl = zigAnalysis.decls[declIndex]; if (childDecl.name === childName) { return childDecl; } } return null; } function getDeclContainerType(decl) { if (decl.type === typeTypeId) { return zigAnalysis.types[decl.value]; } return null; } function computeCanonicalPackagePaths() { var list = new Array(zigAnalysis.packages.length); // Now we try to find all the packages from root. var rootPkg = zigAnalysis.packages[zigAnalysis.rootPkg]; // Breadth-first to keep the path shortest possible. var stack = [{ path: [], pkg: rootPkg, }]; while (stack.length !== 0) { var item = stack.shift(); for (var key in item.pkg.table) { var childPkgIndex = item.pkg.table[key]; if (list[childPkgIndex] != null) continue; var childPkg = zigAnalysis.packages[childPkgIndex]; if (childPkg == null) continue; var newPath = item.path.concat([key]) list[childPkgIndex] = newPath; stack.push({ path: newPath, pkg: childPkg, }); } } return list; } function typeKindIsContainer(typeKind) { return typeKind === typeKinds.Struct || typeKind === typeKinds.Union || typeKind === typeKinds.Enum; } function declCanRepresentTypeKind(typeKind) { return typeKind === typeKinds.ErrorSet || typeKindIsContainer(typeKind); } function computeCanonDeclPaths() { var list = new Array(zigAnalysis.decls.length); canonTypeDecls = new Array(zigAnalysis.types.length); for (var pkgI = 0; pkgI < zigAnalysis.packages.length; pkgI += 1) { if (pkgI === zigAnalysis.rootPkg && rootIsStd) continue; var pkg = zigAnalysis.packages[pkgI]; var pkgNames = canonPkgPaths[pkgI]; var stack = [{ declNames: [], type: zigAnalysis.types[pkg.main], }]; while (stack.length !== 0) { var item = stack.shift(); if (item.type.pubDecls != null) { for (var declI = 0; declI < item.type.pubDecls.length; declI += 1) { var mainDeclIndex = item.type.pubDecls[declI]; if (list[mainDeclIndex] != null) continue; var decl = zigAnalysis.decls[mainDeclIndex]; if (decl.type === typeTypeId && declCanRepresentTypeKind(zigAnalysis.types[decl.value].kind)) { canonTypeDecls[decl.value] = mainDeclIndex; } var declNames = item.declNames.concat([decl.name]); list[mainDeclIndex] = { pkgNames: pkgNames, declNames: declNames, }; var containerType = getDeclContainerType(decl); if (containerType != null) { stack.push({ declNames: declNames, type: containerType, }); } } } } } return list; } function getCanonDeclPath(index) { if (canonDeclPaths == null) { canonDeclPaths = computeCanonDeclPaths(); } return canonDeclPaths[index]; } function getCanonTypeDecl(index) { getCanonDeclPath(0); return canonTypeDecls[index]; } function escapeHtml(text) { return text.replace(/[&"<>]/g, function (m) { return escapeHtmlReplacements[m]; }); } function shortDescMarkdown(docs) { var parts = docs.trim().split("\n"); var firstLine = parts[0]; return markdown(firstLine); } function markdown(input) { const raw_lines = input.split('\n'); // zig allows no '\r', so we don't need to split on CR const lines = []; // PHASE 1: // Dissect lines and determine the type for each line. // Also computes indentation level and removes unnecessary whitespace var is_reading_code = false; var code_indent = 0; for (var line_no = 0; line_no < raw_lines.length; line_no++) { const raw_line = raw_lines[line_no]; const line = { indent: 0, raw_text: raw_line, text: raw_line.trim(), type: "p", // p, h1 … h6, code, ul, ol, blockquote, skip, empty }; if (!is_reading_code) { while ((line.indent < line.raw_text.length) && line.raw_text[line.indent] == ' ') { line.indent += 1; } if (line.text.startsWith("######")) { line.type = "h6"; line.text = line.text.substr(6); } else if (line.text.startsWith("#####")) { line.type = "h5"; line.text = line.text.substr(5); } else if (line.text.startsWith("####")) { line.type = "h4"; line.text = line.text.substr(4); } else if (line.text.startsWith("###")) { line.type = "h3"; line.text = line.text.substr(3); } else if (line.text.startsWith("##")) { line.type = "h2"; line.text = line.text.substr(2); } else if (line.text.startsWith("#")) { line.type = "h1"; line.text = line.text.substr(1); } else if (line.text.startsWith("-")) { line.type = "ul"; line.text = line.text.substr(1); } else if (line.text.match(/^\d+\..*$/)) { // if line starts with {number}{dot} const match = line.text.match(/(\d+)\./); line.type = "ul"; line.text = line.text.substr(match[0].length); line.ordered_number = Number(match[1].length); } else if (line.text == "```") { line.type = "skip"; is_reading_code = true; code_indent = line.indent; } else if (line.text == "") { line.type = "empty"; } } else { if (line.text == "```") { is_reading_code = false; line.type = "skip"; } else { line.type = "code"; line.text = line.raw_text.substr(code_indent); // remove the indent of the ``` from all the code block } } if (line.type != "skip") { lines.push(line); } } // PHASE 2: // Render HTML from markdown lines. // Look at each line and emit fitting HTML code function markdownInlines(innerText, stopChar) { // inline types: // **{INLINE}** : <strong> // __{INLINE}__ : <u> // ~~{INLINE}~~ : <s> // *{INLINE}* : <emph> // _{INLINE}_ : <emph> // `{TEXT}` : <code> // [{INLINE}]({URL}) : <a> // ![{TEXT}]({URL}) : <img> // [[std;format.fmt]] : <a> (inner link) const formats = [ { marker: "**", tag: "strong", }, { marker: "~~", tag: "s", }, { marker: "__", tag: "u", }, { marker: "*", tag: "em", } ]; // Links, images and inner links don't use the same marker to wrap their content. const linksFormat = [ { prefix: "[", regex: /\[([^\]]*)\]\(([^\)]*)\)/, urlIndex: 2, // Index in the match that contains the link URL textIndex: 1 // Index in the match that contains the link text }, { prefix: "h", regex: /http[s]?:\/\/[^\s]+/, urlIndex: 0, textIndex: 0 } ]; const stack = []; var innerHTML = ""; var currentRun = ""; function flushRun() { if (currentRun != "") { innerHTML += escapeHtml(currentRun); } currentRun = ""; } var parsing_code = false; var codetag = ""; var in_code = false; for (var i = 0; i < innerText.length; i++) { if (parsing_code && in_code) { if (innerText.substr(i, codetag.length) == codetag) { // remove leading and trailing whitespace if string both starts and ends with one. if (currentRun[0] == " " && currentRun[currentRun.length - 1] == " ") { currentRun = currentRun.substr(1, currentRun.length - 2); } flushRun(); i += codetag.length - 1; in_code = false; parsing_code = false; innerHTML += "</code>"; codetag = ""; } else { currentRun += innerText[i]; } continue; } if (innerText[i] == "`") { flushRun(); if (!parsing_code) { innerHTML += "<code>"; } parsing_code = true; codetag += "`"; continue; } if (parsing_code) { currentRun += innerText[i]; in_code = true; } else { var foundMatches = false; for (var j = 0; j < linksFormat.length; j++) { const linkFmt = linksFormat[j]; if (linkFmt.prefix == innerText[i]) { var remaining = innerText.substring(i); var matches = remaining.match(linkFmt.regex); if (matches) { flushRun(); innerHTML += ' <a href="' + matches[linkFmt.urlIndex] + '">' + matches[linkFmt.textIndex] + '</a> '; i += matches[0].length; // Skip the fragment we just consumed foundMatches = true; break; } } } if (foundMatches) { continue; } var any = false; for (var idx = (stack.length > 0 ? -1 : 0); idx < formats.length; idx++) { const fmt = idx >= 0 ? formats[idx] : stack[stack.length - 1]; if (innerText.substr(i, fmt.marker.length) == fmt.marker) { flushRun(); if (stack[stack.length - 1] == fmt) { stack.pop(); innerHTML += "</" + fmt.tag + ">"; } else { stack.push(fmt); innerHTML += "<" + fmt.tag + ">"; } i += fmt.marker.length - 1; any = true; break; } } if (!any) { currentRun += innerText[i]; } } } flushRun(); while (stack.length > 0) { const fmt = stack.pop(); innerHTML += "</" + fmt.tag + ">"; } return innerHTML; } var html = ""; for (var line_no = 0; line_no < lines.length; line_no++) { const line = lines[line_no]; function previousLineIs(type) { if (line_no > 0) { return (lines[line_no - 1].type == type); } else { return false; } } function nextLineIs(type) { if (line_no < (lines.length - 1)) { return (lines[line_no + 1].type == type); } else { return false; } } function getPreviousLineIndent() { if (line_no > 0) { return lines[line_no - 1].indent; } else { return 0; } } function getNextLineIndent() { if (line_no < (lines.length - 1)) { return lines[line_no + 1].indent; } else { return 0; } } switch (line.type) { case "h1": case "h2": case "h3": case "h4": case "h5": case "h6": html += "<" + line.type + ">" + markdownInlines(line.text) + "</" + line.type + ">\n"; break; case "ul": case "ol": if (!previousLineIs("ul") || getPreviousLineIndent() < line.indent) { html += "<" + line.type + ">\n"; } html += "<li>" + markdownInlines(line.text) + "</li>\n"; if (!nextLineIs("ul") || getNextLineIndent() < line.indent) { html += "</" + line.type + ">\n"; } break; case "p": if (!previousLineIs("p")) { html += "<p>\n"; } html += markdownInlines(line.text) + "\n"; if (!nextLineIs("p")) { html += "</p>\n"; } break; case "code": if (!previousLineIs("code")) { html += "<pre><code>"; } html += escapeHtml(line.text) + "\n"; if (!nextLineIs("code")) { html += "</code></pre>\n"; } break; } } return html; } function activateSelectedResult() { if (domSectSearchResults.classList.contains("hidden")) { return; } var liDom = domListSearchResults.children[curSearchIndex]; if (liDom == null && domListSearchResults.children.length !== 0) { liDom = domListSearchResults.children[0]; } if (liDom != null) { var aDom = liDom.children[0]; location.href = aDom.getAttribute("href"); curSearchIndex = -1; } domSearch.blur(); } function onSearchKeyDown(ev) { switch (getKeyString(ev)) { case "Enter": // detect if this search changes anything var terms1 = getSearchTerms(); startSearch(); updateCurNav(); var terms2 = getSearchTerms(); // we might have to wait for onHashChange to trigger imFeelingLucky = (terms1.join(' ') !== terms2.join(' ')); if (!imFeelingLucky) activateSelectedResult(); ev.preventDefault(); ev.stopPropagation(); return; case "Esc": domSearch.value = ""; domSearch.blur(); curSearchIndex = -1; ev.preventDefault(); ev.stopPropagation(); startSearch(); return; case "Up": moveSearchCursor(-1); ev.preventDefault(); ev.stopPropagation(); return; case "Down": moveSearchCursor(1); ev.preventDefault(); ev.stopPropagation(); return; default: if (ev.shiftKey || ev.ctrlKey || ev.altKey) return; curSearchIndex = -1; ev.stopPropagation(); startAsyncSearch(); return; } } function moveSearchCursor(dir) { if (curSearchIndex < 0 || curSearchIndex >= domListSearchResults.children.length) { if (dir > 0) { curSearchIndex = -1 + dir; } else if (dir < 0) { curSearchIndex = domListSearchResults.children.length + dir; } } else { curSearchIndex += dir; } if (curSearchIndex < 0) { curSearchIndex = 0; } if (curSearchIndex >= domListSearchResults.children.length) { curSearchIndex = domListSearchResults.children.length - 1; } renderSearchCursor(); } function getKeyString(ev) { var name; var ignoreShift = false; switch (ev.which) { case 13: name = "Enter"; break; case 27: name = "Esc"; break; case 38: name = "Up"; break; case 40: name = "Down"; break; default: ignoreShift = true; name = (ev.key != null) ? ev.key : String.fromCharCode(ev.charCode || ev.keyCode); } if (!ignoreShift && ev.shiftKey) name = "Shift+" + name; if (ev.altKey) name = "Alt+" + name; if (ev.ctrlKey) name = "Ctrl+" + name; return name; } function onWindowKeyDown(ev) { switch (getKeyString(ev)) { case "Esc": if (!domHelpModal.classList.contains("hidden")) { domHelpModal.classList.add("hidden"); ev.preventDefault(); ev.stopPropagation(); } break; case "s": domSearch.focus(); domSearch.select(); ev.preventDefault(); ev.stopPropagation(); startAsyncSearch(); break; case "?": ev.preventDefault(); ev.stopPropagation(); showHelpModal(); break; } } function showHelpModal() { domHelpModal.classList.remove("hidden"); domHelpModal.style.left = (window.innerWidth / 2 - domHelpModal.clientWidth / 2) + "px"; domHelpModal.style.top = (window.innerHeight / 2 - domHelpModal.clientHeight / 2) + "px"; domHelpModal.focus(); } function onClickSearchShowAllResults(ev) { ev.preventDefault(); ev.stopPropagation(); searchTrimResults = false; onHashChange(); } function clearAsyncSearch() { if (searchTimer != null) { clearTimeout(searchTimer); searchTimer = null; } } function startAsyncSearch() { clearAsyncSearch(); searchTrimResults = true; searchTimer = setTimeout(startSearch, 10); } function startSearch() { clearAsyncSearch(); var oldHash = location.hash; var parts = oldHash.split("?"); var newPart2 = (domSearch.value === "") ? "" : ("?" + domSearch.value); location.hash = (parts.length === 1) ? (oldHash + newPart2) : (parts[0] + newPart2); } function getSearchTerms() { var list = curNavSearch.trim().split(/[ \r\n\t]+/); list.sort(); return list; } function renderSearch() { var matchedItems = []; var ignoreCase = (curNavSearch.toLowerCase() === curNavSearch); var terms = getSearchTerms(); decl_loop: for (var declIndex = 0; declIndex < zigAnalysis.decls.length; declIndex += 1) { var canonPath = getCanonDeclPath(declIndex); if (canonPath == null) continue; var decl = zigAnalysis.decls[declIndex]; var lastPkgName = canonPath.pkgNames[canonPath.pkgNames.length - 1]; var fullPathSearchText = lastPkgName + "." + canonPath.declNames.join('.'); var astNode = zigAnalysis.astNodes[decl.src]; var fileAndDocs = zigAnalysis.files[astNode.file]; if (astNode.docs != null) { fileAndDocs += "\n" + astNode.docs; } var fullPathSearchTextLower = fullPathSearchText; if (ignoreCase) { fullPathSearchTextLower = fullPathSearchTextLower.toLowerCase(); fileAndDocs = fileAndDocs.toLowerCase(); } var points = 0; for (var termIndex = 0; termIndex < terms.length; termIndex += 1) { var term = terms[termIndex]; // exact, case sensitive match of full decl path if (fullPathSearchText === term) { points += 4; continue; } // exact, case sensitive match of just decl name if (decl.name == term) { points += 3; continue; } // substring, case insensitive match of full decl path if (fullPathSearchTextLower.indexOf(term) >= 0) { points += 2; continue; } if (fileAndDocs.indexOf(term) >= 0) { points += 1; continue; } continue decl_loop; } matchedItems.push({ decl: decl, path: canonPath, points: points, }); } if (matchedItems.length !== 0) { matchedItems.sort(function(a, b) { var cmp = operatorCompare(b.points, a.points); if (cmp != 0) return cmp; return operatorCompare(a.decl.name, b.decl.name); }); var searchTrimmed = false var searchTrimResultsMaxItems = 200 if (searchTrimResults && matchedItems.length > searchTrimResultsMaxItems) { matchedItems = matchedItems.slice(0, searchTrimResultsMaxItems) searchTrimmed = true } var domListSearchResultsFragment = createDomListFragment(matchedItems.length, '<li><a href="#"></a></li>'); for (var i = 0; i < matchedItems.length; i += 1) { var liDom = domListSearchResultsFragment.children[i]; var aDom = liDom.children[0]; var match = matchedItems[i]; var lastPkgName = match.path.pkgNames[match.path.pkgNames.length - 1]; aDom.textContent = lastPkgName + "." + match.path.declNames.join('.'); aDom.setAttribute('href', navLink(match.path.pkgNames, match.path.declNames)); } domListSearchResults.innerHTML = ""; domListSearchResults.appendChild(domListSearchResultsFragment); domSectSearchResults.classList.remove("hidden"); if (searchTrimmed) { domSectSearchAllResultsLink.classList.remove("hidden"); } renderSearchCursor(); } else { domSectSearchNoResults.classList.remove("hidden"); } } function renderSearchCursor() { for (var i = 0; i < domListSearchResults.children.length; i += 1) { var liDom = domListSearchResults.children[i]; if (curSearchIndex === i) { liDom.classList.add("selected"); } else { liDom.classList.remove("selected"); } } } function indexNodesToFns() { var map = {}; for (var i = 0; i < zigAnalysis.fns.length; i += 1) { var fn = zigAnalysis.fns[i]; if (typeIsGenericFn(fn.type)) continue; if (map[fn.src] == null) { map[fn.src] = [i]; } else { map[fn.src].push(i); } } return map; } function indexNodesToCalls() { var map = {}; for (var i = 0; i < zigAnalysis.calls.length; i += 1) { var call = zigAnalysis.calls[i]; var fn = zigAnalysis.fns[call.fn]; if (map[fn.src] == null) { map[fn.src] = [i]; } else { map[fn.src].push(i); } } return map; } function byNameProperty(a, b) { return operatorCompare(a.name, b.name); } function clone(obj) { var res = {}; for (var key in obj) { res[key] = obj[key]; } return res; } function firstObjectKey(obj) { for (var key in obj) { return key; } } function token(value, tokenClass, wantHtml){ if(wantHtml){ return '<span class="' + tokenClass + '">' + value + '</span>'; } else { return value + ''; } } })();
0
repos/zee_alloc
repos/zee_alloc/docs/index.html
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Documentation - Zig</title> <link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAgklEQVR4AWMYWuD7EllJIM4G4g4g5oIJ/odhOJ8wToOxSTXgNxDHoeiBMfA4+wGShjyYOCkG/IGqWQziEzYAoUAeiF9D5U+DxEg14DRU7jWIT5IBIOdCxf+A+CQZAAoopEB7QJwBCBwHiip8UYmRdrAlDpIMgApwQZNnNii5Dq0MBgCxxycBnwEd+wAAAABJRU5ErkJggg=="> <style> :root { font-size: 1em; --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; --mono: "Source Code Pro", monospace; --tx-color: #141414; --bg-color: #ffffff; --link-color: #2A6286; --sidebar-sh-color: rgba(0, 0, 0, 0.09); --sidebar-pkg-bg-color: #f1f1f1; --sidebar-pkglnk-tx-color: #141414; --sidebar-pkglnk-tx-color-hover: #fff; --sidebar-pkglnk-tx-color-active: #000; --sidebar-pkglnk-bg-color: transparent; --sidebar-pkglnk-bg-color-hover: #555; --sidebar-pkglnk-bg-color-active: #FFBB4D; --search-bg-color: #f3f3f3; --search-bg-color-focus: #ffffff; --search-sh-color: rgba(0, 0, 0, 0.18); --help-sh-color: rgba(0, 0, 0, 0.75); } html, body { margin: 0; padding:0; height: 100%; } a { text-decoration: none; } a:hover { text-decoration: underline; } .hidden { display: none; } /* layout */ .canvas { width: 100vw; height: 100vh; overflow: hidden; margin: 0; padding: 0; font-family: var(--ui); color: var(--tx-color); background-color: var(--bg-color); } .flex-main { display: flex; width: 100%; height: 100%; justify-content: center; z-index: 100; } .flex-filler { flex-grow: 1; flex-shrink: 1; } .flex-left { width: 12rem; max-width: 15vw; min-width: 9.5rem; overflow: auto; -webkit-overflow-scrolling: touch; overflow-wrap: break-word; flex-shrink: 0; flex-grow: 0; z-index: 300; } .flex-right { display: flex; overflow: auto; -webkit-overflow-scrolling: touch; flex-grow: 1; flex-shrink: 1; z-index: 200; } .flex-right > .wrap { width: 60rem; max-width: 85vw; flex-shrink: 1; } .help-modal { z-index: 400; } /* sidebar */ .sidebar { font-size: 1rem; background-color: var(--bg-color); box-shadow: 0 0 1rem var(--sidebar-sh-color); } .sidebar .logo { padding: 1rem 0.35rem 0.35rem 0.35rem; } .sidebar .logo > svg { display: block; overflow: visible; } .sidebar h2 { margin: 0.5rem; padding: 0; font-size: 1.2rem; } .sidebar h2 > span { border-bottom: 0.125rem dotted var(--tx-color); } .sidebar .packages { list-style-type: none; margin: 0; padding: 0; background-color: var(--sidebar-pkg-bg-color); } .sidebar .packages > li > a { display: block; padding: 0.5rem 1rem; color: var(--sidebar-pkglnk-tx-color); background-color: var(--sidebar-pkglnk-bg-color); text-decoration: none; } .sidebar .packages > li > a:hover { color: var(--sidebar-pkglnk-tx-color-hover); background-color: var(--sidebar-pkglnk-bg-color-hover); } .sidebar .packages > li > a.active { color: var(--sidebar-pkglnk-tx-color-active); background-color: var(--sidebar-pkglnk-bg-color-active); } .sidebar p.str { margin: 0.5rem; font-family: var(--mono); } /* docs section */ .docs { padding: 1rem 0.7rem 2.4rem 1.4rem; font-size: 1rem; background-color: var(--bg-color); overflow-wrap: break-word; } .docs .search { width: 100%; margin-bottom: 0.8rem; padding: 0.5rem; font-size: 1rem; font-family: var(--ui); color: var(--tx-color); background-color: var(--search-bg-color); border-top: 0; border-left: 0; border-right: 0; border-bottom-width: 0.125rem; border-bottom-style: solid; border-bottom-color: var(--tx-color); outline: none; transition: border-bottom-color 0.35s, background 0.35s, box-shadow 0.35s; border-radius: 0; -webkit-appearance: none; } .docs .search:focus { background-color: var(--search-bg-color-focus); border-bottom-color: #ffbb4d; box-shadow: 0 0.3em 1em 0.125em var(--search-sh-color); } .docs .search::placeholder { font-size: 1rem; font-family: var(--ui); color: var(--tx-color); opacity: 0.5; } .docs a { color: var(--link-color); } .docs p { margin: 0.8rem 0; } .docs pre { font-family: var(--mono); font-size:1em; background-color:#F5F5F5; padding:1em; overflow-x: auto; } .docs code { font-family: var(--mono); font-size: 1em; } .docs h1 { font-size: 1.4em; margin: 0.8em 0; padding: 0; border-bottom: 0.0625rem dashed; } .docs h2 { font-size: 1.3em; margin: 0.5em 0; padding: 0; border-bottom: 0.0625rem solid; } #listNav { list-style-type: none; margin: 0; padding: 0; overflow: hidden; background-color: #f1f1f1; } #listNav li { float:left; } #listNav li a { display: block; color: #000; text-align: center; padding: .5em .8em; text-decoration: none; } #listNav li a:hover { background-color: #555; color: #fff; } #listNav li a.active { background-color: #FFBB4D; color: #000; } #listSearchResults li.selected { background-color: #93e196; } #tableFnErrors dt { font-weight: bold; } .examples { list-style-type: none; margin: 0; padding: 0; } .examples li { padding: 0.5em 0; white-space: nowrap; overflow-x: auto; } .docs td { margin: 0; padding: 0.5em; max-width: 27em; text-overflow: ellipsis; overflow-x: hidden; } /* help dialog */ .help-modal { display: flex; width: 100%; height: 100%; position: fixed; top: 0; left: 0; justify-content: center; align-items: center; background-color: rgba(0, 0, 0, 0.15); backdrop-filter: blur(0.3em); } .help-modal > .dialog { max-width: 97vw; max-height: 97vh; overflow: auto; font-size: 1rem; color: #fff; background-color: #333; border: 0.125rem solid #000; box-shadow: 0 0.5rem 2.5rem 0.3rem var(--help-sh-color); } .help-modal h1 { margin: 0.75em 2.5em 1em 2.5em; font-size: 1.5em; text-align: center; } .help-modal dt, .help-modal dd { display: inline; margin: 0 0.2em; } .help-modal dl { margin-left: 0.5em; margin-right: 0.5em; } .help-modal kbd { display: inline-block; padding: 0.3em 0.2em; font-size: 1.2em; font-size: var(--mono); line-height: 0.8em; vertical-align: middle; color: #000; background-color: #fafbfc; border-color: #d1d5da; border-bottom-color: #c6cbd1; border: solid 0.0625em; border-radius: 0.1875em; box-shadow: inset 0 -0.0625em 0 #c6cbd1; cursor: default; } /* tokens */ .tok-kw { color: #333; font-weight: bold; } .tok-str { color: #d14; } .tok-builtin { color: #0086b3; } .tok-comment { color: #777; font-style: italic; } .tok-fn { color: #900; font-weight: bold; } .tok-null { color: #008080; } .tok-number { color: #008080; } .tok-type { color: #458; font-weight: bold; } /* dark mode */ @media (prefers-color-scheme: dark) { :root { --tx-color: #bbb; --bg-color: #111; --link-color: #88f; --sidebar-sh-color: rgba(128, 128, 128, 0.09); --sidebar-pkg-bg-color: #333; --sidebar-pkglnk-tx-color: #fff; --sidebar-pkglnk-tx-color-hover: #fff; --sidebar-pkglnk-tx-color-active: #000; --sidebar-pkglnk-bg-color: transparent; --sidebar-pkglnk-bg-color-hover: #555; --sidebar-pkglnk-bg-color-active: #FFBB4D; --search-bg-color: #3c3c3c; --search-bg-color-focus: #000; --search-sh-color: rgba(255, 255, 255, 0.28); --help-sh-color: rgba(142, 142, 142, 0.5); } .docs pre { background-color:#2A2A2A; } #listNav { background-color: #333; } #listNav li a { color: #fff; } #listNav li a:hover { background-color: #555; color: #fff; } #listNav li a.active { background-color: #FFBB4D; color: #000; } #listSearchResults li.selected { background-color: #000; } #listSearchResults li.selected a { color: #fff; } .tok-kw { color: #eee; } .tok-str { color: #2e5; } .tok-builtin { color: #ff894c; } .tok-comment { color: #aa7; } .tok-fn { color: #e33; } .tok-null { color: #ff8080; } .tok-number { color: #ff8080; } .tok-type { color: #68f; } } @media only screen and (max-width: 750px) { .canvas { overflow: auto; } .flex-main { flex-direction: column; display: block; } .sidebar { min-width: calc(100vw - 2.8rem); padding-left: 1.4rem; padding-right: 1.4rem; } .logo { max-width: 6.5rem; } .flex-main > .flex-filler { display: none; } .flex-main > .flex-right > .flex-filler { display: none; } .flex-main > .flex-right > .wrap { max-width: 100vw; } .flex-main > .flex-right > .wrap > .docs { padding-right: 1.4rem; background: transparent; } .packages { display: flex; flex-wrap: wrap; } .table-container table { display: flex; flex-direction: column; } .table-container tr { display: flex; flex-direction: column; } .examples { overflow-x: scroll; -webkit-overflow-scrolling: touch; max-width: 100vw; margin-left: -1.4rem; margin-right: -1.4rem; } .examples li { width: max-content; padding-left: 1.4rem; padding-right: 1.4rem; } .mobile-scroll-container { overflow-x: scroll; -webkit-overflow-scrolling: touch; margin-left: -1.4rem; margin-right: -1.4rem; max-width: 100vw; } .mobile-scroll-container > .scroll-item { margin-left: 1.4rem; margin-right: 1.4rem; box-sizing: border-box; width: max-content; display: inline-block; min-width: calc(100% - 2.8rem); } } </style> </head> <body class="canvas"> <div class="flex-main"> <div class="flex-filler"></div> <div class="flex-left sidebar"> <nav> <div class="logo"> <svg version="1.1" viewBox="0 0 150 80" xmlns="http://www.w3.org/2000/svg"> <g fill="#f7a41d"> <path d="m0,-0.08899l0,80l19,0l6,-10l12,-10l-17,0l0,-40l15,0l0,-20l-35,0zm40,0l0,20l62,0l0,-20l-62,0zm91,0l-6,10l-12,10l17,0l0,40l-15,0l0,20l35,0l0,-80l-19,0zm-83,60l0,20l62,0l0,-20l-62,0z" shape-rendering="crispEdges"></path> <path d="m37,59.91101l-18,20l0,-15l18,-5z"></path> <path d="m113,19.91101l18,-20l0,15l-18,5z"></path> <path d="m96.98,0.54101l36.28,-10.4l-80.29,89.17l-36.28,10.4l80.29,-89.17z"></path> </g> </svg> </div> <div id="sectPkgs" class="hidden"> <h2><span>Packages</span></h2> <ul id="listPkgs" class="packages"></ul> </div> <div id="sectInfo" class="hidden"> <h2><span>Zig Version</span></h2> <p class="str" id="tdZigVer"></p> <h2><span>Target</span></h2> <p class="str" id="tdTarget"></p> </div> </nav> </div> <div class="flex-right"> <div class="wrap"> <section class="docs"> <input type="search" class="search" id="search" autocomplete="off" spellcheck="false" placeholder="`s` to search, `?` to see more options"> <p id="status">Loading...</p> <div id="sectNav" class="hidden"><ul id="listNav"></ul></div> <div id="fnProto" class="hidden"> <div class="mobile-scroll-container"><pre id="fnProtoCode" class="scroll-item"></pre></div> </div> <h1 id="hdrName" class="hidden"></h1> <div id="fnNoExamples" class="hidden"> <p>This function is not tested or referenced.</p> </div> <div id="declNoRef" class="hidden"> <p> This declaration is not tested or referenced, and it has therefore not been included in semantic analysis, which means the only documentation available is whatever is in the doc comments. </p> </div> <div id="tldDocs" class="hidden"></div> <div id="sectParams" class="hidden"> <h2>Parameters</h2> <div id="listParams"></div> </div> <div id="sectFnErrors" class="hidden"> <h2>Errors</h2> <div id="fnErrorsAnyError"> <p><span class="tok-type">anyerror</span> means the error set is known only at runtime.</p> </div> <div id="tableFnErrors"><dl id="listFnErrors"></dl></div> </div> <div id="sectSearchResults" class="hidden"> <h2>Search Results</h2> <ul id="listSearchResults"></ul> <p id="sectSearchAllResultsLink" class="hidden"><a href="">show all results</a></p> </div> <div id="sectSearchNoResults" class="hidden"> <h2>No Results Found</h2> <p>Press escape to exit search and then '?' to see more options.</p> </div> <div id="sectFields" class="hidden"> <h2>Fields</h2> <div id="listFields"></div> </div> <div id="sectTypes" class="hidden"> <h2>Types</h2> <ul id="listTypes"></ul> </div> <div id="sectNamespaces" class="hidden"> <h2>Namespaces</h2> <ul id="listNamespaces"></ul> </div> <div id="sectGlobalVars" class="hidden"> <h2>Global Variables</h2> <div class="table-container"> <table> <tbody id="listGlobalVars"></tbody> </table> </div> </div> <div id="sectFns" class="hidden"> <h2>Functions</h2> <div class="table-container"> <table> <tbody id="listFns"></tbody> </table> </div> </div> <div id="sectValues" class="hidden"> <h2>Values</h2> <div class="table-container"> <table> <tbody id="listValues"></tbody> </table> </div> </div> <div id="sectErrSets" class="hidden"> <h2>Error Sets</h2> <ul id="listErrSets"></ul> </div> <div id="fnExamples" class="hidden"> <h2>Examples</h2> <ul id="listFnExamples" class="examples"></ul> </div> </section> </div> <div class="flex-filler"></div> </div> </div> <div id="helpDialog" class="hidden"> <div class="help-modal"> <div class="dialog"> <h1>Keyboard Shortcuts</h1> <dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd></dl> <dl><dt><kbd>Esc</kbd></dt><dd>Clear focus; close this dialog</dd></dl> <dl><dt><kbd>s</kbd></dt><dd>Focus the search field</dd></dl> <dl><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd></dl> <dl><dt><kbd>↓</kbd></dt><dd>Move down in search results</dd></dl> <dl><dt><kbd>⏎</kbd></dt><dd>Go to active search result</dd></dl> </div> </div> </div> <script src="data.js"></script> <script src="main.js"></script> </body> </html>
0
repos
repos/zig-netip/README.md
# zig-netip This is mostly an educational project to implement a library similar to go's [netip](https://pkg.go.dev/net/netip) using zig idioms and comptime features. The library targets the latest stable release which is currently `0.13`. # Definitions * `Ip4Addr`, `Ip6Addr`, `Ip6AddrScoped` (and an `Addr` union) address types that're small value types. They can be converted to `std.net.Ip4Address` or `std.net.Ip6Address`. All types have a bunch of comptime friendly methods, e.g. `parse`, `get`, `toArray`, and flexible-ish `format` specifiers. * `Ip4Prefix`, `Ip6Prefix` (and a `Prefix` union) address types that're built on top of `Ip4Addr` and `Ip6Addr` abstractions. # Examples Check [the netip tests](../main/src/netip.zig) for more. ```zig test "Addr Example" { // ipv4 create const v4_addr1 = comptime try Ip4Addr.parse("192.0.2.1"); const v4_addr2 = try Addr.parse("192.0.2.1"); const v4_addr3 = Ip4Addr.fromArray(u8, [_]u8{ 192, 0, 2, 2 }); const v4_addr4 = Ip4Addr.fromArray(u16, [_]u16{ 0xC000, 0x0202 }); const v4_addr5 = Addr.init4(Ip4Addr.init(0xC0000203)); const v4_addr6 = Ip4Addr.fromNetAddress(try std.net.Ip4Address.parse("192.0.2.3", 1)); // ipv6 create const v6_addr1 = comptime try Ip6Addr.parse("2001:db8::1"); const v6_addr2 = try Addr.parse("2001:db8::1"); const v6_addr3 = Ip6Addr.fromArray(u8, [_]u8{ 0x20, 0x1, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2 }); const v6_addr4 = Ip6Addr.fromArray(u16, [_]u16{ 0x2001, 0xdb8, 0, 0, 0, 0, 0, 0x2 }); const v6_addr5 = Addr.init6(Ip6Addr.init(0x2001_0db8_0000_0000_0000_0000_0000_0003)); const v6_addr6 = Ip6Addr.fromNetAddress(try std.net.Ip6Address.parse("2001:db8::3", 1)); // ipv6 scoped const v6_scoped1 = comptime try Ip6AddrScoped.parse("2001:db8::1%eth2"); const v6_scoped2 = try Addr.parse("2001:db8::2%4"); // handle parsing errors try testing.expect(Ip4Addr.parse("-=_=-") == Ip4Addr.ParseError.InvalidCharacter); try testing.expect(Addr.parse("0.-=_=-") == Addr.ParseError.InvalidCharacter); try testing.expect(Ip6Addr.parse("-=_=-") == Ip6Addr.ParseError.InvalidCharacter); try testing.expect(Addr.parse("::-=_=-") == Addr.ParseError.InvalidCharacter); // copy const v4_addr7 = v4_addr5; const v6_addr8 = v6_addr3; _ = .{v4_addr7, v4_addr4, v4_addr6, v6_scoped1, v6_scoped2, v6_addr4, v6_addr6}; // compare via values try testing.expectEqual(math.Order.eq, order(v4_addr1, v4_addr2.v4)); try testing.expectEqual(math.Order.lt, order(v6_addr1, v6_addr8)); try testing.expectEqual(math.Order.gt, order(v6_addr8, v6_addr1)); try testing.expectEqual(math.Order.gt, order(v6_addr2, v4_addr2)); // cross AF comparison // print try testing.expectFmt("192.0.2.1", "{}", .{v4_addr1}); try testing.expectFmt("c0.00.02.02", "{X}", .{v4_addr3}); try testing.expectFmt("11000000.0.10.11", "{b}", .{v4_addr5}); try testing.expectFmt("2001:db8::1", "{}", .{v6_addr1}); try testing.expectFmt("2001:db8:0:0:0:0:0:2", "{xE}", .{v6_addr3}); try testing.expectFmt("2001:0db8::0003", "{X}", .{v6_addr5}); try testing.expectFmt("2001:0db8:0000:0000:0000:0000:0000:0001", "{XE}", .{v6_addr2}); } test "Prefix Example" { // create a ipv6 prefix const v6_prefix1 = try Ip6Prefix.init(try Ip6Addr.parse("2001:db8:85a3::1"), 48); const v6_prefix2 = try Prefix.parse("2001:db8:85a3::/48"); // create a prefix const v4_prefix1 = try Ip4Prefix.init(try Ip4Addr.parse("192.0.2.1"), 24); const v4_prefix2 = try Prefix.parse("192.0.2.1/24"); // compare mask bits try testing.expectEqual(v6_prefix1.maskBits(), v6_prefix2.v6.maskBits()); try testing.expectEqual(v4_prefix1.maskBits(), v4_prefix2.v4.maskBits()); // handle parsing errors try testing.expectError(Prefix.ParseError.Overflow, Prefix.parse("2001:db8::/256")); try testing.expectError(Prefix.ParseError.Overflow, Prefix.parse("1.1.1.1/33")); // print try testing.expectFmt("2001:db8:85a3::1/48", "{}", .{v6_prefix1}); try testing.expectFmt("2001:0db8:85a3::0001/48", "{X}", .{v6_prefix1}); try testing.expectFmt("2001:db8:85a3::-2001:db8:85a3:ffff:ffff:ffff:ffff:ffff", "{R}", .{v6_prefix1}); try testing.expectFmt("192.0.2.0/24", "{}", .{v4_prefix1.canonical()}); try testing.expectFmt("192.0.2.0-192.0.2.255", "{R}", .{v4_prefix1}); // contains address try testing.expect(v6_prefix2.containsAddr(try Addr.parse("2001:db8:85a3:cafe::efac"))); try testing.expect(v4_prefix2.containsAddr(try Addr.parse("192.0.2.42"))); // inclusion and overlap test try testing.expectEqual(PrefixInclusion.sub, v6_prefix1.testInclusion(try Ip6Prefix.parse("2001:db8::/32"))); try testing.expect(v6_prefix2.overlaps(try Prefix.parse("2001:db8::/32"))); try testing.expectEqual(PrefixInclusion.sub, v4_prefix1.testInclusion(try Ip4Prefix.parse("192.0.2.0/16"))); try testing.expect(v4_prefix2.overlaps(try Prefix.parse("192.0.2.0/16"))); } ```
0
repos
repos/zig-netip/build.zig.zon
.{ .name = "zig-netip", .version = "0.0.1", .paths = .{ "src/netip.zig", "src/addr.zig", "src/prefix.zig", "build.zig", "build.zig.zon", }, }
0
repos
repos/zig-netip/build.zig
const std = @import("std"); pub fn build(b: *std.Build) !void { // Standard target options allows the person running `zig build` to choose // what target to build for. Here we do not override the defaults, which // means any target is allowed, and the default is native. Other options // for restricting supported target set are available. const target = b.standardTargetOptions(.{}); // Standard optimization options allow the person running `zig build` to select // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not // set a preferred release mode, allowing the user to decide how to optimize. const optimize = b.standardOptimizeOption(.{}); const lib = b.addStaticLibrary(.{ .name = "netip", .root_source_file = b.path("src/netip.zig"), .target = target, .optimize = optimize, }); // This declares intent for the library to be installed into the standard // location when the user invokes the "install" step (the default step when // running `zig build`). b.installArtifact(lib); // Register a module so it can be referenced using the package manager. const netip_module = b.createModule(.{ .root_source_file = b.path("src/netip.zig"), }); try b.modules.put(b.dupe("netip"), netip_module); // Creates a step for unit testing. This only builds the test executable // but does not run it. const main_tests = b.addTest(.{ .root_source_file = b.path("src/netip.zig"), .target = target, .optimize = optimize, }); const run_main_tests = b.addRunArtifact(main_tests); // This creates a build step. It will be visible in the `zig build --help` menu, // and can be selected like this: `zig build test` // This will evaluate the `test` step rather than the default, which is "install". const test_step = b.step("test", "Run library tests"); test_step.dependOn(&run_main_tests.step); }
0
repos/zig-netip
repos/zig-netip/src/addr.zig
const std = @import("std"); const assert = std.debug.assert; const math = std.math; const mem = std.mem; const net = std.net; const posix = std.posix; const testing = std.testing; // common address format options const FormatMode = struct { fmt: []const u8, expand: bool, }; fn invalidFmtErr(comptime fmt: []const u8, comptime value: type) void { @compileError("invalid format string '" ++ fmt ++ "' for type '" ++ @typeName(value) ++ "'"); } // ipv4 mixin functions and constants const ip4 = struct { const BaseType = u32; const StdlibType = net.Ip4Address; const ParseElementType = u8; const PrintElementType = u8; const ParseError = error{ InvalidCharacter, LeadingZero, EmptyOctet, TooManyOctets, NotEnoughOctets, Overflow, }; inline fn convertToStdlibAddress(v: [@sizeOf(BaseType)]u8, port: u16) StdlibType { return StdlibType.init(v, port); } inline fn parse(s: []const u8) ParseError![@sizeOf(BaseType) / @sizeOf(ParseElementType)]ParseElementType { var octs: [4]u8 = [_]u8{0} ** 4; var len: u8 = 0; var ix: u8 = 0; for (s, 0..) |c, i| { switch (c) { '0'...'9' => { if (octs[ix] == 0 and len > 0) { return ParseError.LeadingZero; } octs[ix] = math.mul(u8, octs[ix], 10) catch return ParseError.Overflow; octs[ix] = math.add(u8, octs[ix], c - '0') catch return ParseError.Overflow; len += 1; }, '.' => { // dot in the wrong place if (i == 0 or i == s.len - 1 or s[i - 1] == '.') { return ParseError.EmptyOctet; } if (ix >= 3) { return ParseError.TooManyOctets; } ix += 1; len = 0; }, else => return ParseError.InvalidCharacter, } } if (ix < 3) { return ParseError.NotEnoughOctets; } return octs; } inline fn format( comptime mode: FormatMode, bs: [@sizeOf(BaseType) / @sizeOf(PrintElementType)]PrintElementType, out_stream: anytype, ) !void { const blk = "{" ++ mode.fmt ++ "}"; const fmt_expr = blk ++ ("." ++ blk) ** 3; try std.fmt.format(out_stream, fmt_expr, .{ bs[0], bs[1], bs[2], bs[3], }); } }; // ipv6 mixin function and constaints const ip6 = struct { const BaseType = u128; const StdlibType = std.net.Ip6Address; const ParseElementType = u16; const PrintElementType = u16; const ParseError = error{ InvalidCharacter, EmbeddedIp4InvalidLocation, EmbeddedIp4InvalidFormat, EmptySegment, MultipleEllipses, TooManySegments, NotEnoughSegments, AmbiguousEllipsis, Overflow, }; inline fn convertToStdlibAddress(v: [@sizeOf(BaseType)]u8, port: u16) StdlibType { return StdlibType.init(v, port, 0, 0); } inline fn parse(input: []const u8) ParseError![@sizeOf(BaseType) / @sizeOf(ParseElementType)]ParseElementType { // parsing strategy is almost identical to https://pkg.go.dev/net/netip var s: []const u8 = input[0..]; var addr: [8]u16 = [_]u16{0} ** 8; var ellipsis: ?usize = null; if (s.len >= 2 and s[0] == ':' and s[1] == ':') { ellipsis = 0; s = s[2..]; if (s.len == 0) { return addr; } } var filled: usize = 0; for (addr, 0..) |_, addr_i| { var chunk_end: usize = 0; var acc: u16 = 0; // parse the next segment while (chunk_end < s.len) : (chunk_end += 1) { const c = s[chunk_end]; switch (c) { '0'...'9', 'a'...'f', 'A'...'F' => { const d = switch (c) { '0'...'9' => c - '0', 'a'...'f' => c - 'a' + 10, 'A'...'F' => c - 'A' + 10, else => unreachable, }; acc = math.shlExact(u16, acc, 4) catch return ParseError.Overflow; acc += d; }, '.', ':' => break, else => return ParseError.InvalidCharacter, } } if (chunk_end == 0) { return ParseError.EmptySegment; } // check if this is an embedded v4 address if (chunk_end < s.len and s[chunk_end] == '.') { if ((ellipsis == null and addr_i != 6) or addr_i > 6) { // wrong position to insert 4 bytes of the embedded ip4 return ParseError.EmbeddedIp4InvalidLocation; } // discard the acc and parse the whole fragment as v4 const segs = ip4.parse(s[0..]) catch return ParseError.EmbeddedIp4InvalidFormat; addr[addr_i] = (@as(u16, segs[0]) << 8) | @as(u16, segs[1]); addr[addr_i + 1] = (@as(u16, segs[2]) << 8) | @as(u16, segs[3]); filled += 2; s = s[s.len..]; break; } // save the segment addr[addr_i] = acc; filled += 1; s = s[chunk_end..]; if (s.len == 0) { break; } // the following char must be ':' assert(s[0] == ':'); if (s.len == 1) { return ParseError.EmptySegment; } s = s[1..]; // check one more char in case it's ellipsis '::' if (s[0] == ':') { if (ellipsis) |_| { return ParseError.MultipleEllipses; } ellipsis = filled; s = s[1..]; if (s.len == 0) { break; } } } if (s.len != 0) { return ParseError.TooManySegments; } if (filled < addr.len) { if (ellipsis) |e| { const zs = addr.len - filled; mem.copyBackwards(u16, addr[e + zs .. addr.len], addr[e..filled]); @memset(addr[e .. e + zs], 0); } else { return ParseError.NotEnoughSegments; } } else if (ellipsis) |_| { return ParseError.AmbiguousEllipsis; } return addr; } inline fn format( comptime mode: FormatMode, segs: [@sizeOf(BaseType) / @sizeOf(PrintElementType)]PrintElementType, out_stream: anytype, ) !void { const fmt_seg = "{" ++ (if (mode.fmt.len == 0) "x" else mode.fmt) ++ "}"; var zero_start: usize = 255; var zero_end: usize = 255; var i: usize = 0; while (i < segs.len) : (i += 1) { var j = i; while (j < segs.len and segs[j] == 0) : (j += 1) {} const l = j - i; if (l > 1 and l > zero_end - zero_start) { zero_start = i; zero_end = j; } i = j; } i = 0; while (i < segs.len) : (i += 1) { if (!mode.expand and i == zero_start) { try out_stream.writeAll("::"); i = zero_end; if (i >= segs.len) { break; } } else if (i > 0) { try out_stream.writeAll(":"); } try std.fmt.format(out_stream, fmt_seg, .{segs[i]}); } } }; /// An Addr type constructor representing the IP address as a native-order integer. pub fn AddrForValue(comptime M: type) type { if (M != ip4 and M != ip6) { @compileError("unknown address mixin type '" ++ @typeName(M) ++ "' (only ip4 and ip6 are supported)"); } return packed struct { const Self = @This(); const Mixin = M; /// The internal type of the address. pub const ValueType = M.BaseType; /// The integer type that can be used in shl/shr instructions /// The type can store any bit index of the parent type. pub const PositionType = math.Log2Int(ValueType); /// The equivalent std.net Address type. pub const StdlibType = M.StdlibType; /// Parse errors enum. pub const ParseError = M.ParseError; /// The byte size of the parent type. pub const byte_size = @sizeOf(ValueType); /// Raw native-order integer value that encodes the type. v: ValueType, /// Wrap a native-order integer value into AddrValue. pub fn init(v: ValueType) Self { return Self{ .v = v }; } /// Create an AddrValue from the array of arbitrary integer values. /// Elements of the array are ordered in the network order (most-significant first). /// Each integer value has the network byte order. pub fn fromArrayNetOrder(comptime E: type, a: [byte_size / @sizeOf(E)]E) Self { const p = @as(*align(@alignOf(u8)) const [byte_size / @sizeOf(u8)]u8, @ptrCast(&a)); const v = mem.bigToNative(ValueType, mem.bytesToValue(ValueType, p)); return Self{ .v = v }; } /// Create an AddrValue from the array of arbitrary integer values. /// Elements of the array are ordered in the network order (most-significant first). /// Each integer value has the native byte order. pub fn fromArray(comptime E: type, a: [byte_size / @sizeOf(E)]E) Self { var v: ValueType = 0; inline for (a, 0..) |b, i| { v |= @as(ValueType, b) << (@bitSizeOf(E) * ((byte_size / @sizeOf(E)) - 1 - i)); } return Self{ .v = v }; } /// Create an address from the associated stdlib type. /// The conversion is lossy and the port information /// is discarded. pub fn fromNetAddress(a: StdlibType) Self { const bs = @as(*const [byte_size]u8, @ptrCast(&a.sa.addr)); return fromArrayNetOrder(u8, bs.*); } /// Parse the address from the string representation. /// The method supports only the standard representation of the /// IPv6 address WITHOUT the zone identifier. /// Use a separate type for dealing with scoped addresses. pub fn parse(input: []const u8) ParseError!Self { const res = try M.parse(input); return fromArray(M.ParseElementType, res); } /// Returns the underlying address value. pub fn value(self: Self) ValueType { return self.v; } /// Convert the AddrValue to an array of generic integer values. /// Elements of the array are ordered in the network order (most-significant first). /// Each integer value has the network byte order. pub fn toArrayNetOrder(self: Self, comptime E: type) [byte_size / @sizeOf(E)]E { var a = self.toArray(E); inline for (a, 0..) |b, i| { a[i] = mem.nativeToBig(E, b); } return a; } /// Convert the address to an array of generic integer values. /// Elemenets of the array is ordered in the network order (most-significant first). /// Each integer value has the native byte order. pub fn toArray(self: Self, comptime E: type) [byte_size / @sizeOf(E)]E { var a: [byte_size / @sizeOf(E)]E = undefined; inline for (a, 0..) |_, i| { a[i] = self.get(E, i); } return a; } /// Convert the address to the corresponding stdlib equivalent. /// Since the value doesn't carry port information, /// it must be provided as an argument. pub fn toNetAddress(self: Self, port: u16) StdlibType { return M.convertToStdlibAddress(self.toArrayNetOrder(u8), port); } /// Get an arbitrary integer value from the address. /// The value always has the native byte order. pub fn get(self: Self, comptime E: type, i: PositionType) E { return @as(E, @truncate(self.v >> (@bitSizeOf(E) * (byte_size / @sizeOf(E) - 1 - i)))); } fn formatMode(comptime fmt: []const u8) FormatMode { var mode = FormatMode{ .fmt = "", .expand = false }; var mode_set = false; inline for (fmt) |f| { switch (f) { 'E' => { if (mode.expand) invalidFmtErr(fmt, Self); mode.expand = true; }, 'x', 'X', 'b', 'B' => { if (mode_set) invalidFmtErr(fmt, Self); mode.fmt = switch (f) { 'x' => "x", // hex 'X' => "x:0>" ++ std.fmt.comptimePrint("{}", .{@sizeOf(M.PrintElementType) * 2}), // padded hex 'b' => "b", // bin 'B' => "b:0>" ++ std.fmt.comptimePrint("{}", .{@sizeOf(M.PrintElementType) * 8}), // padded bin else => unreachable, }; mode_set = true; }, else => invalidFmtErr(fmt, Self), } } return mode; } /// Print the address. A number of non-standard (e.g. non-empty) /// modifiers are supported: /// * x - will print all octets as hex numbers (that's the default for IPv6). /// * X - will do the same as 'x', but will also ensure that each value is padded. /// * b - will print all octets as binary numbers instead of base-10. /// * B - will do the same as 'b', but will also ensure that each value is padded. /// * E - will print the IPv6 address in the extended format (without ellipses '::'). /// 'E' modifier can be used with one of the other ones, e.g. like 'xE' or 'BE'. pub fn format( self: Self, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: anytype, ) !void { _ = options; try M.format(formatMode(fmt), self.toArray(M.PrintElementType), out_stream); } /// Compare two addresses. pub fn order(self: Self, other: Self) math.Order { return math.order(self.value(), other.value()); } /// Convert between IPv4 and IPv6 addresses /// Use '::ffff:0:0/96' for IPv4 mapped addresses. pub fn as(self: Self, comptime O: type) ?O { if (Self == O) { return self; } return switch (O.Mixin) { ip6 => O.init(0xffff00000000 | @as(O.ValueType, self.v)), ip4 => if (self.v >> @bitSizeOf(O.ValueType) == 0xffff) O.init(@as(O.ValueType, @truncate(self.v))) else null, else => @compileError("unsupported address conversion from '" ++ @typeName(Self) ++ "' to '" ++ @typeName(O) + "'"), }; } }; } pub const Ip4Addr = AddrForValue(ip4); pub const Ip6Addr = AddrForValue(ip6); pub const Ip6AddrScoped = struct { pub const ParseError = error{EmptyZone} || Ip6Addr.ParseError; pub const NetAddrScopeError = std.fmt.BufPrintError; pub const NoZone: []const u8 = ""; addr: Ip6Addr, zone: []const u8, // not owned, zone.len == 0 for zoneless ips /// Tie the address to the scope pub fn init(addr: Ip6Addr, zn: []const u8) Ip6AddrScoped { return Ip6AddrScoped{ .addr = addr, .zone = zn }; } /// Parse the address from the string representation. /// The method supports only the standard representation of the /// IPv6 address with or without the zone identifier. /// The returned scope (if exists) is a slice of the input (not owned). pub fn parse(input: []const u8) ParseError!Ip6AddrScoped { const b = if (mem.indexOfScalar(u8, input, '%')) |i| i else input.len; const addr = try Ip6Addr.parse(input[0..b]); return switch (input.len - b) { 0 => init(addr, input[b..]), 1 => ParseError.EmptyZone, else => init(addr, input[b + 1 ..]), }; } /// Create an address from the std.net.Ip6Address type. /// The conversion is lossy and the port information /// is discarded. /// Numeric scope_id is converted into the string (1 -> "1"). pub fn fromNetAddress(a: net.Ip6Address, buf: []u8) NetAddrScopeError!Ip6AddrScoped { const addr = Ip6Addr.fromNetAddress(a); const zone = try std.fmt.bufPrint(buf, "{}", .{a.sa.scope_id}); return init(addr, zone); } /// Convert the address to the std.net.Ip6Address type. /// Since the value doesn't carry port information, /// it must be provided as an argument. pub fn toNetAddress(self: Ip6AddrScoped, port: u16) !net.Ip6Address { var stdlib_addr = self.addr.toNetAddress(port); stdlib_addr.sa.scope_id = std.fmt.parseInt(u32, self.zone, 10) catch |err| blk: { if (err != error.InvalidCharacter) return err; break :blk try if_nametoindex(self.zone); }; return stdlib_addr; } // TODO: implement fn if_nametoindex(name: []const u8) !u32 { _ = name; return error.NotImplemented; } /// Returns true if the zone is present. pub fn hasZone(self: Ip6AddrScoped) bool { return self.zone.len > 0; } /// Print the address. pub fn format( self: Ip6AddrScoped, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: anytype, ) !void { try self.addr.format(fmt, options, out_stream); if (self.hasZone()) { try std.fmt.format(out_stream, "%{s}", .{self.zone}); } } /// Compare two addresses. pub fn order(self: Ip6AddrScoped, other: Ip6AddrScoped) math.Order { const addr_order = self.addr.order(other.addr); if (addr_order != math.Order.eq) return addr_order; return mem.order(u8, self.zone, other.zone); } }; pub const AddrType = enum { v4, v6, v6s, }; /// A union type that allows to work with both address types at the same time. /// Only high-level operations are supported. Unwrap the concrete /// prefix type to do any sort of low-level or bit operations. pub const Addr = union(AddrType) { v4: Ip4Addr, v6: Ip6Addr, v6s: Ip6AddrScoped, pub const ParseError = error{UnknownAddress} || Ip4Addr.ParseError || Ip6Addr.ParseError || Ip6AddrScoped.ParseError; pub const FromNetAddressError = error{UnsupportedAddressFamily} || Ip6AddrScoped.NetAddrScopeError; pub fn init4(a: Ip4Addr) Addr { return Addr{ .v4 = a }; } pub fn init6(a: Ip6Addr) Addr { return Addr{ .v6 = a }; } pub fn init6Scoped(a: Ip6AddrScoped) Addr { return Addr{ .v6s = a }; } /// Parse the address from the string representation pub fn parse(s: []const u8) ParseError!Addr { for (s) |c| { switch (c) { '.' => return Addr{ .v4 = try Ip4Addr.parse(s) }, ':' => { const addr_v6 = try Ip6AddrScoped.parse(s); return if (addr_v6.hasZone()) init6Scoped(addr_v6) else init6(addr_v6.addr); }, else => continue, } } return ParseError.UnknownAddress; } /// Create an Addr from the std.net.Address. /// The conversion is lossy and some information /// is discarded. /// Buf is only required for scoped IPv6 addresses. pub fn fromNetAddress(a: std.net.Address, buf: []u8) FromNetAddressError!Addr { return switch (a.any.family) { posix.AF.INET => Addr{ .v4 = Ip4Addr.fromNetAddress(a.in) }, posix.AF.INET6 => switch (a.in6.sa.scope_id) { 0 => Addr{ .v6 = Ip6Addr.fromNetAddress(a.in6) }, else => Addr{ .v6s = try Ip6AddrScoped.fromNetAddress(a.in6, buf) }, }, else => FromNetAddressError.UnsupportedAddressFamily, }; } /// Return the equivalent IPv6 address. pub fn as6(self: Addr) Addr { return switch (self) { .v4 => |a| Addr{ .v6 = a.as(Ip6Addr).? }, .v6 => self, .v6s => |a| Addr{ .v6 = a.addr }, }; } /// Return the equivalent scoped IPv6 address. pub fn as6Scoped(self: Addr, zn: []const u8) Addr { return switch (self) { .v4 => |a| Addr{ .v6s = Ip6AddrScoped.init(a.as(Ip6Addr).?, zn) }, .v6 => |a| Addr{ .v6s = Ip6AddrScoped.init(a, zn) }, .v6s => |a| Addr{ .v6s = Ip6AddrScoped.init(a.addr, zn) }, }; } /// Return the equivalent IPv4 address if it exists. pub fn as4(self: Addr) ?Addr { return switch (self) { .v4 => self, .v6 => |a| (if (a.as(Ip4Addr)) |p| Addr{ .v4 = p } else null), .v6s => |a| (if (a.addr.as(Ip4Addr)) |p| Addr{ .v4 = p } else null), }; } /// Print the address. The modifier is passed to either Ip4Addr or Ip6Addr unchanged. pub fn format( self: Addr, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: anytype, ) !void { switch (self) { .v4 => |a| try a.format(fmt, options, out_stream), .v6 => |a| try a.format(fmt, options, out_stream), .v6s => |a| try a.format(fmt, options, out_stream), } } /// Convert the address to the equivalent std.net.Address. /// Since the value doesn't carry port information, /// it must be provided as an argument. pub fn toNetAddress(self: Addr, port: u16) !std.net.Address { return switch (self) { .v4 => |a| std.net.Address{ .in = a.toNetAddress(port) }, .v6 => |a| std.net.Address{ .in6 = a.toNetAddress(port) }, .v6s => |a| std.net.Address{ .in6 = try a.toNetAddress(port) }, }; } /// Compare two addresses. IPv4 is always less than IPv6 pub fn order(self: Addr, other: Addr) math.Order { return switch (self) { .v4 => |l4| switch (other) { .v4 => |r4| l4.order(r4), .v6 => math.Order.lt, .v6s => math.Order.lt, }, .v6 => |l6| switch (other) { .v4 => math.Order.gt, .v6 => |r6| l6.order(r6), .v6s => |r6s| Ip6AddrScoped.init(l6, Ip6AddrScoped.NoZone).order(r6s), }, .v6s => |l6s| switch (other) { .v4 => math.Order.gt, .v6 => |r6| l6s.order(Ip6AddrScoped.init(r6, Ip6AddrScoped.NoZone)), .v6s => |r6s| l6s.order(r6s), }, }; } }; test "Ip6 Address/sizeOf" { try testing.expectEqual(@sizeOf(u128), @sizeOf(Ip6Addr)); } test "Ip6 Address/fromArrayX" { // 2001:db8::89ab:cdef const expected: u128 = 0x2001_0db8_0000_0000_0000_0000_89ab_cdef; const input_u8 = [16]u8{ 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0x89, 0xab, 0xcd, 0xef }; const input_u16_native = [_]u16{ 0x2001, 0x0db8, 0, 0, 0, 0, 0x89ab, 0xcdef }; const input_u16_net = [_]u16{ mem.nativeToBig(u16, 0x2001), mem.nativeToBig(u16, 0x0db8), 0, 0, 0, 0, mem.nativeToBig(u16, 0x89ab), mem.nativeToBig(u16, 0xcdef), }; try testing.expectEqual(expected, Ip6Addr.fromArrayNetOrder(u8, input_u8).value()); try testing.expectEqual(expected, Ip6Addr.fromArray(u8, input_u8).value()); try testing.expectEqual(expected, Ip6Addr.fromArrayNetOrder(u16, input_u16_net).value()); try testing.expectEqual(expected, Ip6Addr.fromArray(u16, input_u16_native).value()); } test "Ip6 Address/toArrayX" { // 2001:db8::89ab:cdef const value: u128 = 0x2001_0db8_0000_0000_0000_0000_89ab_cdef; const addr = Ip6Addr.init(value); const out_u8 = [16]u8{ 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0x89, 0xab, 0xcd, 0xef }; const out_u16_native = [_]u16{ 0x2001, 0x0db8, 0, 0, 0, 0, 0x89ab, 0xcdef }; const out_u16_net = [_]u16{ mem.nativeToBig(u16, 0x2001), mem.nativeToBig(u16, 0x0db8), 0, 0, 0, 0, mem.nativeToBig(u16, 0x89ab), mem.nativeToBig(u16, 0xcdef), }; try testing.expectEqual(out_u8, addr.toArray(u8)); try testing.expectEqual(out_u8, addr.toArrayNetOrder(u8)); try testing.expectEqual(out_u16_native, addr.toArray(u16)); try testing.expectEqual(out_u16_net, addr.toArrayNetOrder(u16)); } test "Ip6 Address/Parse" { const comp_time_one = comptime try Addr.parse("::1"); // compile time test try testing.expectEqual(@as(u128, 1), comp_time_one.v6.value()); // format tests try testing.expectEqual(Ip6Addr.init(0), (try Ip6Addr.parse("::"))); try testing.expectEqual(Ip6Addr.init(0), (try Ip6Addr.parse("0:0::0:0"))); try testing.expectEqual(Ip6Addr.init(0), (try Addr.parse("::0:0:0")).v6); try testing.expectEqual(Ip6Addr.init(0), (try Addr.parse("0:0:0::")).v6); try testing.expectEqual(Ip6Addr.init(0), (try Addr.parse("0:0:0:0::0:0:0")).v6); try testing.expectEqual(Ip6Addr.init(0), (try Addr.parse("0:0:0:0:0:0:0:0")).v6); try testing.expectEqual(Ip6Addr.init(0), (try Addr.parse("0:0:0:0:0:0:0.0.0.0")).v6); try testing.expectEqual(Ip6Addr.init(0), (try Addr.parse("::0.0.0.0")).v6); try testing.expectEqual(Ip6Addr.init(0), (try Addr.parse("0:0::0.0.0.0")).v6); // value tests try testing.expectEqual( Ip6Addr.fromArray(u16, [_]u16{ 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8 }), (try Ip6Addr.parse("1:2:3:4:5:6:7:8")), ); try testing.expectEqual( Ip6Addr.fromArray(u16, [_]u16{ 0x1, 0x2, 0x3, 0x4, 0x0, 0x6, 0x7, 0x8 }), (try Addr.parse("1:2:3:4::6:7:8")).v6, ); try testing.expectEqual( Ip6Addr.fromArray(u16, [_]u16{ 0x1, 0x2, 0x3, 0x0, 0x0, 0x6, 0x7, 0x8 }), (try Addr.parse("1:2:3::6:7:8")).v6, ); try testing.expectEqual( Ip6Addr.fromArray(u16, [_]u16{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x7, 0x8 }), (try Addr.parse("::6:7:8")).v6, ); try testing.expectEqual( Ip6Addr.fromArray(u16, [_]u16{ 0x1, 0x2, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0 }), (try Addr.parse("1:2:3::")).v6, ); try testing.expectEqual( Ip6Addr.fromArray(u16, [_]u16{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8 }), (try Addr.parse("::8")).v6, ); try testing.expectEqual( Ip6Addr.fromArray(u16, [_]u16{ 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }), (try Addr.parse("1::")).v6, ); // embedded ipv4 try testing.expectEqual( Ip6Addr.fromArray(u8, [_]u8{ 0x1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xa, 0xb, 0xc, 0xd }), (try Ip6Addr.parse("100::10.11.12.13")), ); try testing.expectEqual( Ip6Addr.fromArray(u8, [_]u8{ 0, 0x1, 0, 0x2, 0, 0x3, 0, 0x4, 0, 0x5, 0, 0x6, 0xa, 0xb, 0xc, 0xd }), (try Addr.parse("1:2:3:4:5:6:10.11.12.13")).v6, ); // larger numbers try testing.expectEqual( Ip6Addr.fromArray(u16, [_]u16{ 0x2001, 0x0db8, 0, 0, 0, 0, 0x89ab, 0xcdef }), (try Ip6Addr.parse("2001:db8::89ab:cdef")), ); try testing.expectEqual( Ip6Addr.fromArray(u16, [_]u16{ 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff }), (try Ip6Addr.parse("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")), ); // empty or ambiguous segments try testing.expectError(Addr.ParseError.EmptySegment, Addr.parse(":::")); try testing.expectError(Addr.ParseError.EmptySegment, Addr.parse(":")); try testing.expectError(Addr.ParseError.EmptySegment, Addr.parse("1:2:::4")); try testing.expectError(Addr.ParseError.EmptySegment, Addr.parse("1:2::.1.2.3")); try testing.expectError(Ip6Addr.ParseError.EmptySegment, Ip6Addr.parse("1:2::3:")); // multiple '::' try testing.expectError(Addr.ParseError.MultipleEllipses, Addr.parse("1::2:3::4")); try testing.expectError(Addr.ParseError.MultipleEllipses, Addr.parse("::1:2::")); // overflow try testing.expectError(Addr.ParseError.Overflow, Addr.parse("::1cafe")); // invalid characters try testing.expectError(Ip6Addr.ParseError.InvalidCharacter, Ip6Addr.parse("cafe:xafe::1")); try testing.expectError(Ip6Addr.ParseError.InvalidCharacter, Ip6Addr.parse("cafe;cafe::1")); // incorrectly embedded ip4 try testing.expectError(Ip6Addr.ParseError.EmbeddedIp4InvalidLocation, Ip6Addr.parse("1:1.2.3.4")); try testing.expectError(Ip6Addr.ParseError.EmbeddedIp4InvalidLocation, Ip6Addr.parse("1:2:3:4:5:6:7:1.2.3.4")); // bad embedded ip4 try testing.expectError(Ip6Addr.ParseError.EmbeddedIp4InvalidFormat, Ip6Addr.parse("1::1.300.3.4")); try testing.expectError(Ip6Addr.ParseError.EmbeddedIp4InvalidFormat, Ip6Addr.parse("1::1.200.")); try testing.expectError(Ip6Addr.ParseError.EmbeddedIp4InvalidFormat, Ip6Addr.parse("1::1.1.1")); // too many segments try testing.expectError(Ip6Addr.ParseError.TooManySegments, Ip6Addr.parse("1:2:3:4:5:6:7:8:9:10")); try testing.expectError(Ip6Addr.ParseError.TooManySegments, Ip6Addr.parse("1:2:3:4:5::6:7:8:9:10")); // not enough segments try testing.expectError(Ip6Addr.ParseError.NotEnoughSegments, Ip6Addr.parse("1:2:3")); try testing.expectError(Ip6Addr.ParseError.NotEnoughSegments, Ip6Addr.parse("cafe:dead:beef")); try testing.expectError(Ip6Addr.ParseError.NotEnoughSegments, Ip6Addr.parse("beef")); // ambiguous ellipsis try testing.expectError(Ip6Addr.ParseError.AmbiguousEllipsis, Ip6Addr.parse("1:2:3:4::5:6:7:8")); } test "Ip6 Address Scoped/Parse" { { const expected_addr = Ip6Addr.fromArray(u16, [_]u16{ 0x2001, 0x0db8, 0, 0, 0, 0, 0x89ab, 0xcdef }); const expected_zone = "eth3"; const actual = try Ip6AddrScoped.parse("2001:db8::89ab:cdef%eth3"); try testing.expect(actual.hasZone()); try testing.expectEqual(expected_addr, actual.addr); try testing.expectEqualStrings(expected_zone, actual.zone); } { // the zone can be implementation specific const expected_addr = Ip6Addr.fromArray(u16, [_]u16{ 0x2001, 0x0db8, 0, 0, 0, 0, 0x89ab, 0xcdef }); const expected_zone = "eth%3"; const actual = try Ip6AddrScoped.parse("2001:db8::89ab:cdef%eth%3"); try testing.expect(actual.hasZone()); try testing.expectEqual(expected_addr, actual.addr); try testing.expectEqualStrings(expected_zone, actual.zone); } { const expected_addr = Ip6Addr.fromArray(u16, [_]u16{ 0x2001, 0x0db8, 0, 0, 0, 0, 0x89ab, 0xcdef }); const expected_zone = ""; const actual = try Ip6AddrScoped.parse("2001:db8::89ab:cdef"); try testing.expect(!actual.hasZone()); try testing.expectEqual(expected_addr, actual.addr); try testing.expectEqualStrings(expected_zone, actual.zone); } // raw IPv6 parsing errors try testing.expectError(Ip6AddrScoped.ParseError.AmbiguousEllipsis, Ip6AddrScoped.parse("1:2:3:4::5:6:7:8")); // empty zone try testing.expectError(Ip6AddrScoped.ParseError.EmptyZone, Ip6AddrScoped.parse("::1%")); } test "Ip6 Address/get" { const addr = Ip6Addr.fromArray(u16, [_]u16{ 0x2001, 0x0db8, 0, 0, 0, 0, 0x89ab, 0xcdef }); try testing.expectEqual(@as(u8, 0xb8), addr.get(u8, 3)); try testing.expectEqual(@as(u16, 0x89ab), addr.get(u16, 6)); } test "Ip6 Address/convert to and from std.net.Address" { const value: u128 = 0x2001_0db8_0000_0000_0000_0000_89ab_cdef; const sys_addr = try net.Ip6Address.parse("2001:db8::89ab:cdef", 10); const sys_addr1 = try net.Address.parseIp6("2001:db8::89ab:cdef", 10); const addr = Ip6Addr.fromNetAddress(sys_addr); try testing.expectEqual(value, addr.value()); try testing.expectEqual(sys_addr, addr.toNetAddress(10)); var buf: [10]u8 = undefined; const addr1 = try Addr.fromNetAddress(sys_addr1, buf[0..]); try testing.expectEqual(value, addr1.v6.value()); try testing.expectEqual(sys_addr1.in6, (try addr1.toNetAddress(10)).in6); } test "Ip6 Address Scoped/convert to and from std.net.Address" { const value: u128 = 0x2001_0db8_0000_0000_0000_0000_89ab_cdef; const sys_addr = try net.Ip6Address.parse("2001:db8::89ab:cdef%101", 10); { var buf = [_]u8{0} ** 10; const scoped = try Ip6AddrScoped.fromNetAddress(sys_addr, buf[0..]); try testing.expectEqual(value, scoped.addr.value()); try testing.expectEqualStrings("101", scoped.zone); try testing.expectEqual(sys_addr, try scoped.toNetAddress(10)); } { var buf = [_]u8{0}; try testing.expectError(Ip6AddrScoped.NetAddrScopeError.NoSpaceLeft, Ip6AddrScoped.fromNetAddress(sys_addr, buf[0..])); } } test "Ip6 Address/convert to Ip4 Address" { const value: u128 = 0x00ffffc0a8494f; const eq_value: u32 = 0xc0a8494f; try testing.expectEqual( Addr.init4(Ip4Addr.init(eq_value)), Addr.init6(Ip6Addr.init(value)).as4().?, ); try testing.expectEqual( Addr.init4(Ip4Addr.init(eq_value)), Addr.init6Scoped(Ip6AddrScoped.init(Ip6Addr.init(value), "test")).as4().?, ); const value1: u128 = 0x2001_0db8_0000_0000_0000_0000_89ab_cdef; const addr1 = Ip6Addr.init(value1); try testing.expect(null == addr1.as(Ip4Addr)); try testing.expect(null == Addr.init6(addr1).as4()); try testing.expect(null == Addr.init6Scoped(Ip6AddrScoped.init(addr1, "test")).as4()); try testing.expectEqualStrings("test", Addr.init6(addr1).as6Scoped("test").v6s.zone); } test "Ip6 Address/format" { try testing.expectFmt("2001:db8::89ab:cdef", "{}", .{try Addr.parse("2001:db8::89ab:cdef")}); try testing.expectFmt("2001:db8::", "{}", .{try Addr.parse("2001:db8::")}); try testing.expectFmt("::1", "{}", .{try Ip6Addr.parse("::1")}); try testing.expectFmt("::", "{}", .{try Ip6Addr.parse("::")}); try testing.expectFmt("2001:db8::89ab:cdef", "{x}", .{try Addr.parse("2001:db8::89ab:cdef")}); try testing.expectFmt("2001:db8:0:0:0:0:89ab:cdef", "{xE}", .{try Addr.parse("2001:db8::89ab:cdef")}); try testing.expectFmt("2001:0db8::89ab:cdef", "{X}", .{try Ip6Addr.parse("2001:db8::89ab:cdef")}); try testing.expectFmt("2001:0db8:0000:0000:0000:0000:89ab:cdef", "{XE}", .{try Ip6Addr.parse("2001:db8::89ab:cdef")}); try testing.expectFmt("10000000000001:110110111000::11", "{b}", .{try Addr.parse("2001:db8::3")}); try testing.expectFmt("10000000000001:110110111000:0:0:0:0:0:11", "{bE}", .{try Ip6Addr.parse("2001:db8::3")}); try testing.expectFmt("0010000000000001:0000110110111000::0000000000000011", "{B}", .{try Ip6Addr.parse("2001:db8::3")}); } test "Ip6 Address Scoped/format" { try testing.expectFmt("2001:db8::89ab:cdef", "{x}", .{try Ip6AddrScoped.parse("2001:db8::89ab:cdef")}); try testing.expectFmt("2001:db8:0:0:0:0:89ab:cdef%eth0", "{xE}", .{try Ip6AddrScoped.parse("2001:db8::89ab:cdef%eth0")}); try testing.expectFmt("2001:0db8::89ab:cdef%1", "{X}", .{try Ip6AddrScoped.parse("2001:db8::89ab:cdef%1")}); } test "Ip6 Address/comparison" { const addr1 = Ip6Addr.init(1); const addr2 = Ip6Addr.init(2); try testing.expectEqual(math.Order.eq, addr1.order(addr1)); try testing.expectEqual(math.Order.eq, addr2.order(addr2)); try testing.expectEqual(math.Order.lt, addr1.order(addr2)); try testing.expectEqual(math.Order.gt, addr2.order(addr1)); try testing.expectEqual(math.Order.gt, Addr.init6(addr2).order(Addr.init6(addr1))); try testing.expectEqual(math.Order.gt, Addr.init6(Ip6Addr.init(0)).order(Addr.init4(Ip4Addr.init(0xffffffff)))); } test "Ip6 Address Scoped/comparison" { const addr1 = Ip6Addr.init(1); const scoped1_1 = Ip6AddrScoped.init(addr1, "1"); const scoped1_2 = Ip6AddrScoped.init(addr1, "2"); const addr2 = Ip6Addr.init(2); const scoped2 = Ip6AddrScoped.init(addr2, "1"); const addr3 = Ip6Addr.init(3); const scoped3 = Ip6AddrScoped.init(addr3, "0"); try testing.expectEqual(math.Order.eq, scoped1_1.order(scoped1_1)); try testing.expectEqual(math.Order.lt, scoped1_1.order(scoped1_2)); try testing.expectEqual(math.Order.gt, scoped2.order(scoped1_2)); try testing.expectEqual(math.Order.gt, Addr.init6Scoped(scoped2).order(Addr.init6(addr2))); try testing.expectEqual(math.Order.gt, Addr.init6Scoped(scoped3).order(Addr.init4(Ip4Addr.init(0xffffffff)))); } test "Ip4 Address/sizeOf" { try testing.expectEqual(@sizeOf(u32), @sizeOf(Ip4Addr)); } test "Ip4 Address/fromArrayX" { // 192 168 73 79 <-> c0 a8 49 3b const expected: u32 = 0xc0a8493b; const input_u8 = [_]u8{ 0xc0, 0xa8, 0x49, 0x3b }; const input_u16_native = [_]u16{ 0xc0a8, 0x493b }; const input_u16_net = [_]u16{ mem.nativeToBig(u16, 0xc0a8), mem.nativeToBig(u16, 0x493b), }; try testing.expectEqual(expected, Ip4Addr.fromArrayNetOrder(u8, input_u8).value()); try testing.expectEqual(expected, Ip4Addr.fromArray(u8, input_u8).value()); try testing.expectEqual(expected, Ip4Addr.fromArrayNetOrder(u16, input_u16_net).value()); try testing.expectEqual(expected, Ip4Addr.fromArray(u16, input_u16_native).value()); } test "Ip4 Address/toArrayX" { // 192 168 73 79 <-> c0 a8 49 3b const value: u32 = 0xc0a8493b; const addr = Ip4Addr.init(value); const out_u8 = [_]u8{ 0xc0, 0xa8, 0x49, 0x3b }; const out_u16_native = [_]u16{ 0xc0a8, 0x493b }; const out_u16_net = [_]u16{ mem.nativeToBig(u16, 0xc0a8), mem.nativeToBig(u16, 0x493b), }; try testing.expectEqual(out_u8, addr.toArray(u8)); try testing.expectEqual(out_u8, addr.toArrayNetOrder(u8)); try testing.expectEqual(out_u16_native, addr.toArray(u16)); try testing.expectEqual(out_u16_net, addr.toArrayNetOrder(u16)); } test "Ip4 Address/Parse" { const comp_time_one = comptime try Addr.parse("0.0.0.1"); try testing.expectEqual(@as(u32, 1), comp_time_one.v4.value()); try testing.expectEqual( Ip4Addr.fromArray(u8, [_]u8{ 192, 168, 30, 15 }), (try Addr.parse("192.168.30.15")).v4, ); try testing.expectEqual( Ip4Addr.fromArray(u8, [_]u8{ 0, 0, 0, 0 }), (try Ip4Addr.parse("0.0.0.0")), ); try testing.expectEqual( Ip4Addr.fromArray(u8, [_]u8{ 255, 255, 255, 255 }), (try Ip4Addr.parse("255.255.255.255")), ); try testing.expectError(Ip4Addr.ParseError.NotEnoughOctets, Ip4Addr.parse("")); try testing.expectError(Ip4Addr.ParseError.NotEnoughOctets, Ip4Addr.parse("123")); try testing.expectError(Ip4Addr.ParseError.NotEnoughOctets, Ip4Addr.parse("1.1.1")); try testing.expectError(Ip4Addr.ParseError.InvalidCharacter, Ip4Addr.parse("20::1:1")); try testing.expectError(Ip4Addr.ParseError.Overflow, Ip4Addr.parse("256.1.1.1")); try testing.expectError(Addr.ParseError.LeadingZero, Addr.parse("254.01.1.1")); try testing.expectError(Addr.ParseError.EmptyOctet, Addr.parse(".1.1.1")); try testing.expectError(Ip4Addr.ParseError.EmptyOctet, Ip4Addr.parse("1.1..1")); try testing.expectError(Ip4Addr.ParseError.EmptyOctet, Ip4Addr.parse("1.1.1.")); try testing.expectError(Ip4Addr.ParseError.TooManyOctets, Ip4Addr.parse("1.1.1.1.1")); } test "Ip4 Address/get" { const addr = Ip4Addr.fromArray(u8, [_]u8{ 192, 168, 30, 15 }); try testing.expectEqual(@as(u8, 168), addr.get(u8, 1)); try testing.expectEqual(@as(u16, 0x1e0f), addr.get(u16, 1)); } test "Ip4 Address/convert to and from std.net.Ip4Address" { // 192 168 73 79 <-> c0 a8 49 4f const value: u32 = 0xc0a8494f; const sys_addr = try net.Ip4Address.parse("192.168.73.79", 5); const sys_addr1 = try net.Address.parseIp4("192.168.73.79", 5); const addr = Ip4Addr.fromNetAddress(sys_addr); try testing.expectEqual(value, addr.value()); try testing.expectEqual(sys_addr, addr.toNetAddress(5)); var buf: [10]u8 = undefined; const addr1 = try Addr.fromNetAddress(sys_addr1, buf[0..]); try testing.expectEqual(value, addr1.v4.value()); try testing.expectEqual(sys_addr1.in, (try addr1.toNetAddress(5)).in); } test "Ip4 Address/convert to Ip6 Address" { const value: u32 = 0xc0a8494f; const eq_value: u128 = 0x00ffffc0a8494f; try testing.expectEqual(eq_value, Ip4Addr.fromArray(u32, [_]u32{value}).as(Ip6Addr).?.value()); try testing.expectEqual( Addr.init6(Ip6Addr.init(eq_value)), Addr.init4(Ip4Addr.init(value)).as6(), ); const expected_scoped = Ip6AddrScoped.init(Ip6Addr.init(eq_value), "test"); const actual_scoped = Addr.init4(Ip4Addr.init(value)).as6Scoped("test").v6s; try testing.expectEqual(expected_scoped.addr, actual_scoped.addr); try testing.expectEqualStrings(expected_scoped.zone, actual_scoped.zone); } test "Ip4 Address/format" { try testing.expectFmt("192.168.73.72", "{}", .{try Addr.parse("192.168.73.72")}); try testing.expectFmt("c0.a8.49.1", "{x}", .{try Ip4Addr.parse("192.168.73.1")}); try testing.expectFmt("c0.a8.01.01", "{X}", .{try Addr.parse("192.168.1.1")}); try testing.expectFmt("11000000.10101000.1001001.1001000", "{b}", .{try Ip4Addr.parse("192.168.73.72")}); try testing.expectFmt("11000000.10101000.01001001.01001000", "{B}", .{try Addr.parse("192.168.73.72")}); } test "Ip4 Address/comparison" { const addr1 = Ip4Addr.init(1); const addr2 = Ip4Addr.init(2); try testing.expectEqual(math.Order.eq, addr1.order(addr1)); try testing.expectEqual(math.Order.eq, addr2.order(addr2)); try testing.expectEqual(math.Order.lt, addr1.order(addr2)); try testing.expectEqual(math.Order.gt, addr2.order(addr1)); try testing.expectEqual(math.Order.gt, Addr.init4(addr2).order(Addr.init4(addr1))); try testing.expectEqual(math.Order.lt, Addr.init4(Ip4Addr.init(0xffffffff)).order(Addr.init6(Ip6Addr.init(0)))); }
0
repos/zig-netip
repos/zig-netip/src/netip.zig
const std = @import("std"); const testing = std.testing; const math = std.math; pub fn order(a: anytype, b: @TypeOf(a)) math.Order { return a.order(b); } const addr = @import("./addr.zig"); const prefix = @import("./prefix.zig"); pub const Addr = addr.Addr; pub const Ip4Addr = addr.Ip4Addr; pub const Ip6Addr = addr.Ip6Addr; pub const Ip6AddrScoped = addr.Ip6AddrScoped; pub const PrefixInclusion = prefix.Inclusion; pub const Prefix = prefix.Prefix; pub const Ip4Prefix = prefix.Ip4Prefix; pub const Ip6Prefix = prefix.Ip6Prefix; test "Addr Example" { // ipv4 create const v4_addr1 = comptime try Ip4Addr.parse("192.0.2.1"); const v4_addr2 = try Addr.parse("192.0.2.1"); const v4_addr3 = Ip4Addr.fromArray(u8, [_]u8{ 192, 0, 2, 2 }); const v4_addr4 = Ip4Addr.fromArray(u16, [_]u16{ 0xC000, 0x0202 }); const v4_addr5 = Addr.init4(Ip4Addr.init(0xC0000203)); const v4_addr6 = Ip4Addr.fromNetAddress(try std.net.Ip4Address.parse("192.0.2.3", 1)); // ipv6 create const v6_addr1 = comptime try Ip6Addr.parse("2001:db8::1"); const v6_addr2 = try Addr.parse("2001:db8::1"); const v6_addr3 = Ip6Addr.fromArray(u8, [_]u8{ 0x20, 0x1, 0xd, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2 }); const v6_addr4 = Ip6Addr.fromArray(u16, [_]u16{ 0x2001, 0xdb8, 0, 0, 0, 0, 0, 0x2 }); const v6_addr5 = Addr.init6(Ip6Addr.init(0x2001_0db8_0000_0000_0000_0000_0000_0003)); const v6_addr6 = Ip6Addr.fromNetAddress(try std.net.Ip6Address.parse("2001:db8::3", 1)); // ipv6 scoped const v6_scoped1 = comptime try Ip6AddrScoped.parse("2001:db8::1%eth2"); const v6_scoped2 = try Addr.parse("2001:db8::2%4"); // handle parsing errors try testing.expect(Ip4Addr.parse("-=_=-") == Ip4Addr.ParseError.InvalidCharacter); try testing.expect(Addr.parse("0.-=_=-") == Addr.ParseError.InvalidCharacter); try testing.expect(Ip6Addr.parse("-=_=-") == Ip6Addr.ParseError.InvalidCharacter); try testing.expect(Addr.parse("::-=_=-") == Addr.ParseError.InvalidCharacter); // copy const v4_addr7 = v4_addr5; const v6_addr8 = v6_addr3; _ = .{ v4_addr7, v4_addr4, v4_addr6, v6_scoped1, v6_scoped2, v6_addr4, v6_addr6 }; // compare via values try testing.expectEqual(math.Order.eq, order(v4_addr1, v4_addr2.v4)); try testing.expectEqual(math.Order.lt, order(v6_addr1, v6_addr8)); try testing.expectEqual(math.Order.gt, order(v6_addr8, v6_addr1)); try testing.expectEqual(math.Order.gt, order(v6_addr2, v4_addr2)); // cross AF comparison // print try testing.expectFmt("192.0.2.1", "{}", .{v4_addr1}); try testing.expectFmt("c0.00.02.02", "{X}", .{v4_addr3}); try testing.expectFmt("11000000.0.10.11", "{b}", .{v4_addr5}); try testing.expectFmt("2001:db8::1", "{}", .{v6_addr1}); try testing.expectFmt("2001:db8:0:0:0:0:0:2", "{xE}", .{v6_addr3}); try testing.expectFmt("2001:0db8::0003", "{X}", .{v6_addr5}); try testing.expectFmt("2001:0db8:0000:0000:0000:0000:0000:0001", "{XE}", .{v6_addr2}); } test "Prefix Example" { // create a ipv6 prefix const v6_prefix1 = try Ip6Prefix.init(try Ip6Addr.parse("2001:db8:85a3::1"), 48); const v6_prefix2 = try Prefix.parse("2001:db8:85a3::/48"); // create a prefix const v4_prefix1 = try Ip4Prefix.init(try Ip4Addr.parse("192.0.2.1"), 24); const v4_prefix2 = try Prefix.parse("192.0.2.1/24"); // compare mask bits try testing.expectEqual(v6_prefix1.maskBits(), v6_prefix2.v6.maskBits()); try testing.expectEqual(v4_prefix1.maskBits(), v4_prefix2.v4.maskBits()); // handle parsing errors try testing.expectError(Prefix.ParseError.Overflow, Prefix.parse("2001:db8::/256")); try testing.expectError(Prefix.ParseError.Overflow, Prefix.parse("1.1.1.1/33")); // print try testing.expectFmt("2001:db8:85a3::1/48", "{}", .{v6_prefix1}); try testing.expectFmt("2001:0db8:85a3::0001/48", "{X}", .{v6_prefix1}); try testing.expectFmt("2001:db8:85a3::-2001:db8:85a3:ffff:ffff:ffff:ffff:ffff", "{R}", .{v6_prefix1}); try testing.expectFmt("192.0.2.0/24", "{}", .{v4_prefix1.canonical()}); try testing.expectFmt("192.0.2.0-192.0.2.255", "{R}", .{v4_prefix1}); // contains address try testing.expect(v6_prefix2.containsAddr(try Addr.parse("2001:db8:85a3:cafe::efac"))); try testing.expect(v4_prefix2.containsAddr(try Addr.parse("192.0.2.42"))); // inclusion and overlap test try testing.expectEqual(PrefixInclusion.sub, v6_prefix1.testInclusion(try Ip6Prefix.parse("2001:db8::/32"))); try testing.expect(v6_prefix2.overlaps(try Prefix.parse("2001:db8::/32"))); try testing.expectEqual(PrefixInclusion.sub, v4_prefix1.testInclusion(try Ip4Prefix.parse("192.0.2.0/16"))); try testing.expect(v4_prefix2.overlaps(try Prefix.parse("192.0.2.0/16"))); }
0
repos/zig-netip
repos/zig-netip/src/prefix.zig
const std = @import("std"); const assert = std.debug.assert; const math = std.math; const mem = std.mem; const testing = std.testing; const Signedness = std.builtin.Signedness; const addr = @import("./addr.zig"); const Ip4Addr = addr.Ip4Addr; const Ip6Addr = addr.Ip6Addr; const Addr = addr.Addr; /// Inclusion relationship between 2 prefixes A and B /// (sets of IP addresses they define) pub const Inclusion = enum { /// A is a proper subset of B sub, /// A is equal to B eq, /// A is a proper superset of B super, /// A and B are not related none, }; /// A Prefix type constructor from the corresponding Addr type pub fn PrefixForAddrType(comptime T: type) type { if (T != Ip4Addr and T != Ip6Addr) { @compileError("unknown address type '" ++ @typeName(T) ++ "' (only v4 and v6 addresses are supported)"); } const pos_bits = @typeInfo(T.PositionType).Int.bits; return packed struct { const Self = @This(); const V = T.ValueType; // we need an extra bit to represent the widest mask, e.g. /32 for the v4 address /// The type of the bits mask pub const MaskBitsType = std.meta.Int(Signedness.unsigned, pos_bits + 1); /// The type of wrapped address. pub const AddrType = T; /// Max allowed bit mask pub const maxMaskBits = 1 << pos_bits; // that includes the Overflow and InvalidCharacter pub const ParseError = error{NoBitMask} || T.ParseError; addr: T, mask_bits: MaskBitsType, /// Create a prefix from the given address and the number of bits. /// Following the go's netip implementation, we don't zero bits not /// covered by the mask. /// The mask bits size must be <= address specific maxMaskBits. pub fn init(a: T, bits: MaskBitsType) !Self { if (bits > maxMaskBits) { return error.Overflow; } return safeInit(a, bits); } inline fn safeInit(a: T, bits: MaskBitsType) Self { assert(bits <= maxMaskBits); return Self{ .addr = a, .mask_bits = bits }; } /// Create a new prefix with the same bit mask size as /// the given example prefix. pub fn initAnother(self: Self, a: T) Self { return safeInit(a, self.mask_bits); } /// Parse the prefix from the string representation pub fn parse(s: []const u8) ParseError!Self { if (mem.indexOfScalar(u8, s, '/')) |i| { if (i == s.len - 1) return ParseError.NoBitMask; const parsed = try T.parse(s[0..i]); var bits: MaskBitsType = 0; for (s[i + 1 ..]) |c| { switch (c) { '0'...'9' => { bits = math.mul(MaskBitsType, bits, 10) catch return ParseError.Overflow; bits = math.add(MaskBitsType, bits, @as(MaskBitsType, @truncate(c - '0'))) catch return ParseError.Overflow; }, else => return ParseError.InvalidCharacter, } } if (bits > maxMaskBits) return ParseError.Overflow; return init(parsed, bits); } return ParseError.NoBitMask; } /// Returns underlying address. pub fn addr(self: Self) T { return self.addr; } /// Returns the number of bits in the mask pub fn maskBits(self: Self) MaskBitsType { return self.mask_bits; } inline fn mask(self: Self) V { // shrExact doesn't work because mask_bits has 1 extra bit return ~math.shr(V, ~@as(V, 0), self.mask_bits); } /// Return the first and the last addresses in the prefix pub fn addrRange(self: Self) [2]T { const first = self.addr.value() & self.mask(); const last = first | ~self.mask(); return [2]T{ T.init(first), T.init(last) }; } /// Return the canonical representation of the prefix /// with all insignificant bits set to 0 (bits not covered by the mask). pub fn canonical(self: Self) Self { return self.initAnother(T.init(self.addr.value() & self.mask())); } /// Print the address. The modifier is passed to either Ip4Addr or Ip6Addr unchanged, /// however it can be prepended with the optional 'R' modifier that uses the IP range /// format instead of the standard cidr prefix format. pub fn format( self: Self, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: anytype, ) !void { _ = options; if (fmt.len > 0 and fmt[0] == 'R') { const fmt_trunc = "{" ++ fmt[1..] ++ "}"; const fmt_r = fmt_trunc ++ "-" ++ fmt_trunc; const r = self.addrRange(); try std.fmt.format(out_stream, fmt_r, .{ r[0], r[1] }); } else { try std.fmt.format(out_stream, "{" ++ fmt ++ "}" ++ "/{}", .{ self.addr, self.mask_bits }); } } /// Test the inclusion relationship between two prefixes. pub fn testInclusion(self: Self, other: Self) Inclusion { const common_mask = @min(self.mask_bits, other.mask_bits); const related = math.shr(V, self.addr.value() ^ other.addr.value(), maxMaskBits - common_mask) == 0; if (!related) { return Inclusion.none; } return switch (math.order(self.mask_bits, other.mask_bits)) { .lt => Inclusion.super, .eq => Inclusion.eq, .gt => Inclusion.sub, }; } /// Test if the address is within the range defined by the prefix. pub fn containsAddr(self: Self, a: T) bool { return math.shr(V, self.addr.value() ^ a.value(), maxMaskBits - self.mask_bits) == 0; } /// Two prefixes overlap if they are in the inclusion relationship pub fn overlaps(self: Self, other: Self) bool { return self.testInclusion(other) != Inclusion.none; } /// Convert between IPv4 and IPv6 prefixes /// Use '::ffff:0:0/96' for IPv4 mapped addresses. pub fn as(self: Self, comptime O: type) ?O { if (Self == O) { return self; } return switch (O.AddrType) { Ip6Addr => O.safeInit(self.addr.as(Ip6Addr).?, O.maxMaskBits - maxMaskBits + @as(O.MaskBitsType, self.mask_bits)), Ip4Addr => if (self.addr.as(Ip4Addr)) |a| O.safeInit(a, @as(O.MaskBitsType, @truncate(self.mask_bits - (maxMaskBits - O.maxMaskBits)))) else null, else => @compileError("unsupported prefix conversion from '" ++ @typeName(Self) ++ "' to '" ++ @typeName(O) + "'"), }; } }; } pub const Ip4Prefix = PrefixForAddrType(Ip4Addr); pub const Ip6Prefix = PrefixForAddrType(Ip6Addr); pub const PrefixType = enum { v4, v6, }; /// A union type that allows to work with both prefix types at the same time. /// Only high-level operations are supported. Unwrap the concrete /// prefix type to do any sort of low-level or bit operations. pub const Prefix = union(PrefixType) { v4: Ip4Prefix, v6: Ip6Prefix, pub const ParseError = error{UnknownAddress} || Ip4Prefix.ParseError || Ip6Prefix.ParseError; /// Parse the prefix from the string representation pub fn parse(s: []const u8) ParseError!Prefix { for (s) |c| { switch (c) { '.' => return Prefix{ .v4 = try Ip4Prefix.parse(s) }, ':' => return Prefix{ .v6 = try Ip6Prefix.parse(s) }, else => continue, } } return ParseError.UnknownAddress; } /// Return the canonical representation of the prefix /// with all insignificant bits set to 0 (bits not covered by the mask). pub fn canonical(self: Prefix) Prefix { return switch (self) { .v4 => |a| Prefix{ .v4 = a.canonical() }, .v6 => |a| Prefix{ .v6 = a.canonical() }, }; } /// Return the equivalent IPv6 prefix. pub fn as6(self: Prefix) Prefix { return switch (self) { .v4 => |a| Prefix{ .v6 = a.as(Ip6Prefix).? }, .v6 => self, }; } /// Return the equivalent IPv4 prefix if it exists. pub fn as4(self: Prefix) ?Prefix { return switch (self) { .v4 => self, .v6 => |a| (if (a.as(Ip4Prefix)) |p| Prefix{ .v4 = p } else null), }; } /// Test the inclusion relationship between two prefixes. /// Any IPv6 prefix is not related to the IPv4 prefix or vice-versa. pub fn testInclusion(self: Prefix, other: Prefix) Inclusion { return switch (self) { .v4 => |l4| switch (other) { .v4 => |r4| l4.testInclusion(r4), .v6 => Inclusion.none, }, .v6 => |l6| switch (other) { .v4 => Inclusion.none, .v6 => |r6| l6.testInclusion(r6), }, }; } /// Two prefixes overlap if they are in the inclusion relationship. /// Prefixes from different families do not overlap. pub fn overlaps(self: Prefix, other: Prefix) bool { return switch (self) { .v4 => |l4| switch (other) { .v4 => |r4| l4.overlaps(r4), .v6 => false, }, .v6 => |l6| switch (other) { .v4 => false, .v6 => |r6| l6.overlaps(r6), }, }; } /// Test if the address is within the range defined by the prefix. /// If prefix and the address are from different families, the result /// is always false. pub fn containsAddr(self: Prefix, a: Addr) bool { return switch (self) { .v4 => |l4| switch (a) { .v4 => |r4| l4.containsAddr(r4), .v6 => false, .v6s => false, }, .v6 => |l6| switch (a) { .v4 => false, .v6 => |r6| l6.containsAddr(r6), .v6s => false, }, }; } /// Print the address. The modifier is passed to either Ip4Prefix or Ip6Prefix unchanged. pub fn format( self: Prefix, comptime fmt: []const u8, options: std.fmt.FormatOptions, out_stream: anytype, ) !void { switch (self) { .v4 => |a| try a.format(fmt, options, out_stream), .v6 => |a| try a.format(fmt, options, out_stream), } } }; test "Prefix/trivial init" { const addr4 = Ip4Addr.init(1); const addr6 = Ip6Addr.init(2); const addr6_1 = Ip6Addr.init(3); try testing.expectEqual(Ip4Prefix{ .addr = addr4, .mask_bits = 3 }, try Ip4Prefix.init(addr4, 3)); try testing.expectEqual(Ip6Prefix{ .addr = addr6, .mask_bits = 3 }, try Ip6Prefix.init(addr6, 3)); const prefix = try Ip6Prefix.init(addr6, 32); try testing.expectEqual(Ip6Prefix{ .addr = addr6_1, .mask_bits = 32 }, prefix.initAnother(addr6_1)); try testing.expectError(error.Overflow, Ip4Prefix.init(addr4, 33)); try testing.expectError(error.Overflow, Ip6Prefix.init(addr6, 129)); try testing.expectEqual(u6, Ip4Prefix.MaskBitsType); try testing.expectEqual(u8, Ip6Prefix.MaskBitsType); } test "Prefix/parse4" { const a_str = "192.0.2.1"; const a = try Ip4Addr.parse(a_str); try testing.expectEqual( Prefix{ .v4 = Ip4Prefix.safeInit(a, 24) }, try Prefix.parse(a_str ++ "/24"), ); try testing.expectEqual( Prefix{ .v4 = Ip4Prefix.safeInit(a, 0) }, try Prefix.parse(a_str ++ "/0"), ); try testing.expectEqual( Prefix{ .v4 = Ip4Prefix.safeInit(a, 32) }, try Prefix.parse(a_str ++ "/32"), ); try testing.expectError(Prefix.ParseError.NotEnoughOctets, Prefix.parse("192.0.2/24")); try testing.expectError(Prefix.ParseError.NoBitMask, Prefix.parse("192.0.2/")); try testing.expectError(Prefix.ParseError.NoBitMask, Prefix.parse("192.0.2")); try testing.expectError(Prefix.ParseError.Overflow, Prefix.parse("192.0.2.1/33")); try testing.expectError(Prefix.ParseError.InvalidCharacter, Prefix.parse("192.0.2.1/test")); try testing.expectError(Prefix.ParseError.InvalidCharacter, Prefix.parse("192.0.2.1/-1")); try testing.expectError(Prefix.ParseError.UnknownAddress, Prefix.parse("/")); } test "Prefix/parse6" { const a_str = "2001:db8::1"; const a = try Ip6Addr.parse(a_str); try testing.expectEqual( Prefix{ .v6 = Ip6Prefix.safeInit(a, 96) }, try Prefix.parse(a_str ++ "/96"), ); try testing.expectEqual( Prefix{ .v6 = Ip6Prefix.safeInit(a, 0) }, try Prefix.parse(a_str ++ "/0"), ); try testing.expectEqual( Prefix{ .v6 = Ip6Prefix.safeInit(a, 128) }, try Prefix.parse(a_str ++ "/128"), ); try testing.expectError(Prefix.ParseError.NotEnoughSegments, Ip6Prefix.parse("2001:db8:1/24")); try testing.expectError(Prefix.ParseError.NoBitMask, Ip6Prefix.parse("2001:db8::1/")); try testing.expectError(Prefix.ParseError.NoBitMask, Ip6Prefix.parse("2001:db8::1")); try testing.expectError(Prefix.ParseError.Overflow, Ip6Prefix.parse("2001:db8::1/129")); try testing.expectError(Prefix.ParseError.InvalidCharacter, Ip6Prefix.parse("2001:db8::1/test")); try testing.expectError(Prefix.ParseError.InvalidCharacter, Ip6Prefix.parse("2001:db8::1/-1")); try testing.expectError(Prefix.ParseError.UnknownAddress, Prefix.parse("/")); } test "Prefix/canonicalize" { try testing.expectEqual(try Prefix.parse("2001:db8::/48"), (try Prefix.parse("2001:db8::403:201/48")).canonical()); try testing.expectEqual(try Prefix.parse("2001:db8::/48"), (try Prefix.parse("2001:db8::403:201/48")).canonical()); try testing.expectEqual(try Prefix.parse("2001:0db8:8000::/33"), (try Prefix.parse("2001:db8:85a3::8a2e:370:7334/33")).canonical()); try testing.expectEqual(try Prefix.parse("192.0.2.0/24"), (try Prefix.parse("192.0.2.48/24")).canonical()); try testing.expectEqual(try Prefix.parse("192.0.2.0/24"), (try Prefix.parse("192.0.2.48/24")).canonical()); try testing.expectEqual(try Prefix.parse("37.224.0.0/11"), (try Prefix.parse("37.228.215.135/11")).canonical()); } test "Prefix/addrRange" { try testing.expectEqual( [2]Ip6Addr{ try Ip6Addr.parse("2001:0db8:85a3:0000:0000:0000:0000:0000"), try Ip6Addr.parse("2001:0db8:85a3:001f:ffff:ffff:ffff:ffff"), }, (try Ip6Prefix.parse("2001:db8:85a3::8a2e:370:7334/59")).addrRange(), ); try testing.expectEqual( [2]Ip4Addr{ try Ip4Addr.parse("37.228.214.0"), try Ip4Addr.parse("37.228.215.255"), }, (try Ip4Prefix.parse("37.228.215.135/23")).addrRange(), ); } test "Prefix/format" { const prefix4 = try Prefix.parse("192.0.2.16/24"); const prefix6 = try Prefix.parse("2001:0db8:85a3::1/96"); try testing.expectFmt("192.0.2.16/24", "{}", .{prefix4}); try testing.expectFmt("c0.0.2.10/24", "{x}", .{prefix4}); try testing.expectFmt("c0.00.02.10/24", "{X}", .{prefix4}); try testing.expectFmt("192.0.2.0-192.0.2.255", "{R}", .{prefix4}); try testing.expectFmt("c0.00.02.00-c0.00.02.ff", "{RX}", .{prefix4}); try testing.expectFmt("2001:db8:85a3::1/96", "{}", .{prefix6}); try testing.expectFmt("2001:0db8:85a3::0001/96", "{X}", .{prefix6}); try testing.expectFmt("2001:db8:85a3::1/96", "{x}", .{prefix6}); try testing.expectFmt("2001:db8:85a3::-2001:db8:85a3::ffff:ffff", "{R}", .{prefix6}); try testing.expectFmt("2001:db8:85a3:0:0:0:0:0-2001:db8:85a3:0:0:0:ffff:ffff", "{RE}", .{prefix6}); } test "Prefix/contansAddress" { try testing.expect((try Prefix.parse("10.11.12.13/0")).containsAddr(try Addr.parse("192.168.1.1"))); try testing.expect((try Prefix.parse("10.11.12.13/8")).containsAddr(try Addr.parse("10.6.3.5"))); try testing.expect((try Prefix.parse("10.11.12.13/32")).containsAddr(try Addr.parse("10.11.12.13"))); try testing.expect(!(try Prefix.parse("192.0.2.0/25")).containsAddr(try Addr.parse("192.0.2.192"))); try testing.expect(!(try Prefix.parse("0.0.0.0/0")).containsAddr(try Addr.parse("::1"))); try testing.expect((try Prefix.parse("2001:db8::/0")).containsAddr(try Addr.parse("3001:db8::1"))); try testing.expect((try Prefix.parse("2001:db8::/8")).containsAddr(try Addr.parse("2002:db8::1"))); try testing.expect((try Prefix.parse("2001:db8::/16")).containsAddr(try Addr.parse("2001:db8::2"))); try testing.expect(!(try Prefix.parse("2001:db8::cafe:0/112")).containsAddr(try Addr.parse("2001:db8::beef:7"))); try testing.expect(!(try Prefix.parse("::/0")).containsAddr(try Addr.parse("1.1.1.1"))); } test "Prefix/inclusion" { const prefixes4 = [_]Prefix{ try Prefix.parse("10.11.12.13/0"), try Prefix.parse("10.11.12.13/3"), try Prefix.parse("10.11.12.13/24"), try Prefix.parse("10.11.12.13/31"), try Prefix.parse("10.11.12.13/32"), }; const prefixes6 = [_]Prefix{ try Prefix.parse("2001:db8:cafe::1/0"), try Prefix.parse("2001:db8:cafe::1/3"), try Prefix.parse("2001:db8:cafe::1/32"), try Prefix.parse("2001:db8:cafe::1/127"), try Prefix.parse("2001:db8:cafe::1/128"), }; const prefixes = [_][5]Prefix{ prefixes4, prefixes6 }; for (prefixes) |prefix| { for (prefix, 0..) |p, i| { try testing.expectEqual(Inclusion.eq, p.testInclusion(p)); try testing.expect(p.overlaps(p)); for (prefix[0..i]) |prev| { try testing.expectEqual(Inclusion.sub, p.testInclusion(prev)); try testing.expect(p.overlaps(prev)); } if (i == prefix.len - 1) continue; for (prefix[i + 1 ..]) |next| { try testing.expectEqual(Inclusion.super, p.testInclusion(next)); try testing.expect(p.overlaps(next)); } } } const unrel4_1 = try Prefix.parse("192.168.73.0/24"); const unrel4_2 = try Prefix.parse("192.168.74.0/24"); const unrel6_1 = try Prefix.parse("2001:db8:cafe::1/48"); const unrel6_2 = try Prefix.parse("2001:db8:beef::1/48"); const all_addr4 = try Prefix.parse("0.0.0.0/0"); const all_addr6 = try Prefix.parse("::/0"); try testing.expectEqual(Inclusion.none, unrel4_1.testInclusion(unrel4_2)); try testing.expectEqual(Inclusion.none, unrel6_1.testInclusion(unrel6_2)); try testing.expectEqual(Inclusion.none, all_addr4.testInclusion(all_addr6)); try testing.expect(!unrel4_2.overlaps(unrel4_1)); try testing.expect(!unrel6_2.overlaps(unrel6_1)); try testing.expect(!all_addr6.overlaps(all_addr4)); } test "Prefix/conversion" { try testing.expectEqual(try Prefix.parse("::ffff:0a0b:0c0d/112"), (try Prefix.parse("10.11.12.13/16")).as6()); try testing.expectEqual(try Prefix.parse("::ffff:0a0b:0c0d/128"), (try Prefix.parse("10.11.12.13/32")).as6()); try testing.expectEqual(try Prefix.parse("10.11.12.13/16"), (try Prefix.parse("::ffff:0a0b:0c0d/112")).as4().?); try testing.expectEqual(try Prefix.parse("10.11.12.13/32"), (try Prefix.parse("::ffff:0a0b:0c0d/128")).as4().?); try testing.expect(null == (try Prefix.parse("2001::ffff:0a0b:0c0d/48")).as4()); }
0
repos
repos/Zig-binding-GLFW-OpemGL-tutorial/main.zig
const std=@import("std"); const glfw=@cImport({ @cInclude("GLFW/glfw3.h"); @cInclude("GLFW/glfw3native.h"); }); const gl=@cImport({ @cInclude("GL/gl.h"); }); pub fn main() !void { if (glfw.glfwInit() == 0) { std.debug.print("GLFW 初始化失败", .{}); return; } const window:?*glfw.GLFWwindow = glfw.glfwCreateWindow(200, 200, "glfw binding", null, null); if (window == null) { glfw.glfwTerminate(); std.debug.print("窗口创建失败", .{}); return; } glfw.glfwMakeContextCurrent(window); while (glfw.glfwWindowShouldClose(window) == 0) { // 渲染代码 glfw.glfwSwapBuffers(window); glfw.glfwPollEvents(); } glfw.glfwDestroyWindow(window); glfw.glfwTerminate(); }
0
repos
repos/Zig-binding-GLFW-OpemGL-tutorial/build.zig
const std=@import("std"); pub fn build(b:*std.Build) void{ //standard build step const target=b.standardTargetOptions(.{}); const optimize=b.standardOptimizeOption(.{}); const exe=b.addExecutable(.{ .name = "main", .root_source_file = b.path("./main.zig"), .target = target, .optimize = optimize, }); // set subsystem to windows means del the console exe.subsystem=.Windows; //link glfw include path and lib path exe.addIncludePath(b.path("./include/")); exe.addLibraryPath(b.path("./lib-static-ucrt/")); //link windows system libs exe.linkSystemLibrary("glfw3dll"); exe.linkSystemLibrary("opengl32"); exe.linkSystemLibrary("gdi32"); //link c standard librarys exe.linkLibC(); //build exe b.installArtifact(exe); }
0
repos/Zig-binding-GLFW-OpemGL-tutorial/include
repos/Zig-binding-GLFW-OpemGL-tutorial/include/GLFW/glfw3native.h
/************************************************************************* * GLFW 3.4 - www.glfw.org * A library for OpenGL, window and input *------------------------------------------------------------------------ * Copyright (c) 2002-2006 Marcus Geelnard * Copyright (c) 2006-2018 Camilla Löwy <[email protected]> * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would * be appreciated but is not required. * * 2. Altered source versions must be plainly marked as such, and must not * be misrepresented as being the original software. * * 3. This notice may not be removed or altered from any source * distribution. * *************************************************************************/ #ifndef _glfw3_native_h_ #define _glfw3_native_h_ #ifdef __cplusplus extern "C" { #endif /************************************************************************* * Doxygen documentation *************************************************************************/ /*! @file glfw3native.h * @brief The header of the native access functions. * * This is the header file of the native access functions. See @ref native for * more information. */ /*! @defgroup native Native access * @brief Functions related to accessing native handles. * * **By using the native access functions you assert that you know what you're * doing and how to fix problems caused by using them. If you don't, you * shouldn't be using them.** * * Before the inclusion of @ref glfw3native.h, you may define zero or more * window system API macro and zero or more context creation API macros. * * The chosen backends must match those the library was compiled for. Failure * to do this will cause a link-time error. * * The available window API macros are: * * `GLFW_EXPOSE_NATIVE_WIN32` * * `GLFW_EXPOSE_NATIVE_COCOA` * * `GLFW_EXPOSE_NATIVE_X11` * * `GLFW_EXPOSE_NATIVE_WAYLAND` * * The available context API macros are: * * `GLFW_EXPOSE_NATIVE_WGL` * * `GLFW_EXPOSE_NATIVE_NSGL` * * `GLFW_EXPOSE_NATIVE_GLX` * * `GLFW_EXPOSE_NATIVE_EGL` * * `GLFW_EXPOSE_NATIVE_OSMESA` * * These macros select which of the native access functions that are declared * and which platform-specific headers to include. It is then up your (by * definition platform-specific) code to handle which of these should be * defined. * * If you do not want the platform-specific headers to be included, define * `GLFW_NATIVE_INCLUDE_NONE` before including the @ref glfw3native.h header. * * @code * #define GLFW_EXPOSE_NATIVE_WIN32 * #define GLFW_EXPOSE_NATIVE_WGL * #define GLFW_NATIVE_INCLUDE_NONE * #include <GLFW/glfw3native.h> * @endcode */ /************************************************************************* * System headers and types *************************************************************************/ #if !defined(GLFW_NATIVE_INCLUDE_NONE) #if defined(GLFW_EXPOSE_NATIVE_WIN32) || defined(GLFW_EXPOSE_NATIVE_WGL) /* This is a workaround for the fact that glfw3.h needs to export APIENTRY (for * example to allow applications to correctly declare a GL_KHR_debug callback) * but windows.h assumes no one will define APIENTRY before it does */ #if defined(GLFW_APIENTRY_DEFINED) #undef APIENTRY #undef GLFW_APIENTRY_DEFINED #endif #include <windows.h> #endif #if defined(GLFW_EXPOSE_NATIVE_COCOA) || defined(GLFW_EXPOSE_NATIVE_NSGL) #if defined(__OBJC__) #import <Cocoa/Cocoa.h> #else #include <ApplicationServices/ApplicationServices.h> #include <objc/objc.h> #endif #endif #if defined(GLFW_EXPOSE_NATIVE_X11) || defined(GLFW_EXPOSE_NATIVE_GLX) #include <X11/Xlib.h> #include <X11/extensions/Xrandr.h> #endif #if defined(GLFW_EXPOSE_NATIVE_WAYLAND) #include <wayland-client.h> #endif #if defined(GLFW_EXPOSE_NATIVE_WGL) /* WGL is declared by windows.h */ #endif #if defined(GLFW_EXPOSE_NATIVE_NSGL) /* NSGL is declared by Cocoa.h */ #endif #if defined(GLFW_EXPOSE_NATIVE_GLX) /* This is a workaround for the fact that glfw3.h defines GLAPIENTRY because by * default it also acts as an OpenGL header * However, glx.h will include gl.h, which will define it unconditionally */ #if defined(GLFW_GLAPIENTRY_DEFINED) #undef GLAPIENTRY #undef GLFW_GLAPIENTRY_DEFINED #endif #include <GL/glx.h> #endif #if defined(GLFW_EXPOSE_NATIVE_EGL) #include <EGL/egl.h> #endif #if defined(GLFW_EXPOSE_NATIVE_OSMESA) /* This is a workaround for the fact that glfw3.h defines GLAPIENTRY because by * default it also acts as an OpenGL header * However, osmesa.h will include gl.h, which will define it unconditionally */ #if defined(GLFW_GLAPIENTRY_DEFINED) #undef GLAPIENTRY #undef GLFW_GLAPIENTRY_DEFINED #endif #include <GL/osmesa.h> #endif #endif /*GLFW_NATIVE_INCLUDE_NONE*/ /************************************************************************* * Functions *************************************************************************/ #if defined(GLFW_EXPOSE_NATIVE_WIN32) /*! @brief Returns the adapter device name of the specified monitor. * * @return The UTF-8 encoded adapter device name (for example `\\.\DISPLAY1`) * of the specified monitor, or `NULL` if an [error](@ref error_handling) * occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_UNAVAILABLE. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.1. * * @ingroup native */ GLFWAPI const char* glfwGetWin32Adapter(GLFWmonitor* monitor); /*! @brief Returns the display device name of the specified monitor. * * @return The UTF-8 encoded display device name (for example * `\\.\DISPLAY1\Monitor0`) of the specified monitor, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_UNAVAILABLE. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.1. * * @ingroup native */ GLFWAPI const char* glfwGetWin32Monitor(GLFWmonitor* monitor); /*! @brief Returns the `HWND` of the specified window. * * @return The `HWND` of the specified window, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_UNAVAILABLE. * * @remark The `HDC` associated with the window can be queried with the * [GetDC](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdc) * function. * @code * HDC dc = GetDC(glfwGetWin32Window(window)); * @endcode * This DC is private and does not need to be released. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.0. * * @ingroup native */ GLFWAPI HWND glfwGetWin32Window(GLFWwindow* window); #endif #if defined(GLFW_EXPOSE_NATIVE_WGL) /*! @brief Returns the `HGLRC` of the specified window. * * @return The `HGLRC` of the specified window, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_PLATFORM_UNAVAILABLE and @ref GLFW_NO_WINDOW_CONTEXT. * * @remark The `HDC` associated with the window can be queried with the * [GetDC](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdc) * function. * @code * HDC dc = GetDC(glfwGetWin32Window(window)); * @endcode * This DC is private and does not need to be released. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.0. * * @ingroup native */ GLFWAPI HGLRC glfwGetWGLContext(GLFWwindow* window); #endif #if defined(GLFW_EXPOSE_NATIVE_COCOA) /*! @brief Returns the `CGDirectDisplayID` of the specified monitor. * * @return The `CGDirectDisplayID` of the specified monitor, or * `kCGNullDirectDisplay` if an [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_UNAVAILABLE. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.1. * * @ingroup native */ GLFWAPI CGDirectDisplayID glfwGetCocoaMonitor(GLFWmonitor* monitor); /*! @brief Returns the `NSWindow` of the specified window. * * @return The `NSWindow` of the specified window, or `nil` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_UNAVAILABLE. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.0. * * @ingroup native */ GLFWAPI id glfwGetCocoaWindow(GLFWwindow* window); /*! @brief Returns the `NSView` of the specified window. * * @return The `NSView` of the specified window, or `nil` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_UNAVAILABLE. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.4. * * @ingroup native */ GLFWAPI id glfwGetCocoaView(GLFWwindow* window); #endif #if defined(GLFW_EXPOSE_NATIVE_NSGL) /*! @brief Returns the `NSOpenGLContext` of the specified window. * * @return The `NSOpenGLContext` of the specified window, or `nil` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_PLATFORM_UNAVAILABLE and @ref GLFW_NO_WINDOW_CONTEXT. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.0. * * @ingroup native */ GLFWAPI id glfwGetNSGLContext(GLFWwindow* window); #endif #if defined(GLFW_EXPOSE_NATIVE_X11) /*! @brief Returns the `Display` used by GLFW. * * @return The `Display` used by GLFW, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_UNAVAILABLE. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.0. * * @ingroup native */ GLFWAPI Display* glfwGetX11Display(void); /*! @brief Returns the `RRCrtc` of the specified monitor. * * @return The `RRCrtc` of the specified monitor, or `None` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_UNAVAILABLE. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.1. * * @ingroup native */ GLFWAPI RRCrtc glfwGetX11Adapter(GLFWmonitor* monitor); /*! @brief Returns the `RROutput` of the specified monitor. * * @return The `RROutput` of the specified monitor, or `None` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_UNAVAILABLE. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.1. * * @ingroup native */ GLFWAPI RROutput glfwGetX11Monitor(GLFWmonitor* monitor); /*! @brief Returns the `Window` of the specified window. * * @return The `Window` of the specified window, or `None` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_UNAVAILABLE. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.0. * * @ingroup native */ GLFWAPI Window glfwGetX11Window(GLFWwindow* window); /*! @brief Sets the current primary selection to the specified string. * * @param[in] string A UTF-8 encoded string. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_PLATFORM_UNAVAILABLE and @ref GLFW_PLATFORM_ERROR. * * @pointer_lifetime The specified string is copied before this function * returns. * * @thread_safety This function must only be called from the main thread. * * @sa @ref clipboard * @sa glfwGetX11SelectionString * @sa glfwSetClipboardString * * @since Added in version 3.3. * * @ingroup native */ GLFWAPI void glfwSetX11SelectionString(const char* string); /*! @brief Returns the contents of the current primary selection as a string. * * If the selection is empty or if its contents cannot be converted, `NULL` * is returned and a @ref GLFW_FORMAT_UNAVAILABLE error is generated. * * @return The contents of the selection as a UTF-8 encoded string, or `NULL` * if an [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_PLATFORM_UNAVAILABLE and @ref GLFW_PLATFORM_ERROR. * * @pointer_lifetime The returned string is allocated and freed by GLFW. You * should not free it yourself. It is valid until the next call to @ref * glfwGetX11SelectionString or @ref glfwSetX11SelectionString, or until the * library is terminated. * * @thread_safety This function must only be called from the main thread. * * @sa @ref clipboard * @sa glfwSetX11SelectionString * @sa glfwGetClipboardString * * @since Added in version 3.3. * * @ingroup native */ GLFWAPI const char* glfwGetX11SelectionString(void); #endif #if defined(GLFW_EXPOSE_NATIVE_GLX) /*! @brief Returns the `GLXContext` of the specified window. * * @return The `GLXContext` of the specified window, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_NO_WINDOW_CONTEXT and @ref GLFW_PLATFORM_UNAVAILABLE. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.0. * * @ingroup native */ GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* window); /*! @brief Returns the `GLXWindow` of the specified window. * * @return The `GLXWindow` of the specified window, or `None` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_NO_WINDOW_CONTEXT and @ref GLFW_PLATFORM_UNAVAILABLE. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.2. * * @ingroup native */ GLFWAPI GLXWindow glfwGetGLXWindow(GLFWwindow* window); #endif #if defined(GLFW_EXPOSE_NATIVE_WAYLAND) /*! @brief Returns the `struct wl_display*` used by GLFW. * * @return The `struct wl_display*` used by GLFW, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_UNAVAILABLE. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.2. * * @ingroup native */ GLFWAPI struct wl_display* glfwGetWaylandDisplay(void); /*! @brief Returns the `struct wl_output*` of the specified monitor. * * @return The `struct wl_output*` of the specified monitor, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_UNAVAILABLE. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.2. * * @ingroup native */ GLFWAPI struct wl_output* glfwGetWaylandMonitor(GLFWmonitor* monitor); /*! @brief Returns the main `struct wl_surface*` of the specified window. * * @return The main `struct wl_surface*` of the specified window, or `NULL` if * an [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_UNAVAILABLE. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.2. * * @ingroup native */ GLFWAPI struct wl_surface* glfwGetWaylandWindow(GLFWwindow* window); #endif #if defined(GLFW_EXPOSE_NATIVE_EGL) /*! @brief Returns the `EGLDisplay` used by GLFW. * * @return The `EGLDisplay` used by GLFW, or `EGL_NO_DISPLAY` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @remark Because EGL is initialized on demand, this function will return * `EGL_NO_DISPLAY` until the first context has been created via EGL. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.0. * * @ingroup native */ GLFWAPI EGLDisplay glfwGetEGLDisplay(void); /*! @brief Returns the `EGLContext` of the specified window. * * @return The `EGLContext` of the specified window, or `EGL_NO_CONTEXT` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_NO_WINDOW_CONTEXT. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.0. * * @ingroup native */ GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* window); /*! @brief Returns the `EGLSurface` of the specified window. * * @return The `EGLSurface` of the specified window, or `EGL_NO_SURFACE` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_NO_WINDOW_CONTEXT. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.0. * * @ingroup native */ GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* window); #endif #if defined(GLFW_EXPOSE_NATIVE_OSMESA) /*! @brief Retrieves the color buffer associated with the specified window. * * @param[in] window The window whose color buffer to retrieve. * @param[out] width Where to store the width of the color buffer, or `NULL`. * @param[out] height Where to store the height of the color buffer, or `NULL`. * @param[out] format Where to store the OSMesa pixel format of the color * buffer, or `NULL`. * @param[out] buffer Where to store the address of the color buffer, or * `NULL`. * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_NO_WINDOW_CONTEXT. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.3. * * @ingroup native */ GLFWAPI int glfwGetOSMesaColorBuffer(GLFWwindow* window, int* width, int* height, int* format, void** buffer); /*! @brief Retrieves the depth buffer associated with the specified window. * * @param[in] window The window whose depth buffer to retrieve. * @param[out] width Where to store the width of the depth buffer, or `NULL`. * @param[out] height Where to store the height of the depth buffer, or `NULL`. * @param[out] bytesPerValue Where to store the number of bytes per depth * buffer element, or `NULL`. * @param[out] buffer Where to store the address of the depth buffer, or * `NULL`. * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_NO_WINDOW_CONTEXT. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.3. * * @ingroup native */ GLFWAPI int glfwGetOSMesaDepthBuffer(GLFWwindow* window, int* width, int* height, int* bytesPerValue, void** buffer); /*! @brief Returns the `OSMesaContext` of the specified window. * * @return The `OSMesaContext` of the specified window, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_NO_WINDOW_CONTEXT. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @since Added in version 3.3. * * @ingroup native */ GLFWAPI OSMesaContext glfwGetOSMesaContext(GLFWwindow* window); #endif #ifdef __cplusplus } #endif #endif /* _glfw3_native_h_ */
0
repos/Zig-binding-GLFW-OpemGL-tutorial/include
repos/Zig-binding-GLFW-OpemGL-tutorial/include/GLFW/glfw3.h
/************************************************************************* * GLFW 3.4 - www.glfw.org * A library for OpenGL, window and input *------------------------------------------------------------------------ * Copyright (c) 2002-2006 Marcus Geelnard * Copyright (c) 2006-2019 Camilla Löwy <[email protected]> * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would * be appreciated but is not required. * * 2. Altered source versions must be plainly marked as such, and must not * be misrepresented as being the original software. * * 3. This notice may not be removed or altered from any source * distribution. * *************************************************************************/ #ifndef _glfw3_h_ #define _glfw3_h_ #ifdef __cplusplus extern "C" { #endif /************************************************************************* * Doxygen documentation *************************************************************************/ /*! @file glfw3.h * @brief The header of the GLFW 3 API. * * This is the header file of the GLFW 3 API. It defines all its types and * declares all its functions. * * For more information about how to use this file, see @ref build_include. */ /*! @defgroup context Context reference * @brief Functions and types related to OpenGL and OpenGL ES contexts. * * This is the reference documentation for OpenGL and OpenGL ES context related * functions. For more task-oriented information, see the @ref context_guide. */ /*! @defgroup vulkan Vulkan support reference * @brief Functions and types related to Vulkan. * * This is the reference documentation for Vulkan related functions and types. * For more task-oriented information, see the @ref vulkan_guide. */ /*! @defgroup init Initialization, version and error reference * @brief Functions and types related to initialization and error handling. * * This is the reference documentation for initialization and termination of * the library, version management and error handling. For more task-oriented * information, see the @ref intro_guide. */ /*! @defgroup input Input reference * @brief Functions and types related to input handling. * * This is the reference documentation for input related functions and types. * For more task-oriented information, see the @ref input_guide. */ /*! @defgroup monitor Monitor reference * @brief Functions and types related to monitors. * * This is the reference documentation for monitor related functions and types. * For more task-oriented information, see the @ref monitor_guide. */ /*! @defgroup window Window reference * @brief Functions and types related to windows. * * This is the reference documentation for window related functions and types, * including creation, deletion and event polling. For more task-oriented * information, see the @ref window_guide. */ /************************************************************************* * Compiler- and platform-specific preprocessor work *************************************************************************/ /* If we are we on Windows, we want a single define for it. */ #if !defined(_WIN32) && (defined(__WIN32__) || defined(WIN32) || defined(__MINGW32__)) #define _WIN32 #endif /* _WIN32 */ /* Include because most Windows GLU headers need wchar_t and * the macOS OpenGL header blocks the definition of ptrdiff_t by glext.h. * Include it unconditionally to avoid surprising side-effects. */ #include <stddef.h> /* Include because it is needed by Vulkan and related functions. * Include it unconditionally to avoid surprising side-effects. */ #include <stdint.h> #if defined(GLFW_INCLUDE_VULKAN) #include <vulkan/vulkan.h> #endif /* Vulkan header */ /* The Vulkan header may have indirectly included windows.h (because of * VK_USE_PLATFORM_WIN32_KHR) so we offer our replacement symbols after it. */ /* It is customary to use APIENTRY for OpenGL function pointer declarations on * all platforms. Additionally, the Windows OpenGL header needs APIENTRY. */ #if !defined(APIENTRY) #if defined(_WIN32) #define APIENTRY __stdcall #else #define APIENTRY #endif #define GLFW_APIENTRY_DEFINED #endif /* APIENTRY */ /* Some Windows OpenGL headers need this. */ #if !defined(WINGDIAPI) && defined(_WIN32) #define WINGDIAPI __declspec(dllimport) #define GLFW_WINGDIAPI_DEFINED #endif /* WINGDIAPI */ /* Some Windows GLU headers need this. */ #if !defined(CALLBACK) && defined(_WIN32) #define CALLBACK __stdcall #define GLFW_CALLBACK_DEFINED #endif /* CALLBACK */ /* Include the chosen OpenGL or OpenGL ES headers. */ #if defined(GLFW_INCLUDE_ES1) #include <GLES/gl.h> #if defined(GLFW_INCLUDE_GLEXT) #include <GLES/glext.h> #endif #elif defined(GLFW_INCLUDE_ES2) #include <GLES2/gl2.h> #if defined(GLFW_INCLUDE_GLEXT) #include <GLES2/gl2ext.h> #endif #elif defined(GLFW_INCLUDE_ES3) #include <GLES3/gl3.h> #if defined(GLFW_INCLUDE_GLEXT) #include <GLES2/gl2ext.h> #endif #elif defined(GLFW_INCLUDE_ES31) #include <GLES3/gl31.h> #if defined(GLFW_INCLUDE_GLEXT) #include <GLES2/gl2ext.h> #endif #elif defined(GLFW_INCLUDE_ES32) #include <GLES3/gl32.h> #if defined(GLFW_INCLUDE_GLEXT) #include <GLES2/gl2ext.h> #endif #elif defined(GLFW_INCLUDE_GLCOREARB) #if defined(__APPLE__) #include <OpenGL/gl3.h> #if defined(GLFW_INCLUDE_GLEXT) #include <OpenGL/gl3ext.h> #endif /*GLFW_INCLUDE_GLEXT*/ #else /*__APPLE__*/ #include <GL/glcorearb.h> #if defined(GLFW_INCLUDE_GLEXT) #include <GL/glext.h> #endif #endif /*__APPLE__*/ #elif defined(GLFW_INCLUDE_GLU) #if defined(__APPLE__) #if defined(GLFW_INCLUDE_GLU) #include <OpenGL/glu.h> #endif #else /*__APPLE__*/ #if defined(GLFW_INCLUDE_GLU) #include <GL/glu.h> #endif #endif /*__APPLE__*/ #elif !defined(GLFW_INCLUDE_NONE) && \ !defined(__gl_h_) && \ !defined(__gles1_gl_h_) && \ !defined(__gles2_gl2_h_) && \ !defined(__gles2_gl3_h_) && \ !defined(__gles2_gl31_h_) && \ !defined(__gles2_gl32_h_) && \ !defined(__gl_glcorearb_h_) && \ !defined(__gl2_h_) /*legacy*/ && \ !defined(__gl3_h_) /*legacy*/ && \ !defined(__gl31_h_) /*legacy*/ && \ !defined(__gl32_h_) /*legacy*/ && \ !defined(__glcorearb_h_) /*legacy*/ && \ !defined(__GL_H__) /*non-standard*/ && \ !defined(__gltypes_h_) /*non-standard*/ && \ !defined(__glee_h_) /*non-standard*/ #if defined(__APPLE__) #if !defined(GLFW_INCLUDE_GLEXT) #define GL_GLEXT_LEGACY #endif #include <OpenGL/gl.h> #else /*__APPLE__*/ #include <GL/gl.h> #if defined(GLFW_INCLUDE_GLEXT) #include <GL/glext.h> #endif #endif /*__APPLE__*/ #endif /* OpenGL and OpenGL ES headers */ #if defined(GLFW_DLL) && defined(_GLFW_BUILD_DLL) /* GLFW_DLL must be defined by applications that are linking against the DLL * version of the GLFW library. _GLFW_BUILD_DLL is defined by the GLFW * configuration header when compiling the DLL version of the library. */ #error "You must not have both GLFW_DLL and _GLFW_BUILD_DLL defined" #endif /* GLFWAPI is used to declare public API functions for export * from the DLL / shared library / dynamic library. */ #if defined(_WIN32) && defined(_GLFW_BUILD_DLL) /* We are building GLFW as a Win32 DLL */ #define GLFWAPI __declspec(dllexport) #elif defined(_WIN32) && defined(GLFW_DLL) /* We are calling a GLFW Win32 DLL */ #define GLFWAPI __declspec(dllimport) #elif defined(__GNUC__) && defined(_GLFW_BUILD_DLL) /* We are building GLFW as a Unix shared library */ #define GLFWAPI __attribute__((visibility("default"))) #else #define GLFWAPI #endif /************************************************************************* * GLFW API tokens *************************************************************************/ /*! @name GLFW version macros * @{ */ /*! @brief The major version number of the GLFW header. * * The major version number of the GLFW header. This is incremented when the * API is changed in non-compatible ways. * @ingroup init */ #define GLFW_VERSION_MAJOR 3 /*! @brief The minor version number of the GLFW header. * * The minor version number of the GLFW header. This is incremented when * features are added to the API but it remains backward-compatible. * @ingroup init */ #define GLFW_VERSION_MINOR 4 /*! @brief The revision number of the GLFW header. * * The revision number of the GLFW header. This is incremented when a bug fix * release is made that does not contain any API changes. * @ingroup init */ #define GLFW_VERSION_REVISION 0 /*! @} */ /*! @brief One. * * This is only semantic sugar for the number 1. You can instead use `1` or * `true` or `_True` or `GL_TRUE` or `VK_TRUE` or anything else that is equal * to one. * * @ingroup init */ #define GLFW_TRUE 1 /*! @brief Zero. * * This is only semantic sugar for the number 0. You can instead use `0` or * `false` or `_False` or `GL_FALSE` or `VK_FALSE` or anything else that is * equal to zero. * * @ingroup init */ #define GLFW_FALSE 0 /*! @name Key and button actions * @{ */ /*! @brief The key or mouse button was released. * * The key or mouse button was released. * * @ingroup input */ #define GLFW_RELEASE 0 /*! @brief The key or mouse button was pressed. * * The key or mouse button was pressed. * * @ingroup input */ #define GLFW_PRESS 1 /*! @brief The key was held down until it repeated. * * The key was held down until it repeated. * * @ingroup input */ #define GLFW_REPEAT 2 /*! @} */ /*! @defgroup hat_state Joystick hat states * @brief Joystick hat states. * * See [joystick hat input](@ref joystick_hat) for how these are used. * * @ingroup input * @{ */ #define GLFW_HAT_CENTERED 0 #define GLFW_HAT_UP 1 #define GLFW_HAT_RIGHT 2 #define GLFW_HAT_DOWN 4 #define GLFW_HAT_LEFT 8 #define GLFW_HAT_RIGHT_UP (GLFW_HAT_RIGHT | GLFW_HAT_UP) #define GLFW_HAT_RIGHT_DOWN (GLFW_HAT_RIGHT | GLFW_HAT_DOWN) #define GLFW_HAT_LEFT_UP (GLFW_HAT_LEFT | GLFW_HAT_UP) #define GLFW_HAT_LEFT_DOWN (GLFW_HAT_LEFT | GLFW_HAT_DOWN) /*! @ingroup input */ #define GLFW_KEY_UNKNOWN -1 /*! @} */ /*! @defgroup keys Keyboard key tokens * @brief Keyboard key tokens. * * See [key input](@ref input_key) for how these are used. * * These key codes are inspired by the _USB HID Usage Tables v1.12_ (p. 53-60), * but re-arranged to map to 7-bit ASCII for printable keys (function keys are * put in the 256+ range). * * The naming of the key codes follow these rules: * - The US keyboard layout is used * - Names of printable alphanumeric characters are used (e.g. "A", "R", * "3", etc.) * - For non-alphanumeric characters, Unicode:ish names are used (e.g. * "COMMA", "LEFT_SQUARE_BRACKET", etc.). Note that some names do not * correspond to the Unicode standard (usually for brevity) * - Keys that lack a clear US mapping are named "WORLD_x" * - For non-printable keys, custom names are used (e.g. "F4", * "BACKSPACE", etc.) * * @ingroup input * @{ */ /* Printable keys */ #define GLFW_KEY_SPACE 32 #define GLFW_KEY_APOSTROPHE 39 /* ' */ #define GLFW_KEY_COMMA 44 /* , */ #define GLFW_KEY_MINUS 45 /* - */ #define GLFW_KEY_PERIOD 46 /* . */ #define GLFW_KEY_SLASH 47 /* / */ #define GLFW_KEY_0 48 #define GLFW_KEY_1 49 #define GLFW_KEY_2 50 #define GLFW_KEY_3 51 #define GLFW_KEY_4 52 #define GLFW_KEY_5 53 #define GLFW_KEY_6 54 #define GLFW_KEY_7 55 #define GLFW_KEY_8 56 #define GLFW_KEY_9 57 #define GLFW_KEY_SEMICOLON 59 /* ; */ #define GLFW_KEY_EQUAL 61 /* = */ #define GLFW_KEY_A 65 #define GLFW_KEY_B 66 #define GLFW_KEY_C 67 #define GLFW_KEY_D 68 #define GLFW_KEY_E 69 #define GLFW_KEY_F 70 #define GLFW_KEY_G 71 #define GLFW_KEY_H 72 #define GLFW_KEY_I 73 #define GLFW_KEY_J 74 #define GLFW_KEY_K 75 #define GLFW_KEY_L 76 #define GLFW_KEY_M 77 #define GLFW_KEY_N 78 #define GLFW_KEY_O 79 #define GLFW_KEY_P 80 #define GLFW_KEY_Q 81 #define GLFW_KEY_R 82 #define GLFW_KEY_S 83 #define GLFW_KEY_T 84 #define GLFW_KEY_U 85 #define GLFW_KEY_V 86 #define GLFW_KEY_W 87 #define GLFW_KEY_X 88 #define GLFW_KEY_Y 89 #define GLFW_KEY_Z 90 #define GLFW_KEY_LEFT_BRACKET 91 /* [ */ #define GLFW_KEY_BACKSLASH 92 /* \ */ #define GLFW_KEY_RIGHT_BRACKET 93 /* ] */ #define GLFW_KEY_GRAVE_ACCENT 96 /* ` */ #define GLFW_KEY_WORLD_1 161 /* non-US #1 */ #define GLFW_KEY_WORLD_2 162 /* non-US #2 */ /* Function keys */ #define GLFW_KEY_ESCAPE 256 #define GLFW_KEY_ENTER 257 #define GLFW_KEY_TAB 258 #define GLFW_KEY_BACKSPACE 259 #define GLFW_KEY_INSERT 260 #define GLFW_KEY_DELETE 261 #define GLFW_KEY_RIGHT 262 #define GLFW_KEY_LEFT 263 #define GLFW_KEY_DOWN 264 #define GLFW_KEY_UP 265 #define GLFW_KEY_PAGE_UP 266 #define GLFW_KEY_PAGE_DOWN 267 #define GLFW_KEY_HOME 268 #define GLFW_KEY_END 269 #define GLFW_KEY_CAPS_LOCK 280 #define GLFW_KEY_SCROLL_LOCK 281 #define GLFW_KEY_NUM_LOCK 282 #define GLFW_KEY_PRINT_SCREEN 283 #define GLFW_KEY_PAUSE 284 #define GLFW_KEY_F1 290 #define GLFW_KEY_F2 291 #define GLFW_KEY_F3 292 #define GLFW_KEY_F4 293 #define GLFW_KEY_F5 294 #define GLFW_KEY_F6 295 #define GLFW_KEY_F7 296 #define GLFW_KEY_F8 297 #define GLFW_KEY_F9 298 #define GLFW_KEY_F10 299 #define GLFW_KEY_F11 300 #define GLFW_KEY_F12 301 #define GLFW_KEY_F13 302 #define GLFW_KEY_F14 303 #define GLFW_KEY_F15 304 #define GLFW_KEY_F16 305 #define GLFW_KEY_F17 306 #define GLFW_KEY_F18 307 #define GLFW_KEY_F19 308 #define GLFW_KEY_F20 309 #define GLFW_KEY_F21 310 #define GLFW_KEY_F22 311 #define GLFW_KEY_F23 312 #define GLFW_KEY_F24 313 #define GLFW_KEY_F25 314 #define GLFW_KEY_KP_0 320 #define GLFW_KEY_KP_1 321 #define GLFW_KEY_KP_2 322 #define GLFW_KEY_KP_3 323 #define GLFW_KEY_KP_4 324 #define GLFW_KEY_KP_5 325 #define GLFW_KEY_KP_6 326 #define GLFW_KEY_KP_7 327 #define GLFW_KEY_KP_8 328 #define GLFW_KEY_KP_9 329 #define GLFW_KEY_KP_DECIMAL 330 #define GLFW_KEY_KP_DIVIDE 331 #define GLFW_KEY_KP_MULTIPLY 332 #define GLFW_KEY_KP_SUBTRACT 333 #define GLFW_KEY_KP_ADD 334 #define GLFW_KEY_KP_ENTER 335 #define GLFW_KEY_KP_EQUAL 336 #define GLFW_KEY_LEFT_SHIFT 340 #define GLFW_KEY_LEFT_CONTROL 341 #define GLFW_KEY_LEFT_ALT 342 #define GLFW_KEY_LEFT_SUPER 343 #define GLFW_KEY_RIGHT_SHIFT 344 #define GLFW_KEY_RIGHT_CONTROL 345 #define GLFW_KEY_RIGHT_ALT 346 #define GLFW_KEY_RIGHT_SUPER 347 #define GLFW_KEY_MENU 348 #define GLFW_KEY_LAST GLFW_KEY_MENU /*! @} */ /*! @defgroup mods Modifier key flags * @brief Modifier key flags. * * See [key input](@ref input_key) for how these are used. * * @ingroup input * @{ */ /*! @brief If this bit is set one or more Shift keys were held down. * * If this bit is set one or more Shift keys were held down. */ #define GLFW_MOD_SHIFT 0x0001 /*! @brief If this bit is set one or more Control keys were held down. * * If this bit is set one or more Control keys were held down. */ #define GLFW_MOD_CONTROL 0x0002 /*! @brief If this bit is set one or more Alt keys were held down. * * If this bit is set one or more Alt keys were held down. */ #define GLFW_MOD_ALT 0x0004 /*! @brief If this bit is set one or more Super keys were held down. * * If this bit is set one or more Super keys were held down. */ #define GLFW_MOD_SUPER 0x0008 /*! @brief If this bit is set the Caps Lock key is enabled. * * If this bit is set the Caps Lock key is enabled and the @ref * GLFW_LOCK_KEY_MODS input mode is set. */ #define GLFW_MOD_CAPS_LOCK 0x0010 /*! @brief If this bit is set the Num Lock key is enabled. * * If this bit is set the Num Lock key is enabled and the @ref * GLFW_LOCK_KEY_MODS input mode is set. */ #define GLFW_MOD_NUM_LOCK 0x0020 /*! @} */ /*! @defgroup buttons Mouse buttons * @brief Mouse button IDs. * * See [mouse button input](@ref input_mouse_button) for how these are used. * * @ingroup input * @{ */ #define GLFW_MOUSE_BUTTON_1 0 #define GLFW_MOUSE_BUTTON_2 1 #define GLFW_MOUSE_BUTTON_3 2 #define GLFW_MOUSE_BUTTON_4 3 #define GLFW_MOUSE_BUTTON_5 4 #define GLFW_MOUSE_BUTTON_6 5 #define GLFW_MOUSE_BUTTON_7 6 #define GLFW_MOUSE_BUTTON_8 7 #define GLFW_MOUSE_BUTTON_LAST GLFW_MOUSE_BUTTON_8 #define GLFW_MOUSE_BUTTON_LEFT GLFW_MOUSE_BUTTON_1 #define GLFW_MOUSE_BUTTON_RIGHT GLFW_MOUSE_BUTTON_2 #define GLFW_MOUSE_BUTTON_MIDDLE GLFW_MOUSE_BUTTON_3 /*! @} */ /*! @defgroup joysticks Joysticks * @brief Joystick IDs. * * See [joystick input](@ref joystick) for how these are used. * * @ingroup input * @{ */ #define GLFW_JOYSTICK_1 0 #define GLFW_JOYSTICK_2 1 #define GLFW_JOYSTICK_3 2 #define GLFW_JOYSTICK_4 3 #define GLFW_JOYSTICK_5 4 #define GLFW_JOYSTICK_6 5 #define GLFW_JOYSTICK_7 6 #define GLFW_JOYSTICK_8 7 #define GLFW_JOYSTICK_9 8 #define GLFW_JOYSTICK_10 9 #define GLFW_JOYSTICK_11 10 #define GLFW_JOYSTICK_12 11 #define GLFW_JOYSTICK_13 12 #define GLFW_JOYSTICK_14 13 #define GLFW_JOYSTICK_15 14 #define GLFW_JOYSTICK_16 15 #define GLFW_JOYSTICK_LAST GLFW_JOYSTICK_16 /*! @} */ /*! @defgroup gamepad_buttons Gamepad buttons * @brief Gamepad buttons. * * See @ref gamepad for how these are used. * * @ingroup input * @{ */ #define GLFW_GAMEPAD_BUTTON_A 0 #define GLFW_GAMEPAD_BUTTON_B 1 #define GLFW_GAMEPAD_BUTTON_X 2 #define GLFW_GAMEPAD_BUTTON_Y 3 #define GLFW_GAMEPAD_BUTTON_LEFT_BUMPER 4 #define GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER 5 #define GLFW_GAMEPAD_BUTTON_BACK 6 #define GLFW_GAMEPAD_BUTTON_START 7 #define GLFW_GAMEPAD_BUTTON_GUIDE 8 #define GLFW_GAMEPAD_BUTTON_LEFT_THUMB 9 #define GLFW_GAMEPAD_BUTTON_RIGHT_THUMB 10 #define GLFW_GAMEPAD_BUTTON_DPAD_UP 11 #define GLFW_GAMEPAD_BUTTON_DPAD_RIGHT 12 #define GLFW_GAMEPAD_BUTTON_DPAD_DOWN 13 #define GLFW_GAMEPAD_BUTTON_DPAD_LEFT 14 #define GLFW_GAMEPAD_BUTTON_LAST GLFW_GAMEPAD_BUTTON_DPAD_LEFT #define GLFW_GAMEPAD_BUTTON_CROSS GLFW_GAMEPAD_BUTTON_A #define GLFW_GAMEPAD_BUTTON_CIRCLE GLFW_GAMEPAD_BUTTON_B #define GLFW_GAMEPAD_BUTTON_SQUARE GLFW_GAMEPAD_BUTTON_X #define GLFW_GAMEPAD_BUTTON_TRIANGLE GLFW_GAMEPAD_BUTTON_Y /*! @} */ /*! @defgroup gamepad_axes Gamepad axes * @brief Gamepad axes. * * See @ref gamepad for how these are used. * * @ingroup input * @{ */ #define GLFW_GAMEPAD_AXIS_LEFT_X 0 #define GLFW_GAMEPAD_AXIS_LEFT_Y 1 #define GLFW_GAMEPAD_AXIS_RIGHT_X 2 #define GLFW_GAMEPAD_AXIS_RIGHT_Y 3 #define GLFW_GAMEPAD_AXIS_LEFT_TRIGGER 4 #define GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER 5 #define GLFW_GAMEPAD_AXIS_LAST GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER /*! @} */ /*! @defgroup errors Error codes * @brief Error codes. * * See [error handling](@ref error_handling) for how these are used. * * @ingroup init * @{ */ /*! @brief No error has occurred. * * No error has occurred. * * @analysis Yay. */ #define GLFW_NO_ERROR 0 /*! @brief GLFW has not been initialized. * * This occurs if a GLFW function was called that must not be called unless the * library is [initialized](@ref intro_init). * * @analysis Application programmer error. Initialize GLFW before calling any * function that requires initialization. */ #define GLFW_NOT_INITIALIZED 0x00010001 /*! @brief No context is current for this thread. * * This occurs if a GLFW function was called that needs and operates on the * current OpenGL or OpenGL ES context but no context is current on the calling * thread. One such function is @ref glfwSwapInterval. * * @analysis Application programmer error. Ensure a context is current before * calling functions that require a current context. */ #define GLFW_NO_CURRENT_CONTEXT 0x00010002 /*! @brief One of the arguments to the function was an invalid enum value. * * One of the arguments to the function was an invalid enum value, for example * requesting @ref GLFW_RED_BITS with @ref glfwGetWindowAttrib. * * @analysis Application programmer error. Fix the offending call. */ #define GLFW_INVALID_ENUM 0x00010003 /*! @brief One of the arguments to the function was an invalid value. * * One of the arguments to the function was an invalid value, for example * requesting a non-existent OpenGL or OpenGL ES version like 2.7. * * Requesting a valid but unavailable OpenGL or OpenGL ES version will instead * result in a @ref GLFW_VERSION_UNAVAILABLE error. * * @analysis Application programmer error. Fix the offending call. */ #define GLFW_INVALID_VALUE 0x00010004 /*! @brief A memory allocation failed. * * A memory allocation failed. * * @analysis A bug in GLFW or the underlying operating system. Report the bug * to our [issue tracker](https://github.com/glfw/glfw/issues). */ #define GLFW_OUT_OF_MEMORY 0x00010005 /*! @brief GLFW could not find support for the requested API on the system. * * GLFW could not find support for the requested API on the system. * * @analysis The installed graphics driver does not support the requested * API, or does not support it via the chosen context creation API. * Below are a few examples. * * @par * Some pre-installed Windows graphics drivers do not support OpenGL. AMD only * supports OpenGL ES via EGL, while Nvidia and Intel only support it via * a WGL or GLX extension. macOS does not provide OpenGL ES at all. The Mesa * EGL, OpenGL and OpenGL ES libraries do not interface with the Nvidia binary * driver. Older graphics drivers do not support Vulkan. */ #define GLFW_API_UNAVAILABLE 0x00010006 /*! @brief The requested OpenGL or OpenGL ES version is not available. * * The requested OpenGL or OpenGL ES version (including any requested context * or framebuffer hints) is not available on this machine. * * @analysis The machine does not support your requirements. If your * application is sufficiently flexible, downgrade your requirements and try * again. Otherwise, inform the user that their machine does not match your * requirements. * * @par * Future invalid OpenGL and OpenGL ES versions, for example OpenGL 4.8 if 5.0 * comes out before the 4.x series gets that far, also fail with this error and * not @ref GLFW_INVALID_VALUE, because GLFW cannot know what future versions * will exist. */ #define GLFW_VERSION_UNAVAILABLE 0x00010007 /*! @brief A platform-specific error occurred that does not match any of the * more specific categories. * * A platform-specific error occurred that does not match any of the more * specific categories. * * @analysis A bug or configuration error in GLFW, the underlying operating * system or its drivers, or a lack of required resources. Report the issue to * our [issue tracker](https://github.com/glfw/glfw/issues). */ #define GLFW_PLATFORM_ERROR 0x00010008 /*! @brief The requested format is not supported or available. * * If emitted during window creation, the requested pixel format is not * supported. * * If emitted when querying the clipboard, the contents of the clipboard could * not be converted to the requested format. * * @analysis If emitted during window creation, one or more * [hard constraints](@ref window_hints_hard) did not match any of the * available pixel formats. If your application is sufficiently flexible, * downgrade your requirements and try again. Otherwise, inform the user that * their machine does not match your requirements. * * @par * If emitted when querying the clipboard, ignore the error or report it to * the user, as appropriate. */ #define GLFW_FORMAT_UNAVAILABLE 0x00010009 /*! @brief The specified window does not have an OpenGL or OpenGL ES context. * * A window that does not have an OpenGL or OpenGL ES context was passed to * a function that requires it to have one. * * @analysis Application programmer error. Fix the offending call. */ #define GLFW_NO_WINDOW_CONTEXT 0x0001000A /*! @brief The specified cursor shape is not available. * * The specified standard cursor shape is not available, either because the * current platform cursor theme does not provide it or because it is not * available on the platform. * * @analysis Platform or system settings limitation. Pick another * [standard cursor shape](@ref shapes) or create a * [custom cursor](@ref cursor_custom). */ #define GLFW_CURSOR_UNAVAILABLE 0x0001000B /*! @brief The requested feature is not provided by the platform. * * The requested feature is not provided by the platform, so GLFW is unable to * implement it. The documentation for each function notes if it could emit * this error. * * @analysis Platform or platform version limitation. The error can be ignored * unless the feature is critical to the application. * * @par * A function call that emits this error has no effect other than the error and * updating any existing out parameters. */ #define GLFW_FEATURE_UNAVAILABLE 0x0001000C /*! @brief The requested feature is not implemented for the platform. * * The requested feature has not yet been implemented in GLFW for this platform. * * @analysis An incomplete implementation of GLFW for this platform, hopefully * fixed in a future release. The error can be ignored unless the feature is * critical to the application. * * @par * A function call that emits this error has no effect other than the error and * updating any existing out parameters. */ #define GLFW_FEATURE_UNIMPLEMENTED 0x0001000D /*! @brief Platform unavailable or no matching platform was found. * * If emitted during initialization, no matching platform was found. If the @ref * GLFW_PLATFORM init hint was set to `GLFW_ANY_PLATFORM`, GLFW could not detect any of * the platforms supported by this library binary, except for the Null platform. If the * init hint was set to a specific platform, it is either not supported by this library * binary or GLFW was not able to detect it. * * If emitted by a native access function, GLFW was initialized for a different platform * than the function is for. * * @analysis Failure to detect any platform usually only happens on non-macOS Unix * systems, either when no window system is running or the program was run from * a terminal that does not have the necessary environment variables. Fall back to * a different platform if possible or notify the user that no usable platform was * detected. * * Failure to detect a specific platform may have the same cause as above or be because * support for that platform was not compiled in. Call @ref glfwPlatformSupported to * check whether a specific platform is supported by a library binary. */ #define GLFW_PLATFORM_UNAVAILABLE 0x0001000E /*! @} */ /*! @addtogroup window * @{ */ /*! @brief Input focus window hint and attribute * * Input focus [window hint](@ref GLFW_FOCUSED_hint) or * [window attribute](@ref GLFW_FOCUSED_attrib). */ #define GLFW_FOCUSED 0x00020001 /*! @brief Window iconification window attribute * * Window iconification [window attribute](@ref GLFW_ICONIFIED_attrib). */ #define GLFW_ICONIFIED 0x00020002 /*! @brief Window resize-ability window hint and attribute * * Window resize-ability [window hint](@ref GLFW_RESIZABLE_hint) and * [window attribute](@ref GLFW_RESIZABLE_attrib). */ #define GLFW_RESIZABLE 0x00020003 /*! @brief Window visibility window hint and attribute * * Window visibility [window hint](@ref GLFW_VISIBLE_hint) and * [window attribute](@ref GLFW_VISIBLE_attrib). */ #define GLFW_VISIBLE 0x00020004 /*! @brief Window decoration window hint and attribute * * Window decoration [window hint](@ref GLFW_DECORATED_hint) and * [window attribute](@ref GLFW_DECORATED_attrib). */ #define GLFW_DECORATED 0x00020005 /*! @brief Window auto-iconification window hint and attribute * * Window auto-iconification [window hint](@ref GLFW_AUTO_ICONIFY_hint) and * [window attribute](@ref GLFW_AUTO_ICONIFY_attrib). */ #define GLFW_AUTO_ICONIFY 0x00020006 /*! @brief Window decoration window hint and attribute * * Window decoration [window hint](@ref GLFW_FLOATING_hint) and * [window attribute](@ref GLFW_FLOATING_attrib). */ #define GLFW_FLOATING 0x00020007 /*! @brief Window maximization window hint and attribute * * Window maximization [window hint](@ref GLFW_MAXIMIZED_hint) and * [window attribute](@ref GLFW_MAXIMIZED_attrib). */ #define GLFW_MAXIMIZED 0x00020008 /*! @brief Cursor centering window hint * * Cursor centering [window hint](@ref GLFW_CENTER_CURSOR_hint). */ #define GLFW_CENTER_CURSOR 0x00020009 /*! @brief Window framebuffer transparency hint and attribute * * Window framebuffer transparency * [window hint](@ref GLFW_TRANSPARENT_FRAMEBUFFER_hint) and * [window attribute](@ref GLFW_TRANSPARENT_FRAMEBUFFER_attrib). */ #define GLFW_TRANSPARENT_FRAMEBUFFER 0x0002000A /*! @brief Mouse cursor hover window attribute. * * Mouse cursor hover [window attribute](@ref GLFW_HOVERED_attrib). */ #define GLFW_HOVERED 0x0002000B /*! @brief Input focus on calling show window hint and attribute * * Input focus [window hint](@ref GLFW_FOCUS_ON_SHOW_hint) or * [window attribute](@ref GLFW_FOCUS_ON_SHOW_attrib). */ #define GLFW_FOCUS_ON_SHOW 0x0002000C /*! @brief Mouse input transparency window hint and attribute * * Mouse input transparency [window hint](@ref GLFW_MOUSE_PASSTHROUGH_hint) or * [window attribute](@ref GLFW_MOUSE_PASSTHROUGH_attrib). */ #define GLFW_MOUSE_PASSTHROUGH 0x0002000D /*! @brief Initial position x-coordinate window hint. * * Initial position x-coordinate [window hint](@ref GLFW_POSITION_X). */ #define GLFW_POSITION_X 0x0002000E /*! @brief Initial position y-coordinate window hint. * * Initial position y-coordinate [window hint](@ref GLFW_POSITION_Y). */ #define GLFW_POSITION_Y 0x0002000F /*! @brief Framebuffer bit depth hint. * * Framebuffer bit depth [hint](@ref GLFW_RED_BITS). */ #define GLFW_RED_BITS 0x00021001 /*! @brief Framebuffer bit depth hint. * * Framebuffer bit depth [hint](@ref GLFW_GREEN_BITS). */ #define GLFW_GREEN_BITS 0x00021002 /*! @brief Framebuffer bit depth hint. * * Framebuffer bit depth [hint](@ref GLFW_BLUE_BITS). */ #define GLFW_BLUE_BITS 0x00021003 /*! @brief Framebuffer bit depth hint. * * Framebuffer bit depth [hint](@ref GLFW_ALPHA_BITS). */ #define GLFW_ALPHA_BITS 0x00021004 /*! @brief Framebuffer bit depth hint. * * Framebuffer bit depth [hint](@ref GLFW_DEPTH_BITS). */ #define GLFW_DEPTH_BITS 0x00021005 /*! @brief Framebuffer bit depth hint. * * Framebuffer bit depth [hint](@ref GLFW_STENCIL_BITS). */ #define GLFW_STENCIL_BITS 0x00021006 /*! @brief Framebuffer bit depth hint. * * Framebuffer bit depth [hint](@ref GLFW_ACCUM_RED_BITS). */ #define GLFW_ACCUM_RED_BITS 0x00021007 /*! @brief Framebuffer bit depth hint. * * Framebuffer bit depth [hint](@ref GLFW_ACCUM_GREEN_BITS). */ #define GLFW_ACCUM_GREEN_BITS 0x00021008 /*! @brief Framebuffer bit depth hint. * * Framebuffer bit depth [hint](@ref GLFW_ACCUM_BLUE_BITS). */ #define GLFW_ACCUM_BLUE_BITS 0x00021009 /*! @brief Framebuffer bit depth hint. * * Framebuffer bit depth [hint](@ref GLFW_ACCUM_ALPHA_BITS). */ #define GLFW_ACCUM_ALPHA_BITS 0x0002100A /*! @brief Framebuffer auxiliary buffer hint. * * Framebuffer auxiliary buffer [hint](@ref GLFW_AUX_BUFFERS). */ #define GLFW_AUX_BUFFERS 0x0002100B /*! @brief OpenGL stereoscopic rendering hint. * * OpenGL stereoscopic rendering [hint](@ref GLFW_STEREO). */ #define GLFW_STEREO 0x0002100C /*! @brief Framebuffer MSAA samples hint. * * Framebuffer MSAA samples [hint](@ref GLFW_SAMPLES). */ #define GLFW_SAMPLES 0x0002100D /*! @brief Framebuffer sRGB hint. * * Framebuffer sRGB [hint](@ref GLFW_SRGB_CAPABLE). */ #define GLFW_SRGB_CAPABLE 0x0002100E /*! @brief Monitor refresh rate hint. * * Monitor refresh rate [hint](@ref GLFW_REFRESH_RATE). */ #define GLFW_REFRESH_RATE 0x0002100F /*! @brief Framebuffer double buffering hint and attribute. * * Framebuffer double buffering [hint](@ref GLFW_DOUBLEBUFFER_hint) and * [attribute](@ref GLFW_DOUBLEBUFFER_attrib). */ #define GLFW_DOUBLEBUFFER 0x00021010 /*! @brief Context client API hint and attribute. * * Context client API [hint](@ref GLFW_CLIENT_API_hint) and * [attribute](@ref GLFW_CLIENT_API_attrib). */ #define GLFW_CLIENT_API 0x00022001 /*! @brief Context client API major version hint and attribute. * * Context client API major version [hint](@ref GLFW_CONTEXT_VERSION_MAJOR_hint) * and [attribute](@ref GLFW_CONTEXT_VERSION_MAJOR_attrib). */ #define GLFW_CONTEXT_VERSION_MAJOR 0x00022002 /*! @brief Context client API minor version hint and attribute. * * Context client API minor version [hint](@ref GLFW_CONTEXT_VERSION_MINOR_hint) * and [attribute](@ref GLFW_CONTEXT_VERSION_MINOR_attrib). */ #define GLFW_CONTEXT_VERSION_MINOR 0x00022003 /*! @brief Context client API revision number attribute. * * Context client API revision number * [attribute](@ref GLFW_CONTEXT_REVISION_attrib). */ #define GLFW_CONTEXT_REVISION 0x00022004 /*! @brief Context robustness hint and attribute. * * Context client API revision number [hint](@ref GLFW_CONTEXT_ROBUSTNESS_hint) * and [attribute](@ref GLFW_CONTEXT_ROBUSTNESS_attrib). */ #define GLFW_CONTEXT_ROBUSTNESS 0x00022005 /*! @brief OpenGL forward-compatibility hint and attribute. * * OpenGL forward-compatibility [hint](@ref GLFW_OPENGL_FORWARD_COMPAT_hint) * and [attribute](@ref GLFW_OPENGL_FORWARD_COMPAT_attrib). */ #define GLFW_OPENGL_FORWARD_COMPAT 0x00022006 /*! @brief Debug mode context hint and attribute. * * Debug mode context [hint](@ref GLFW_CONTEXT_DEBUG_hint) and * [attribute](@ref GLFW_CONTEXT_DEBUG_attrib). */ #define GLFW_CONTEXT_DEBUG 0x00022007 /*! @brief Legacy name for compatibility. * * This is an alias for compatibility with earlier versions. */ #define GLFW_OPENGL_DEBUG_CONTEXT GLFW_CONTEXT_DEBUG /*! @brief OpenGL profile hint and attribute. * * OpenGL profile [hint](@ref GLFW_OPENGL_PROFILE_hint) and * [attribute](@ref GLFW_OPENGL_PROFILE_attrib). */ #define GLFW_OPENGL_PROFILE 0x00022008 /*! @brief Context flush-on-release hint and attribute. * * Context flush-on-release [hint](@ref GLFW_CONTEXT_RELEASE_BEHAVIOR_hint) and * [attribute](@ref GLFW_CONTEXT_RELEASE_BEHAVIOR_attrib). */ #define GLFW_CONTEXT_RELEASE_BEHAVIOR 0x00022009 /*! @brief Context error suppression hint and attribute. * * Context error suppression [hint](@ref GLFW_CONTEXT_NO_ERROR_hint) and * [attribute](@ref GLFW_CONTEXT_NO_ERROR_attrib). */ #define GLFW_CONTEXT_NO_ERROR 0x0002200A /*! @brief Context creation API hint and attribute. * * Context creation API [hint](@ref GLFW_CONTEXT_CREATION_API_hint) and * [attribute](@ref GLFW_CONTEXT_CREATION_API_attrib). */ #define GLFW_CONTEXT_CREATION_API 0x0002200B /*! @brief Window content area scaling window * [window hint](@ref GLFW_SCALE_TO_MONITOR). */ #define GLFW_SCALE_TO_MONITOR 0x0002200C /*! @brief Window framebuffer scaling * [window hint](@ref GLFW_SCALE_FRAMEBUFFER_hint). */ #define GLFW_SCALE_FRAMEBUFFER 0x0002200D /*! @brief Legacy name for compatibility. * * This is an alias for the * [GLFW_SCALE_FRAMEBUFFER](@ref GLFW_SCALE_FRAMEBUFFER_hint) window hint for * compatibility with earlier versions. */ #define GLFW_COCOA_RETINA_FRAMEBUFFER 0x00023001 /*! @brief macOS specific * [window hint](@ref GLFW_COCOA_FRAME_NAME_hint). */ #define GLFW_COCOA_FRAME_NAME 0x00023002 /*! @brief macOS specific * [window hint](@ref GLFW_COCOA_GRAPHICS_SWITCHING_hint). */ #define GLFW_COCOA_GRAPHICS_SWITCHING 0x00023003 /*! @brief X11 specific * [window hint](@ref GLFW_X11_CLASS_NAME_hint). */ #define GLFW_X11_CLASS_NAME 0x00024001 /*! @brief X11 specific * [window hint](@ref GLFW_X11_CLASS_NAME_hint). */ #define GLFW_X11_INSTANCE_NAME 0x00024002 #define GLFW_WIN32_KEYBOARD_MENU 0x00025001 /*! @brief Win32 specific [window hint](@ref GLFW_WIN32_SHOWDEFAULT_hint). */ #define GLFW_WIN32_SHOWDEFAULT 0x00025002 /*! @brief Wayland specific * [window hint](@ref GLFW_WAYLAND_APP_ID_hint). * * Allows specification of the Wayland app_id. */ #define GLFW_WAYLAND_APP_ID 0x00026001 /*! @} */ #define GLFW_NO_API 0 #define GLFW_OPENGL_API 0x00030001 #define GLFW_OPENGL_ES_API 0x00030002 #define GLFW_NO_ROBUSTNESS 0 #define GLFW_NO_RESET_NOTIFICATION 0x00031001 #define GLFW_LOSE_CONTEXT_ON_RESET 0x00031002 #define GLFW_OPENGL_ANY_PROFILE 0 #define GLFW_OPENGL_CORE_PROFILE 0x00032001 #define GLFW_OPENGL_COMPAT_PROFILE 0x00032002 #define GLFW_CURSOR 0x00033001 #define GLFW_STICKY_KEYS 0x00033002 #define GLFW_STICKY_MOUSE_BUTTONS 0x00033003 #define GLFW_LOCK_KEY_MODS 0x00033004 #define GLFW_RAW_MOUSE_MOTION 0x00033005 #define GLFW_CURSOR_NORMAL 0x00034001 #define GLFW_CURSOR_HIDDEN 0x00034002 #define GLFW_CURSOR_DISABLED 0x00034003 #define GLFW_CURSOR_CAPTURED 0x00034004 #define GLFW_ANY_RELEASE_BEHAVIOR 0 #define GLFW_RELEASE_BEHAVIOR_FLUSH 0x00035001 #define GLFW_RELEASE_BEHAVIOR_NONE 0x00035002 #define GLFW_NATIVE_CONTEXT_API 0x00036001 #define GLFW_EGL_CONTEXT_API 0x00036002 #define GLFW_OSMESA_CONTEXT_API 0x00036003 #define GLFW_ANGLE_PLATFORM_TYPE_NONE 0x00037001 #define GLFW_ANGLE_PLATFORM_TYPE_OPENGL 0x00037002 #define GLFW_ANGLE_PLATFORM_TYPE_OPENGLES 0x00037003 #define GLFW_ANGLE_PLATFORM_TYPE_D3D9 0x00037004 #define GLFW_ANGLE_PLATFORM_TYPE_D3D11 0x00037005 #define GLFW_ANGLE_PLATFORM_TYPE_VULKAN 0x00037007 #define GLFW_ANGLE_PLATFORM_TYPE_METAL 0x00037008 #define GLFW_WAYLAND_PREFER_LIBDECOR 0x00038001 #define GLFW_WAYLAND_DISABLE_LIBDECOR 0x00038002 #define GLFW_ANY_POSITION 0x80000000 /*! @defgroup shapes Standard cursor shapes * @brief Standard system cursor shapes. * * These are the [standard cursor shapes](@ref cursor_standard) that can be * requested from the platform (window system). * * @ingroup input * @{ */ /*! @brief The regular arrow cursor shape. * * The regular arrow cursor shape. */ #define GLFW_ARROW_CURSOR 0x00036001 /*! @brief The text input I-beam cursor shape. * * The text input I-beam cursor shape. */ #define GLFW_IBEAM_CURSOR 0x00036002 /*! @brief The crosshair cursor shape. * * The crosshair cursor shape. */ #define GLFW_CROSSHAIR_CURSOR 0x00036003 /*! @brief The pointing hand cursor shape. * * The pointing hand cursor shape. */ #define GLFW_POINTING_HAND_CURSOR 0x00036004 /*! @brief The horizontal resize/move arrow shape. * * The horizontal resize/move arrow shape. This is usually a horizontal * double-headed arrow. */ #define GLFW_RESIZE_EW_CURSOR 0x00036005 /*! @brief The vertical resize/move arrow shape. * * The vertical resize/move shape. This is usually a vertical double-headed * arrow. */ #define GLFW_RESIZE_NS_CURSOR 0x00036006 /*! @brief The top-left to bottom-right diagonal resize/move arrow shape. * * The top-left to bottom-right diagonal resize/move shape. This is usually * a diagonal double-headed arrow. * * @note @macos This shape is provided by a private system API and may fail * with @ref GLFW_CURSOR_UNAVAILABLE in the future. * * @note @wayland This shape is provided by a newer standard not supported by * all cursor themes. * * @note @x11 This shape is provided by a newer standard not supported by all * cursor themes. */ #define GLFW_RESIZE_NWSE_CURSOR 0x00036007 /*! @brief The top-right to bottom-left diagonal resize/move arrow shape. * * The top-right to bottom-left diagonal resize/move shape. This is usually * a diagonal double-headed arrow. * * @note @macos This shape is provided by a private system API and may fail * with @ref GLFW_CURSOR_UNAVAILABLE in the future. * * @note @wayland This shape is provided by a newer standard not supported by * all cursor themes. * * @note @x11 This shape is provided by a newer standard not supported by all * cursor themes. */ #define GLFW_RESIZE_NESW_CURSOR 0x00036008 /*! @brief The omni-directional resize/move cursor shape. * * The omni-directional resize cursor/move shape. This is usually either * a combined horizontal and vertical double-headed arrow or a grabbing hand. */ #define GLFW_RESIZE_ALL_CURSOR 0x00036009 /*! @brief The operation-not-allowed shape. * * The operation-not-allowed shape. This is usually a circle with a diagonal * line through it. * * @note @wayland This shape is provided by a newer standard not supported by * all cursor themes. * * @note @x11 This shape is provided by a newer standard not supported by all * cursor themes. */ #define GLFW_NOT_ALLOWED_CURSOR 0x0003600A /*! @brief Legacy name for compatibility. * * This is an alias for compatibility with earlier versions. */ #define GLFW_HRESIZE_CURSOR GLFW_RESIZE_EW_CURSOR /*! @brief Legacy name for compatibility. * * This is an alias for compatibility with earlier versions. */ #define GLFW_VRESIZE_CURSOR GLFW_RESIZE_NS_CURSOR /*! @brief Legacy name for compatibility. * * This is an alias for compatibility with earlier versions. */ #define GLFW_HAND_CURSOR GLFW_POINTING_HAND_CURSOR /*! @} */ #define GLFW_CONNECTED 0x00040001 #define GLFW_DISCONNECTED 0x00040002 /*! @addtogroup init * @{ */ /*! @brief Joystick hat buttons init hint. * * Joystick hat buttons [init hint](@ref GLFW_JOYSTICK_HAT_BUTTONS). */ #define GLFW_JOYSTICK_HAT_BUTTONS 0x00050001 /*! @brief ANGLE rendering backend init hint. * * ANGLE rendering backend [init hint](@ref GLFW_ANGLE_PLATFORM_TYPE_hint). */ #define GLFW_ANGLE_PLATFORM_TYPE 0x00050002 /*! @brief Platform selection init hint. * * Platform selection [init hint](@ref GLFW_PLATFORM). */ #define GLFW_PLATFORM 0x00050003 /*! @brief macOS specific init hint. * * macOS specific [init hint](@ref GLFW_COCOA_CHDIR_RESOURCES_hint). */ #define GLFW_COCOA_CHDIR_RESOURCES 0x00051001 /*! @brief macOS specific init hint. * * macOS specific [init hint](@ref GLFW_COCOA_MENUBAR_hint). */ #define GLFW_COCOA_MENUBAR 0x00051002 /*! @brief X11 specific init hint. * * X11 specific [init hint](@ref GLFW_X11_XCB_VULKAN_SURFACE_hint). */ #define GLFW_X11_XCB_VULKAN_SURFACE 0x00052001 /*! @brief Wayland specific init hint. * * Wayland specific [init hint](@ref GLFW_WAYLAND_LIBDECOR_hint). */ #define GLFW_WAYLAND_LIBDECOR 0x00053001 /*! @} */ /*! @addtogroup init * @{ */ /*! @brief Hint value that enables automatic platform selection. * * Hint value for @ref GLFW_PLATFORM that enables automatic platform selection. */ #define GLFW_ANY_PLATFORM 0x00060000 #define GLFW_PLATFORM_WIN32 0x00060001 #define GLFW_PLATFORM_COCOA 0x00060002 #define GLFW_PLATFORM_WAYLAND 0x00060003 #define GLFW_PLATFORM_X11 0x00060004 #define GLFW_PLATFORM_NULL 0x00060005 /*! @} */ #define GLFW_DONT_CARE -1 /************************************************************************* * GLFW API types *************************************************************************/ /*! @brief Client API function pointer type. * * Generic function pointer used for returning client API function pointers * without forcing a cast from a regular pointer. * * @sa @ref context_glext * @sa @ref glfwGetProcAddress * * @since Added in version 3.0. * * @ingroup context */ typedef void (*GLFWglproc)(void); /*! @brief Vulkan API function pointer type. * * Generic function pointer used for returning Vulkan API function pointers * without forcing a cast from a regular pointer. * * @sa @ref vulkan_proc * @sa @ref glfwGetInstanceProcAddress * * @since Added in version 3.2. * * @ingroup vulkan */ typedef void (*GLFWvkproc)(void); /*! @brief Opaque monitor object. * * Opaque monitor object. * * @see @ref monitor_object * * @since Added in version 3.0. * * @ingroup monitor */ typedef struct GLFWmonitor GLFWmonitor; /*! @brief Opaque window object. * * Opaque window object. * * @see @ref window_object * * @since Added in version 3.0. * * @ingroup window */ typedef struct GLFWwindow GLFWwindow; /*! @brief Opaque cursor object. * * Opaque cursor object. * * @see @ref cursor_object * * @since Added in version 3.1. * * @ingroup input */ typedef struct GLFWcursor GLFWcursor; /*! @brief The function pointer type for memory allocation callbacks. * * This is the function pointer type for memory allocation callbacks. A memory * allocation callback function has the following signature: * @code * void* function_name(size_t size, void* user) * @endcode * * This function must return either a memory block at least `size` bytes long, * or `NULL` if allocation failed. Note that not all parts of GLFW handle allocation * failures gracefully yet. * * This function must support being called during @ref glfwInit but before the library is * flagged as initialized, as well as during @ref glfwTerminate after the library is no * longer flagged as initialized. * * Any memory allocated via this function will be deallocated via the same allocator * during library termination or earlier. * * Any memory allocated via this function must be suitably aligned for any object type. * If you are using C99 or earlier, this alignment is platform-dependent but will be the * same as what `malloc` provides. If you are using C11 or later, this is the value of * `alignof(max_align_t)`. * * The size will always be greater than zero. Allocations of size zero are filtered out * before reaching the custom allocator. * * If this function returns `NULL`, GLFW will emit @ref GLFW_OUT_OF_MEMORY. * * This function must not call any GLFW function. * * @param[in] size The minimum size, in bytes, of the memory block. * @param[in] user The user-defined pointer from the allocator. * @return The address of the newly allocated memory block, or `NULL` if an * error occurred. * * @pointer_lifetime The returned memory block must be valid at least until it * is deallocated. * * @reentrancy This function should not call any GLFW function. * * @thread_safety This function must support being called from any thread that calls GLFW * functions. * * @sa @ref init_allocator * @sa @ref GLFWallocator * * @since Added in version 3.4. * * @ingroup init */ typedef void* (* GLFWallocatefun)(size_t size, void* user); /*! @brief The function pointer type for memory reallocation callbacks. * * This is the function pointer type for memory reallocation callbacks. * A memory reallocation callback function has the following signature: * @code * void* function_name(void* block, size_t size, void* user) * @endcode * * This function must return a memory block at least `size` bytes long, or * `NULL` if allocation failed. Note that not all parts of GLFW handle allocation * failures gracefully yet. * * This function must support being called during @ref glfwInit but before the library is * flagged as initialized, as well as during @ref glfwTerminate after the library is no * longer flagged as initialized. * * Any memory allocated via this function will be deallocated via the same allocator * during library termination or earlier. * * Any memory allocated via this function must be suitably aligned for any object type. * If you are using C99 or earlier, this alignment is platform-dependent but will be the * same as what `realloc` provides. If you are using C11 or later, this is the value of * `alignof(max_align_t)`. * * The block address will never be `NULL` and the size will always be greater than zero. * Reallocations of a block to size zero are converted into deallocations before reaching * the custom allocator. Reallocations of `NULL` to a non-zero size are converted into * regular allocations before reaching the custom allocator. * * If this function returns `NULL`, GLFW will emit @ref GLFW_OUT_OF_MEMORY. * * This function must not call any GLFW function. * * @param[in] block The address of the memory block to reallocate. * @param[in] size The new minimum size, in bytes, of the memory block. * @param[in] user The user-defined pointer from the allocator. * @return The address of the newly allocated or resized memory block, or * `NULL` if an error occurred. * * @pointer_lifetime The returned memory block must be valid at least until it * is deallocated. * * @reentrancy This function should not call any GLFW function. * * @thread_safety This function must support being called from any thread that calls GLFW * functions. * * @sa @ref init_allocator * @sa @ref GLFWallocator * * @since Added in version 3.4. * * @ingroup init */ typedef void* (* GLFWreallocatefun)(void* block, size_t size, void* user); /*! @brief The function pointer type for memory deallocation callbacks. * * This is the function pointer type for memory deallocation callbacks. * A memory deallocation callback function has the following signature: * @code * void function_name(void* block, void* user) * @endcode * * This function may deallocate the specified memory block. This memory block * will have been allocated with the same allocator. * * This function must support being called during @ref glfwInit but before the library is * flagged as initialized, as well as during @ref glfwTerminate after the library is no * longer flagged as initialized. * * The block address will never be `NULL`. Deallocations of `NULL` are filtered out * before reaching the custom allocator. * * If this function returns `NULL`, GLFW will emit @ref GLFW_OUT_OF_MEMORY. * * This function must not call any GLFW function. * * @param[in] block The address of the memory block to deallocate. * @param[in] user The user-defined pointer from the allocator. * * @pointer_lifetime The specified memory block will not be accessed by GLFW * after this function is called. * * @reentrancy This function should not call any GLFW function. * * @thread_safety This function must support being called from any thread that calls GLFW * functions. * * @sa @ref init_allocator * @sa @ref GLFWallocator * * @since Added in version 3.4. * * @ingroup init */ typedef void (* GLFWdeallocatefun)(void* block, void* user); /*! @brief The function pointer type for error callbacks. * * This is the function pointer type for error callbacks. An error callback * function has the following signature: * @code * void callback_name(int error_code, const char* description) * @endcode * * @param[in] error_code An [error code](@ref errors). Future releases may add * more error codes. * @param[in] description A UTF-8 encoded string describing the error. * * @pointer_lifetime The error description string is valid until the callback * function returns. * * @sa @ref error_handling * @sa @ref glfwSetErrorCallback * * @since Added in version 3.0. * * @ingroup init */ typedef void (* GLFWerrorfun)(int error_code, const char* description); /*! @brief The function pointer type for window position callbacks. * * This is the function pointer type for window position callbacks. A window * position callback function has the following signature: * @code * void callback_name(GLFWwindow* window, int xpos, int ypos) * @endcode * * @param[in] window The window that was moved. * @param[in] xpos The new x-coordinate, in screen coordinates, of the * upper-left corner of the content area of the window. * @param[in] ypos The new y-coordinate, in screen coordinates, of the * upper-left corner of the content area of the window. * * @sa @ref window_pos * @sa @ref glfwSetWindowPosCallback * * @since Added in version 3.0. * * @ingroup window */ typedef void (* GLFWwindowposfun)(GLFWwindow* window, int xpos, int ypos); /*! @brief The function pointer type for window size callbacks. * * This is the function pointer type for window size callbacks. A window size * callback function has the following signature: * @code * void callback_name(GLFWwindow* window, int width, int height) * @endcode * * @param[in] window The window that was resized. * @param[in] width The new width, in screen coordinates, of the window. * @param[in] height The new height, in screen coordinates, of the window. * * @sa @ref window_size * @sa @ref glfwSetWindowSizeCallback * * @since Added in version 1.0. * @glfw3 Added window handle parameter. * * @ingroup window */ typedef void (* GLFWwindowsizefun)(GLFWwindow* window, int width, int height); /*! @brief The function pointer type for window close callbacks. * * This is the function pointer type for window close callbacks. A window * close callback function has the following signature: * @code * void function_name(GLFWwindow* window) * @endcode * * @param[in] window The window that the user attempted to close. * * @sa @ref window_close * @sa @ref glfwSetWindowCloseCallback * * @since Added in version 2.5. * @glfw3 Added window handle parameter. * * @ingroup window */ typedef void (* GLFWwindowclosefun)(GLFWwindow* window); /*! @brief The function pointer type for window content refresh callbacks. * * This is the function pointer type for window content refresh callbacks. * A window content refresh callback function has the following signature: * @code * void function_name(GLFWwindow* window); * @endcode * * @param[in] window The window whose content needs to be refreshed. * * @sa @ref window_refresh * @sa @ref glfwSetWindowRefreshCallback * * @since Added in version 2.5. * @glfw3 Added window handle parameter. * * @ingroup window */ typedef void (* GLFWwindowrefreshfun)(GLFWwindow* window); /*! @brief The function pointer type for window focus callbacks. * * This is the function pointer type for window focus callbacks. A window * focus callback function has the following signature: * @code * void function_name(GLFWwindow* window, int focused) * @endcode * * @param[in] window The window that gained or lost input focus. * @param[in] focused `GLFW_TRUE` if the window was given input focus, or * `GLFW_FALSE` if it lost it. * * @sa @ref window_focus * @sa @ref glfwSetWindowFocusCallback * * @since Added in version 3.0. * * @ingroup window */ typedef void (* GLFWwindowfocusfun)(GLFWwindow* window, int focused); /*! @brief The function pointer type for window iconify callbacks. * * This is the function pointer type for window iconify callbacks. A window * iconify callback function has the following signature: * @code * void function_name(GLFWwindow* window, int iconified) * @endcode * * @param[in] window The window that was iconified or restored. * @param[in] iconified `GLFW_TRUE` if the window was iconified, or * `GLFW_FALSE` if it was restored. * * @sa @ref window_iconify * @sa @ref glfwSetWindowIconifyCallback * * @since Added in version 3.0. * * @ingroup window */ typedef void (* GLFWwindowiconifyfun)(GLFWwindow* window, int iconified); /*! @brief The function pointer type for window maximize callbacks. * * This is the function pointer type for window maximize callbacks. A window * maximize callback function has the following signature: * @code * void function_name(GLFWwindow* window, int maximized) * @endcode * * @param[in] window The window that was maximized or restored. * @param[in] maximized `GLFW_TRUE` if the window was maximized, or * `GLFW_FALSE` if it was restored. * * @sa @ref window_maximize * @sa glfwSetWindowMaximizeCallback * * @since Added in version 3.3. * * @ingroup window */ typedef void (* GLFWwindowmaximizefun)(GLFWwindow* window, int maximized); /*! @brief The function pointer type for framebuffer size callbacks. * * This is the function pointer type for framebuffer size callbacks. * A framebuffer size callback function has the following signature: * @code * void function_name(GLFWwindow* window, int width, int height) * @endcode * * @param[in] window The window whose framebuffer was resized. * @param[in] width The new width, in pixels, of the framebuffer. * @param[in] height The new height, in pixels, of the framebuffer. * * @sa @ref window_fbsize * @sa @ref glfwSetFramebufferSizeCallback * * @since Added in version 3.0. * * @ingroup window */ typedef void (* GLFWframebuffersizefun)(GLFWwindow* window, int width, int height); /*! @brief The function pointer type for window content scale callbacks. * * This is the function pointer type for window content scale callbacks. * A window content scale callback function has the following signature: * @code * void function_name(GLFWwindow* window, float xscale, float yscale) * @endcode * * @param[in] window The window whose content scale changed. * @param[in] xscale The new x-axis content scale of the window. * @param[in] yscale The new y-axis content scale of the window. * * @sa @ref window_scale * @sa @ref glfwSetWindowContentScaleCallback * * @since Added in version 3.3. * * @ingroup window */ typedef void (* GLFWwindowcontentscalefun)(GLFWwindow* window, float xscale, float yscale); /*! @brief The function pointer type for mouse button callbacks. * * This is the function pointer type for mouse button callback functions. * A mouse button callback function has the following signature: * @code * void function_name(GLFWwindow* window, int button, int action, int mods) * @endcode * * @param[in] window The window that received the event. * @param[in] button The [mouse button](@ref buttons) that was pressed or * released. * @param[in] action One of `GLFW_PRESS` or `GLFW_RELEASE`. Future releases * may add more actions. * @param[in] mods Bit field describing which [modifier keys](@ref mods) were * held down. * * @sa @ref input_mouse_button * @sa @ref glfwSetMouseButtonCallback * * @since Added in version 1.0. * @glfw3 Added window handle and modifier mask parameters. * * @ingroup input */ typedef void (* GLFWmousebuttonfun)(GLFWwindow* window, int button, int action, int mods); /*! @brief The function pointer type for cursor position callbacks. * * This is the function pointer type for cursor position callbacks. A cursor * position callback function has the following signature: * @code * void function_name(GLFWwindow* window, double xpos, double ypos); * @endcode * * @param[in] window The window that received the event. * @param[in] xpos The new cursor x-coordinate, relative to the left edge of * the content area. * @param[in] ypos The new cursor y-coordinate, relative to the top edge of the * content area. * * @sa @ref cursor_pos * @sa @ref glfwSetCursorPosCallback * * @since Added in version 3.0. Replaces `GLFWmouseposfun`. * * @ingroup input */ typedef void (* GLFWcursorposfun)(GLFWwindow* window, double xpos, double ypos); /*! @brief The function pointer type for cursor enter/leave callbacks. * * This is the function pointer type for cursor enter/leave callbacks. * A cursor enter/leave callback function has the following signature: * @code * void function_name(GLFWwindow* window, int entered) * @endcode * * @param[in] window The window that received the event. * @param[in] entered `GLFW_TRUE` if the cursor entered the window's content * area, or `GLFW_FALSE` if it left it. * * @sa @ref cursor_enter * @sa @ref glfwSetCursorEnterCallback * * @since Added in version 3.0. * * @ingroup input */ typedef void (* GLFWcursorenterfun)(GLFWwindow* window, int entered); /*! @brief The function pointer type for scroll callbacks. * * This is the function pointer type for scroll callbacks. A scroll callback * function has the following signature: * @code * void function_name(GLFWwindow* window, double xoffset, double yoffset) * @endcode * * @param[in] window The window that received the event. * @param[in] xoffset The scroll offset along the x-axis. * @param[in] yoffset The scroll offset along the y-axis. * * @sa @ref scrolling * @sa @ref glfwSetScrollCallback * * @since Added in version 3.0. Replaces `GLFWmousewheelfun`. * * @ingroup input */ typedef void (* GLFWscrollfun)(GLFWwindow* window, double xoffset, double yoffset); /*! @brief The function pointer type for keyboard key callbacks. * * This is the function pointer type for keyboard key callbacks. A keyboard * key callback function has the following signature: * @code * void function_name(GLFWwindow* window, int key, int scancode, int action, int mods) * @endcode * * @param[in] window The window that received the event. * @param[in] key The [keyboard key](@ref keys) that was pressed or released. * @param[in] scancode The platform-specific scancode of the key. * @param[in] action `GLFW_PRESS`, `GLFW_RELEASE` or `GLFW_REPEAT`. Future * releases may add more actions. * @param[in] mods Bit field describing which [modifier keys](@ref mods) were * held down. * * @sa @ref input_key * @sa @ref glfwSetKeyCallback * * @since Added in version 1.0. * @glfw3 Added window handle, scancode and modifier mask parameters. * * @ingroup input */ typedef void (* GLFWkeyfun)(GLFWwindow* window, int key, int scancode, int action, int mods); /*! @brief The function pointer type for Unicode character callbacks. * * This is the function pointer type for Unicode character callbacks. * A Unicode character callback function has the following signature: * @code * void function_name(GLFWwindow* window, unsigned int codepoint) * @endcode * * @param[in] window The window that received the event. * @param[in] codepoint The Unicode code point of the character. * * @sa @ref input_char * @sa @ref glfwSetCharCallback * * @since Added in version 2.4. * @glfw3 Added window handle parameter. * * @ingroup input */ typedef void (* GLFWcharfun)(GLFWwindow* window, unsigned int codepoint); /*! @brief The function pointer type for Unicode character with modifiers * callbacks. * * This is the function pointer type for Unicode character with modifiers * callbacks. It is called for each input character, regardless of what * modifier keys are held down. A Unicode character with modifiers callback * function has the following signature: * @code * void function_name(GLFWwindow* window, unsigned int codepoint, int mods) * @endcode * * @param[in] window The window that received the event. * @param[in] codepoint The Unicode code point of the character. * @param[in] mods Bit field describing which [modifier keys](@ref mods) were * held down. * * @sa @ref input_char * @sa @ref glfwSetCharModsCallback * * @deprecated Scheduled for removal in version 4.0. * * @since Added in version 3.1. * * @ingroup input */ typedef void (* GLFWcharmodsfun)(GLFWwindow* window, unsigned int codepoint, int mods); /*! @brief The function pointer type for path drop callbacks. * * This is the function pointer type for path drop callbacks. A path drop * callback function has the following signature: * @code * void function_name(GLFWwindow* window, int path_count, const char* paths[]) * @endcode * * @param[in] window The window that received the event. * @param[in] path_count The number of dropped paths. * @param[in] paths The UTF-8 encoded file and/or directory path names. * * @pointer_lifetime The path array and its strings are valid until the * callback function returns. * * @sa @ref path_drop * @sa @ref glfwSetDropCallback * * @since Added in version 3.1. * * @ingroup input */ typedef void (* GLFWdropfun)(GLFWwindow* window, int path_count, const char* paths[]); /*! @brief The function pointer type for monitor configuration callbacks. * * This is the function pointer type for monitor configuration callbacks. * A monitor callback function has the following signature: * @code * void function_name(GLFWmonitor* monitor, int event) * @endcode * * @param[in] monitor The monitor that was connected or disconnected. * @param[in] event One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`. Future * releases may add more events. * * @sa @ref monitor_event * @sa @ref glfwSetMonitorCallback * * @since Added in version 3.0. * * @ingroup monitor */ typedef void (* GLFWmonitorfun)(GLFWmonitor* monitor, int event); /*! @brief The function pointer type for joystick configuration callbacks. * * This is the function pointer type for joystick configuration callbacks. * A joystick configuration callback function has the following signature: * @code * void function_name(int jid, int event) * @endcode * * @param[in] jid The joystick that was connected or disconnected. * @param[in] event One of `GLFW_CONNECTED` or `GLFW_DISCONNECTED`. Future * releases may add more events. * * @sa @ref joystick_event * @sa @ref glfwSetJoystickCallback * * @since Added in version 3.2. * * @ingroup input */ typedef void (* GLFWjoystickfun)(int jid, int event); /*! @brief Video mode type. * * This describes a single video mode. * * @sa @ref monitor_modes * @sa @ref glfwGetVideoMode * @sa @ref glfwGetVideoModes * * @since Added in version 1.0. * @glfw3 Added refresh rate member. * * @ingroup monitor */ typedef struct GLFWvidmode { /*! The width, in screen coordinates, of the video mode. */ int width; /*! The height, in screen coordinates, of the video mode. */ int height; /*! The bit depth of the red channel of the video mode. */ int redBits; /*! The bit depth of the green channel of the video mode. */ int greenBits; /*! The bit depth of the blue channel of the video mode. */ int blueBits; /*! The refresh rate, in Hz, of the video mode. */ int refreshRate; } GLFWvidmode; /*! @brief Gamma ramp. * * This describes the gamma ramp for a monitor. * * @sa @ref monitor_gamma * @sa @ref glfwGetGammaRamp * @sa @ref glfwSetGammaRamp * * @since Added in version 3.0. * * @ingroup monitor */ typedef struct GLFWgammaramp { /*! An array of value describing the response of the red channel. */ unsigned short* red; /*! An array of value describing the response of the green channel. */ unsigned short* green; /*! An array of value describing the response of the blue channel. */ unsigned short* blue; /*! The number of elements in each array. */ unsigned int size; } GLFWgammaramp; /*! @brief Image data. * * This describes a single 2D image. See the documentation for each related * function what the expected pixel format is. * * @sa @ref cursor_custom * @sa @ref window_icon * * @since Added in version 2.1. * @glfw3 Removed format and bytes-per-pixel members. * * @ingroup window */ typedef struct GLFWimage { /*! The width, in pixels, of this image. */ int width; /*! The height, in pixels, of this image. */ int height; /*! The pixel data of this image, arranged left-to-right, top-to-bottom. */ unsigned char* pixels; } GLFWimage; /*! @brief Gamepad input state * * This describes the input state of a gamepad. * * @sa @ref gamepad * @sa @ref glfwGetGamepadState * * @since Added in version 3.3. * * @ingroup input */ typedef struct GLFWgamepadstate { /*! The states of each [gamepad button](@ref gamepad_buttons), `GLFW_PRESS` * or `GLFW_RELEASE`. */ unsigned char buttons[15]; /*! The states of each [gamepad axis](@ref gamepad_axes), in the range -1.0 * to 1.0 inclusive. */ float axes[6]; } GLFWgamepadstate; /*! @brief Custom heap memory allocator. * * This describes a custom heap memory allocator for GLFW. To set an allocator, pass it * to @ref glfwInitAllocator before initializing the library. * * @sa @ref init_allocator * @sa @ref glfwInitAllocator * * @since Added in version 3.4. * * @ingroup init */ typedef struct GLFWallocator { /*! The memory allocation function. See @ref GLFWallocatefun for details about * allocation function. */ GLFWallocatefun allocate; /*! The memory reallocation function. See @ref GLFWreallocatefun for details about * reallocation function. */ GLFWreallocatefun reallocate; /*! The memory deallocation function. See @ref GLFWdeallocatefun for details about * deallocation function. */ GLFWdeallocatefun deallocate; /*! The user pointer for this custom allocator. This value will be passed to the * allocator functions. */ void* user; } GLFWallocator; /************************************************************************* * GLFW API functions *************************************************************************/ /*! @brief Initializes the GLFW library. * * This function initializes the GLFW library. Before most GLFW functions can * be used, GLFW must be initialized, and before an application terminates GLFW * should be terminated in order to free any resources allocated during or * after initialization. * * If this function fails, it calls @ref glfwTerminate before returning. If it * succeeds, you should call @ref glfwTerminate before the application exits. * * Additional calls to this function after successful initialization but before * termination will return `GLFW_TRUE` immediately. * * The @ref GLFW_PLATFORM init hint controls which platforms are considered during * initialization. This also depends on which platforms the library was compiled to * support. * * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_PLATFORM_UNAVAILABLE and @ref * GLFW_PLATFORM_ERROR. * * @remark @macos This function will change the current directory of the * application to the `Contents/Resources` subdirectory of the application's * bundle, if present. This can be disabled with the @ref * GLFW_COCOA_CHDIR_RESOURCES init hint. * * @remark @macos This function will create the main menu and dock icon for the * application. If GLFW finds a `MainMenu.nib` it is loaded and assumed to * contain a menu bar. Otherwise a minimal menu bar is created manually with * common commands like Hide, Quit and About. The About entry opens a minimal * about dialog with information from the application's bundle. The menu bar * and dock icon can be disabled entirely with the @ref GLFW_COCOA_MENUBAR init * hint. * * @remark __Wayland, X11:__ If the library was compiled with support for both * Wayland and X11, and the @ref GLFW_PLATFORM init hint is set to * `GLFW_ANY_PLATFORM`, the `XDG_SESSION_TYPE` environment variable affects * which platform is picked. If the environment variable is not set, or is set * to something other than `wayland` or `x11`, the regular detection mechanism * will be used instead. * * @remark @x11 This function will set the `LC_CTYPE` category of the * application locale according to the current environment if that category is * still "C". This is because the "C" locale breaks Unicode text input. * * @thread_safety This function must only be called from the main thread. * * @sa @ref intro_init * @sa @ref glfwInitHint * @sa @ref glfwInitAllocator * @sa @ref glfwTerminate * * @since Added in version 1.0. * * @ingroup init */ GLFWAPI int glfwInit(void); /*! @brief Terminates the GLFW library. * * This function destroys all remaining windows and cursors, restores any * modified gamma ramps and frees any other allocated resources. Once this * function is called, you must again call @ref glfwInit successfully before * you will be able to use most GLFW functions. * * If GLFW has been successfully initialized, this function should be called * before the application exits. If initialization fails, there is no need to * call this function, as it is called by @ref glfwInit before it returns * failure. * * This function has no effect if GLFW is not initialized. * * @errors Possible errors include @ref GLFW_PLATFORM_ERROR. * * @remark This function may be called before @ref glfwInit. * * @warning The contexts of any remaining windows must not be current on any * other thread when this function is called. * * @reentrancy This function must not be called from a callback. * * @thread_safety This function must only be called from the main thread. * * @sa @ref intro_init * @sa @ref glfwInit * * @since Added in version 1.0. * * @ingroup init */ GLFWAPI void glfwTerminate(void); /*! @brief Sets the specified init hint to the desired value. * * This function sets hints for the next initialization of GLFW. * * The values you set hints to are never reset by GLFW, but they only take * effect during initialization. Once GLFW has been initialized, any values * you set will be ignored until the library is terminated and initialized * again. * * Some hints are platform specific. These may be set on any platform but they * will only affect their specific platform. Other platforms will ignore them. * Setting these hints requires no platform specific headers or functions. * * @param[in] hint The [init hint](@ref init_hints) to set. * @param[in] value The new value of the init hint. * * @errors Possible errors include @ref GLFW_INVALID_ENUM and @ref * GLFW_INVALID_VALUE. * * @remarks This function may be called before @ref glfwInit. * * @thread_safety This function must only be called from the main thread. * * @sa init_hints * @sa glfwInit * * @since Added in version 3.3. * * @ingroup init */ GLFWAPI void glfwInitHint(int hint, int value); /*! @brief Sets the init allocator to the desired value. * * To use the default allocator, call this function with a `NULL` argument. * * If you specify an allocator struct, every member must be a valid function * pointer. If any member is `NULL`, this function will emit @ref * GLFW_INVALID_VALUE and the init allocator will be unchanged. * * The functions in the allocator must fulfil a number of requirements. See the * documentation for @ref GLFWallocatefun, @ref GLFWreallocatefun and @ref * GLFWdeallocatefun for details. * * @param[in] allocator The allocator to use at the next initialization, or * `NULL` to use the default one. * * @errors Possible errors include @ref GLFW_INVALID_VALUE. * * @pointer_lifetime The specified allocator is copied before this function * returns. * * @thread_safety This function must only be called from the main thread. * * @sa @ref init_allocator * @sa @ref glfwInit * * @since Added in version 3.4. * * @ingroup init */ GLFWAPI void glfwInitAllocator(const GLFWallocator* allocator); #if defined(VK_VERSION_1_0) /*! @brief Sets the desired Vulkan `vkGetInstanceProcAddr` function. * * This function sets the `vkGetInstanceProcAddr` function that GLFW will use for all * Vulkan related entry point queries. * * This feature is mostly useful on macOS, if your copy of the Vulkan loader is in * a location where GLFW cannot find it through dynamic loading, or if you are still * using the static library version of the loader. * * If set to `NULL`, GLFW will try to load the Vulkan loader dynamically by its standard * name and get this function from there. This is the default behavior. * * The standard name of the loader is `vulkan-1.dll` on Windows, `libvulkan.so.1` on * Linux and other Unix-like systems and `libvulkan.1.dylib` on macOS. If your code is * also loading it via these names then you probably don't need to use this function. * * The function address you set is never reset by GLFW, but it only takes effect during * initialization. Once GLFW has been initialized, any updates will be ignored until the * library is terminated and initialized again. * * @param[in] loader The address of the function to use, or `NULL`. * * @par Loader function signature * @code * PFN_vkVoidFunction vkGetInstanceProcAddr(VkInstance instance, const char* name) * @endcode * For more information about this function, see the * [Vulkan Registry](https://www.khronos.org/registry/vulkan/). * * @errors None. * * @remark This function may be called before @ref glfwInit. * * @thread_safety This function must only be called from the main thread. * * @sa @ref vulkan_loader * @sa @ref glfwInit * * @since Added in version 3.4. * * @ingroup init */ GLFWAPI void glfwInitVulkanLoader(PFN_vkGetInstanceProcAddr loader); #endif /*VK_VERSION_1_0*/ /*! @brief Retrieves the version of the GLFW library. * * This function retrieves the major, minor and revision numbers of the GLFW * library. It is intended for when you are using GLFW as a shared library and * want to ensure that you are using the minimum required version. * * Any or all of the version arguments may be `NULL`. * * @param[out] major Where to store the major version number, or `NULL`. * @param[out] minor Where to store the minor version number, or `NULL`. * @param[out] rev Where to store the revision number, or `NULL`. * * @errors None. * * @remark This function may be called before @ref glfwInit. * * @thread_safety This function may be called from any thread. * * @sa @ref intro_version * @sa @ref glfwGetVersionString * * @since Added in version 1.0. * * @ingroup init */ GLFWAPI void glfwGetVersion(int* major, int* minor, int* rev); /*! @brief Returns a string describing the compile-time configuration. * * This function returns the compile-time generated * [version string](@ref intro_version_string) of the GLFW library binary. It describes * the version, platforms, compiler and any platform or operating system specific * compile-time options. It should not be confused with the OpenGL or OpenGL ES version * string, queried with `glGetString`. * * __Do not use the version string__ to parse the GLFW library version. The * @ref glfwGetVersion function provides the version of the running library * binary in numerical format. * * __Do not use the version string__ to parse what platforms are supported. The @ref * glfwPlatformSupported function lets you query platform support. * * @return The ASCII encoded GLFW version string. * * @errors None. * * @remark This function may be called before @ref glfwInit. * * @pointer_lifetime The returned string is static and compile-time generated. * * @thread_safety This function may be called from any thread. * * @sa @ref intro_version * @sa @ref glfwGetVersion * * @since Added in version 3.0. * * @ingroup init */ GLFWAPI const char* glfwGetVersionString(void); /*! @brief Returns and clears the last error for the calling thread. * * This function returns and clears the [error code](@ref errors) of the last * error that occurred on the calling thread, and optionally a UTF-8 encoded * human-readable description of it. If no error has occurred since the last * call, it returns @ref GLFW_NO_ERROR (zero) and the description pointer is * set to `NULL`. * * @param[in] description Where to store the error description pointer, or `NULL`. * @return The last error code for the calling thread, or @ref GLFW_NO_ERROR * (zero). * * @errors None. * * @pointer_lifetime The returned string is allocated and freed by GLFW. You * should not free it yourself. It is guaranteed to be valid only until the * next error occurs or the library is terminated. * * @remark This function may be called before @ref glfwInit. * * @thread_safety This function may be called from any thread. * * @sa @ref error_handling * @sa @ref glfwSetErrorCallback * * @since Added in version 3.3. * * @ingroup init */ GLFWAPI int glfwGetError(const char** description); /*! @brief Sets the error callback. * * This function sets the error callback, which is called with an error code * and a human-readable description each time a GLFW error occurs. * * The error code is set before the callback is called. Calling @ref * glfwGetError from the error callback will return the same value as the error * code argument. * * The error callback is called on the thread where the error occurred. If you * are using GLFW from multiple threads, your error callback needs to be * written accordingly. * * Because the description string may have been generated specifically for that * error, it is not guaranteed to be valid after the callback has returned. If * you wish to use it after the callback returns, you need to make a copy. * * Once set, the error callback remains set even after the library has been * terminated. * * @param[in] callback The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set. * * @callback_signature * @code * void callback_name(int error_code, const char* description) * @endcode * For more information about the callback parameters, see the * [callback pointer type](@ref GLFWerrorfun). * * @errors None. * * @remark This function may be called before @ref glfwInit. * * @thread_safety This function must only be called from the main thread. * * @sa @ref error_handling * @sa @ref glfwGetError * * @since Added in version 3.0. * * @ingroup init */ GLFWAPI GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun callback); /*! @brief Returns the currently selected platform. * * This function returns the platform that was selected during initialization. The * returned value will be one of `GLFW_PLATFORM_WIN32`, `GLFW_PLATFORM_COCOA`, * `GLFW_PLATFORM_WAYLAND`, `GLFW_PLATFORM_X11` or `GLFW_PLATFORM_NULL`. * * @return The currently selected platform, or zero if an error occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function may be called from any thread. * * @sa @ref platform * @sa @ref glfwPlatformSupported * * @since Added in version 3.4. * * @ingroup init */ GLFWAPI int glfwGetPlatform(void); /*! @brief Returns whether the library includes support for the specified platform. * * This function returns whether the library was compiled with support for the specified * platform. The platform must be one of `GLFW_PLATFORM_WIN32`, `GLFW_PLATFORM_COCOA`, * `GLFW_PLATFORM_WAYLAND`, `GLFW_PLATFORM_X11` or `GLFW_PLATFORM_NULL`. * * @param[in] platform The platform to query. * @return `GLFW_TRUE` if the platform is supported, or `GLFW_FALSE` otherwise. * * @errors Possible errors include @ref GLFW_INVALID_ENUM. * * @remark This function may be called before @ref glfwInit. * * @thread_safety This function may be called from any thread. * * @sa @ref platform * @sa @ref glfwGetPlatform * * @since Added in version 3.4. * * @ingroup init */ GLFWAPI int glfwPlatformSupported(int platform); /*! @brief Returns the currently connected monitors. * * This function returns an array of handles for all currently connected * monitors. The primary monitor is always first in the returned array. If no * monitors were found, this function returns `NULL`. * * @param[out] count Where to store the number of monitors in the returned * array. This is set to zero if an error occurred. * @return An array of monitor handles, or `NULL` if no monitors were found or * if an [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @pointer_lifetime The returned array is allocated and freed by GLFW. You * should not free it yourself. It is guaranteed to be valid only until the * monitor configuration changes or the library is terminated. * * @thread_safety This function must only be called from the main thread. * * @sa @ref monitor_monitors * @sa @ref monitor_event * @sa @ref glfwGetPrimaryMonitor * * @since Added in version 3.0. * * @ingroup monitor */ GLFWAPI GLFWmonitor** glfwGetMonitors(int* count); /*! @brief Returns the primary monitor. * * This function returns the primary monitor. This is usually the monitor * where elements like the task bar or global menu bar are located. * * @return The primary monitor, or `NULL` if no monitors were found or if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @remark The primary monitor is always first in the array returned by @ref * glfwGetMonitors. * * @sa @ref monitor_monitors * @sa @ref glfwGetMonitors * * @since Added in version 3.0. * * @ingroup monitor */ GLFWAPI GLFWmonitor* glfwGetPrimaryMonitor(void); /*! @brief Returns the position of the monitor's viewport on the virtual screen. * * This function returns the position, in screen coordinates, of the upper-left * corner of the specified monitor. * * Any or all of the position arguments may be `NULL`. If an error occurs, all * non-`NULL` position arguments will be set to zero. * * @param[in] monitor The monitor to query. * @param[out] xpos Where to store the monitor x-coordinate, or `NULL`. * @param[out] ypos Where to store the monitor y-coordinate, or `NULL`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @thread_safety This function must only be called from the main thread. * * @sa @ref monitor_properties * * @since Added in version 3.0. * * @ingroup monitor */ GLFWAPI void glfwGetMonitorPos(GLFWmonitor* monitor, int* xpos, int* ypos); /*! @brief Retrieves the work area of the monitor. * * This function returns the position, in screen coordinates, of the upper-left * corner of the work area of the specified monitor along with the work area * size in screen coordinates. The work area is defined as the area of the * monitor not occluded by the window system task bar where present. If no * task bar exists then the work area is the monitor resolution in screen * coordinates. * * Any or all of the position and size arguments may be `NULL`. If an error * occurs, all non-`NULL` position and size arguments will be set to zero. * * @param[in] monitor The monitor to query. * @param[out] xpos Where to store the monitor x-coordinate, or `NULL`. * @param[out] ypos Where to store the monitor y-coordinate, or `NULL`. * @param[out] width Where to store the monitor width, or `NULL`. * @param[out] height Where to store the monitor height, or `NULL`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @thread_safety This function must only be called from the main thread. * * @sa @ref monitor_workarea * * @since Added in version 3.3. * * @ingroup monitor */ GLFWAPI void glfwGetMonitorWorkarea(GLFWmonitor* monitor, int* xpos, int* ypos, int* width, int* height); /*! @brief Returns the physical size of the monitor. * * This function returns the size, in millimetres, of the display area of the * specified monitor. * * Some platforms do not provide accurate monitor size information, either * because the monitor [EDID][] data is incorrect or because the driver does * not report it accurately. * * [EDID]: https://en.wikipedia.org/wiki/Extended_display_identification_data * * Any or all of the size arguments may be `NULL`. If an error occurs, all * non-`NULL` size arguments will be set to zero. * * @param[in] monitor The monitor to query. * @param[out] widthMM Where to store the width, in millimetres, of the * monitor's display area, or `NULL`. * @param[out] heightMM Where to store the height, in millimetres, of the * monitor's display area, or `NULL`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @remark @win32 On Windows 8 and earlier the physical size is calculated from * the current resolution and system DPI instead of querying the monitor EDID data. * * @thread_safety This function must only be called from the main thread. * * @sa @ref monitor_properties * * @since Added in version 3.0. * * @ingroup monitor */ GLFWAPI void glfwGetMonitorPhysicalSize(GLFWmonitor* monitor, int* widthMM, int* heightMM); /*! @brief Retrieves the content scale for the specified monitor. * * This function retrieves the content scale for the specified monitor. The * content scale is the ratio between the current DPI and the platform's * default DPI. This is especially important for text and any UI elements. If * the pixel dimensions of your UI scaled by this look appropriate on your * machine then it should appear at a reasonable size on other machines * regardless of their DPI and scaling settings. This relies on the system DPI * and scaling settings being somewhat correct. * * The content scale may depend on both the monitor resolution and pixel * density and on user settings. It may be very different from the raw DPI * calculated from the physical size and current resolution. * * @param[in] monitor The monitor to query. * @param[out] xscale Where to store the x-axis content scale, or `NULL`. * @param[out] yscale Where to store the y-axis content scale, or `NULL`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @remark @wayland Fractional scaling information is not yet available for * monitors, so this function only returns integer content scales. * * @thread_safety This function must only be called from the main thread. * * @sa @ref monitor_scale * @sa @ref glfwGetWindowContentScale * * @since Added in version 3.3. * * @ingroup monitor */ GLFWAPI void glfwGetMonitorContentScale(GLFWmonitor* monitor, float* xscale, float* yscale); /*! @brief Returns the name of the specified monitor. * * This function returns a human-readable name, encoded as UTF-8, of the * specified monitor. The name typically reflects the make and model of the * monitor and is not guaranteed to be unique among the connected monitors. * * @param[in] monitor The monitor to query. * @return The UTF-8 encoded name of the monitor, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @pointer_lifetime The returned string is allocated and freed by GLFW. You * should not free it yourself. It is valid until the specified monitor is * disconnected or the library is terminated. * * @thread_safety This function must only be called from the main thread. * * @sa @ref monitor_properties * * @since Added in version 3.0. * * @ingroup monitor */ GLFWAPI const char* glfwGetMonitorName(GLFWmonitor* monitor); /*! @brief Sets the user pointer of the specified monitor. * * This function sets the user-defined pointer of the specified monitor. The * current value is retained until the monitor is disconnected. The initial * value is `NULL`. * * This function may be called from the monitor callback, even for a monitor * that is being disconnected. * * @param[in] monitor The monitor whose pointer to set. * @param[in] pointer The new value. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @sa @ref monitor_userptr * @sa @ref glfwGetMonitorUserPointer * * @since Added in version 3.3. * * @ingroup monitor */ GLFWAPI void glfwSetMonitorUserPointer(GLFWmonitor* monitor, void* pointer); /*! @brief Returns the user pointer of the specified monitor. * * This function returns the current value of the user-defined pointer of the * specified monitor. The initial value is `NULL`. * * This function may be called from the monitor callback, even for a monitor * that is being disconnected. * * @param[in] monitor The monitor whose pointer to return. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @sa @ref monitor_userptr * @sa @ref glfwSetMonitorUserPointer * * @since Added in version 3.3. * * @ingroup monitor */ GLFWAPI void* glfwGetMonitorUserPointer(GLFWmonitor* monitor); /*! @brief Sets the monitor configuration callback. * * This function sets the monitor configuration callback, or removes the * currently set callback. This is called when a monitor is connected to or * disconnected from the system. * * @param[in] callback The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(GLFWmonitor* monitor, int event) * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWmonitorfun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref monitor_event * * @since Added in version 3.0. * * @ingroup monitor */ GLFWAPI GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun callback); /*! @brief Returns the available video modes for the specified monitor. * * This function returns an array of all video modes supported by the specified * monitor. The returned array is sorted in ascending order, first by color * bit depth (the sum of all channel depths), then by resolution area (the * product of width and height), then resolution width and finally by refresh * rate. * * @param[in] monitor The monitor to query. * @param[out] count Where to store the number of video modes in the returned * array. This is set to zero if an error occurred. * @return An array of video modes, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @pointer_lifetime The returned array is allocated and freed by GLFW. You * should not free it yourself. It is valid until the specified monitor is * disconnected, this function is called again for that monitor or the library * is terminated. * * @thread_safety This function must only be called from the main thread. * * @sa @ref monitor_modes * @sa @ref glfwGetVideoMode * * @since Added in version 1.0. * @glfw3 Changed to return an array of modes for a specific monitor. * * @ingroup monitor */ GLFWAPI const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* monitor, int* count); /*! @brief Returns the current mode of the specified monitor. * * This function returns the current video mode of the specified monitor. If * you have created a full screen window for that monitor, the return value * will depend on whether that window is iconified. * * @param[in] monitor The monitor to query. * @return The current mode of the monitor, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @pointer_lifetime The returned array is allocated and freed by GLFW. You * should not free it yourself. It is valid until the specified monitor is * disconnected or the library is terminated. * * @thread_safety This function must only be called from the main thread. * * @sa @ref monitor_modes * @sa @ref glfwGetVideoModes * * @since Added in version 3.0. Replaces `glfwGetDesktopMode`. * * @ingroup monitor */ GLFWAPI const GLFWvidmode* glfwGetVideoMode(GLFWmonitor* monitor); /*! @brief Generates a gamma ramp and sets it for the specified monitor. * * This function generates an appropriately sized gamma ramp from the specified * exponent and then calls @ref glfwSetGammaRamp with it. The value must be * a finite number greater than zero. * * The software controlled gamma ramp is applied _in addition_ to the hardware * gamma correction, which today is usually an approximation of sRGB gamma. * This means that setting a perfectly linear ramp, or gamma 1.0, will produce * the default (usually sRGB-like) behavior. * * For gamma correct rendering with OpenGL or OpenGL ES, see the @ref * GLFW_SRGB_CAPABLE hint. * * @param[in] monitor The monitor whose gamma ramp to set. * @param[in] gamma The desired exponent. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref GLFW_INVALID_VALUE, * @ref GLFW_PLATFORM_ERROR and @ref GLFW_FEATURE_UNAVAILABLE (see remarks). * * @remark @wayland Gamma handling is a privileged protocol, this function * will thus never be implemented and emits @ref GLFW_FEATURE_UNAVAILABLE. * * @thread_safety This function must only be called from the main thread. * * @sa @ref monitor_gamma * * @since Added in version 3.0. * * @ingroup monitor */ GLFWAPI void glfwSetGamma(GLFWmonitor* monitor, float gamma); /*! @brief Returns the current gamma ramp for the specified monitor. * * This function returns the current gamma ramp of the specified monitor. * * @param[in] monitor The monitor to query. * @return The current gamma ramp, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref GLFW_PLATFORM_ERROR * and @ref GLFW_FEATURE_UNAVAILABLE (see remarks). * * @remark @wayland Gamma handling is a privileged protocol, this function * will thus never be implemented and emits @ref GLFW_FEATURE_UNAVAILABLE while * returning `NULL`. * * @pointer_lifetime The returned structure and its arrays are allocated and * freed by GLFW. You should not free them yourself. They are valid until the * specified monitor is disconnected, this function is called again for that * monitor or the library is terminated. * * @thread_safety This function must only be called from the main thread. * * @sa @ref monitor_gamma * * @since Added in version 3.0. * * @ingroup monitor */ GLFWAPI const GLFWgammaramp* glfwGetGammaRamp(GLFWmonitor* monitor); /*! @brief Sets the current gamma ramp for the specified monitor. * * This function sets the current gamma ramp for the specified monitor. The * original gamma ramp for that monitor is saved by GLFW the first time this * function is called and is restored by @ref glfwTerminate. * * The software controlled gamma ramp is applied _in addition_ to the hardware * gamma correction, which today is usually an approximation of sRGB gamma. * This means that setting a perfectly linear ramp, or gamma 1.0, will produce * the default (usually sRGB-like) behavior. * * For gamma correct rendering with OpenGL or OpenGL ES, see the @ref * GLFW_SRGB_CAPABLE hint. * * @param[in] monitor The monitor whose gamma ramp to set. * @param[in] ramp The gamma ramp to use. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref GLFW_PLATFORM_ERROR * and @ref GLFW_FEATURE_UNAVAILABLE (see remarks). * * @remark The size of the specified gamma ramp should match the size of the * current ramp for that monitor. * * @remark @win32 The gamma ramp size must be 256. * * @remark @wayland Gamma handling is a privileged protocol, this function * will thus never be implemented and emits @ref GLFW_FEATURE_UNAVAILABLE. * * @pointer_lifetime The specified gamma ramp is copied before this function * returns. * * @thread_safety This function must only be called from the main thread. * * @sa @ref monitor_gamma * * @since Added in version 3.0. * * @ingroup monitor */ GLFWAPI void glfwSetGammaRamp(GLFWmonitor* monitor, const GLFWgammaramp* ramp); /*! @brief Resets all window hints to their default values. * * This function resets all window hints to their * [default values](@ref window_hints_values). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_hints * @sa @ref glfwWindowHint * @sa @ref glfwWindowHintString * * @since Added in version 3.0. * * @ingroup window */ GLFWAPI void glfwDefaultWindowHints(void); /*! @brief Sets the specified window hint to the desired value. * * This function sets hints for the next call to @ref glfwCreateWindow. The * hints, once set, retain their values until changed by a call to this * function or @ref glfwDefaultWindowHints, or until the library is terminated. * * Only integer value hints can be set with this function. String value hints * are set with @ref glfwWindowHintString. * * This function does not check whether the specified hint values are valid. * If you set hints to invalid values this will instead be reported by the next * call to @ref glfwCreateWindow. * * Some hints are platform specific. These may be set on any platform but they * will only affect their specific platform. Other platforms will ignore them. * Setting these hints requires no platform specific headers or functions. * * @param[in] hint The [window hint](@ref window_hints) to set. * @param[in] value The new value of the window hint. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_INVALID_ENUM. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_hints * @sa @ref glfwWindowHintString * @sa @ref glfwDefaultWindowHints * * @since Added in version 3.0. Replaces `glfwOpenWindowHint`. * * @ingroup window */ GLFWAPI void glfwWindowHint(int hint, int value); /*! @brief Sets the specified window hint to the desired value. * * This function sets hints for the next call to @ref glfwCreateWindow. The * hints, once set, retain their values until changed by a call to this * function or @ref glfwDefaultWindowHints, or until the library is terminated. * * Only string type hints can be set with this function. Integer value hints * are set with @ref glfwWindowHint. * * This function does not check whether the specified hint values are valid. * If you set hints to invalid values this will instead be reported by the next * call to @ref glfwCreateWindow. * * Some hints are platform specific. These may be set on any platform but they * will only affect their specific platform. Other platforms will ignore them. * Setting these hints requires no platform specific headers or functions. * * @param[in] hint The [window hint](@ref window_hints) to set. * @param[in] value The new value of the window hint. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_INVALID_ENUM. * * @pointer_lifetime The specified string is copied before this function * returns. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_hints * @sa @ref glfwWindowHint * @sa @ref glfwDefaultWindowHints * * @since Added in version 3.3. * * @ingroup window */ GLFWAPI void glfwWindowHintString(int hint, const char* value); /*! @brief Creates a window and its associated context. * * This function creates a window and its associated OpenGL or OpenGL ES * context. Most of the options controlling how the window and its context * should be created are specified with [window hints](@ref window_hints). * * Successful creation does not change which context is current. Before you * can use the newly created context, you need to * [make it current](@ref context_current). For information about the `share` * parameter, see @ref context_sharing. * * The created window, framebuffer and context may differ from what you * requested, as not all parameters and hints are * [hard constraints](@ref window_hints_hard). This includes the size of the * window, especially for full screen windows. To query the actual attributes * of the created window, framebuffer and context, see @ref * glfwGetWindowAttrib, @ref glfwGetWindowSize and @ref glfwGetFramebufferSize. * * To create a full screen window, you need to specify the monitor the window * will cover. If no monitor is specified, the window will be windowed mode. * Unless you have a way for the user to choose a specific monitor, it is * recommended that you pick the primary monitor. For more information on how * to query connected monitors, see @ref monitor_monitors. * * For full screen windows, the specified size becomes the resolution of the * window's _desired video mode_. As long as a full screen window is not * iconified, the supported video mode most closely matching the desired video * mode is set for the specified monitor. For more information about full * screen windows, including the creation of so called _windowed full screen_ * or _borderless full screen_ windows, see @ref window_windowed_full_screen. * * Once you have created the window, you can switch it between windowed and * full screen mode with @ref glfwSetWindowMonitor. This will not affect its * OpenGL or OpenGL ES context. * * By default, newly created windows use the placement recommended by the * window system. To create the window at a specific position, set the @ref * GLFW_POSITION_X and @ref GLFW_POSITION_Y window hints before creation. To * restore the default behavior, set either or both hints back to * `GLFW_ANY_POSITION`. * * As long as at least one full screen window is not iconified, the screensaver * is prohibited from starting. * * Window systems put limits on window sizes. Very large or very small window * dimensions may be overridden by the window system on creation. Check the * actual [size](@ref window_size) after creation. * * The [swap interval](@ref buffer_swap) is not set during window creation and * the initial value may vary depending on driver settings and defaults. * * @param[in] width The desired width, in screen coordinates, of the window. * This must be greater than zero. * @param[in] height The desired height, in screen coordinates, of the window. * This must be greater than zero. * @param[in] title The initial, UTF-8 encoded window title. * @param[in] monitor The monitor to use for full screen mode, or `NULL` for * windowed mode. * @param[in] share The window whose context to share resources with, or `NULL` * to not share resources. * @return The handle of the created window, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_ENUM, @ref GLFW_INVALID_VALUE, @ref GLFW_API_UNAVAILABLE, @ref * GLFW_VERSION_UNAVAILABLE, @ref GLFW_FORMAT_UNAVAILABLE, @ref * GLFW_NO_WINDOW_CONTEXT and @ref GLFW_PLATFORM_ERROR. * * @remark @win32 Window creation will fail if the Microsoft GDI software * OpenGL implementation is the only one available. * * @remark @win32 If the executable has an icon resource named `GLFW_ICON,` it * will be set as the initial icon for the window. If no such icon is present, * the `IDI_APPLICATION` icon will be used instead. To set a different icon, * see @ref glfwSetWindowIcon. * * @remark @win32 The context to share resources with must not be current on * any other thread. * * @remark @macos The OS only supports core profile contexts for OpenGL * versions 3.2 and later. Before creating an OpenGL context of version 3.2 or * later you must set the [GLFW_OPENGL_PROFILE](@ref GLFW_OPENGL_PROFILE_hint) * hint accordingly. OpenGL 3.0 and 3.1 contexts are not supported at all * on macOS. * * @remark @macos The GLFW window has no icon, as it is not a document * window, but the dock icon will be the same as the application bundle's icon. * For more information on bundles, see the * [Bundle Programming Guide][bundle-guide] in the Mac Developer Library. * * [bundle-guide]: https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/ * * @remark @macos On OS X 10.10 and later the window frame will not be rendered * at full resolution on Retina displays unless the * [GLFW_SCALE_FRAMEBUFFER](@ref GLFW_SCALE_FRAMEBUFFER_hint) * hint is `GLFW_TRUE` and the `NSHighResolutionCapable` key is enabled in the * application bundle's `Info.plist`. For more information, see * [High Resolution Guidelines for OS X][hidpi-guide] in the Mac Developer * Library. The GLFW test and example programs use a custom `Info.plist` * template for this, which can be found as `CMake/Info.plist.in` in the source * tree. * * [hidpi-guide]: https://developer.apple.com/library/mac/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Explained/Explained.html * * @remark @macos When activating frame autosaving with * [GLFW_COCOA_FRAME_NAME](@ref GLFW_COCOA_FRAME_NAME_hint), the specified * window size and position may be overridden by previously saved values. * * @remark @wayland GLFW uses [libdecor][] where available to create its window * decorations. This in turn uses server-side XDG decorations where available * and provides high quality client-side decorations on compositors like GNOME. * If both XDG decorations and libdecor are unavailable, GLFW falls back to * a very simple set of window decorations that only support moving, resizing * and the window manager's right-click menu. * * [libdecor]: https://gitlab.freedesktop.org/libdecor/libdecor * * @remark @x11 Some window managers will not respect the placement of * initially hidden windows. * * @remark @x11 Due to the asynchronous nature of X11, it may take a moment for * a window to reach its requested state. This means you may not be able to * query the final size, position or other attributes directly after window * creation. * * @remark @x11 The class part of the `WM_CLASS` window property will by * default be set to the window title passed to this function. The instance * part will use the contents of the `RESOURCE_NAME` environment variable, if * present and not empty, or fall back to the window title. Set the * [GLFW_X11_CLASS_NAME](@ref GLFW_X11_CLASS_NAME_hint) and * [GLFW_X11_INSTANCE_NAME](@ref GLFW_X11_INSTANCE_NAME_hint) window hints to * override this. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_creation * @sa @ref glfwDestroyWindow * * @since Added in version 3.0. Replaces `glfwOpenWindow`. * * @ingroup window */ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share); /*! @brief Destroys the specified window and its context. * * This function destroys the specified window and its context. On calling * this function, no further callbacks will be called for that window. * * If the context of the specified window is current on the main thread, it is * detached before being destroyed. * * @param[in] window The window to destroy. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @note The context of the specified window must not be current on any other * thread when this function is called. * * @reentrancy This function must not be called from a callback. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_creation * @sa @ref glfwCreateWindow * * @since Added in version 3.0. Replaces `glfwCloseWindow`. * * @ingroup window */ GLFWAPI void glfwDestroyWindow(GLFWwindow* window); /*! @brief Checks the close flag of the specified window. * * This function returns the value of the close flag of the specified window. * * @param[in] window The window to query. * @return The value of the close flag. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @sa @ref window_close * * @since Added in version 3.0. * * @ingroup window */ GLFWAPI int glfwWindowShouldClose(GLFWwindow* window); /*! @brief Sets the close flag of the specified window. * * This function sets the value of the close flag of the specified window. * This can be used to override the user's attempt to close the window, or * to signal that it should be closed. * * @param[in] window The window whose flag to change. * @param[in] value The new value. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @sa @ref window_close * * @since Added in version 3.0. * * @ingroup window */ GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* window, int value); /*! @brief Returns the title of the specified window. * * This function returns the window title, encoded as UTF-8, of the specified * window. This is the title set previously by @ref glfwCreateWindow * or @ref glfwSetWindowTitle. * * @param[in] window The window to query. * @return The UTF-8 encoded window title, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @remark The returned title is currently a copy of the title last set by @ref * glfwCreateWindow or @ref glfwSetWindowTitle. It does not include any * additional text which may be appended by the platform or another program. * * @pointer_lifetime The returned string is allocated and freed by GLFW. You * should not free it yourself. It is valid until the next call to @ref * glfwGetWindowTitle or @ref glfwSetWindowTitle, or until the library is * terminated. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_title * @sa @ref glfwSetWindowTitle * * @since Added in version 3.4. * * @ingroup window */ GLFWAPI const char* glfwGetWindowTitle(GLFWwindow* window); /*! @brief Sets the title of the specified window. * * This function sets the window title, encoded as UTF-8, of the specified * window. * * @param[in] window The window whose title to change. * @param[in] title The UTF-8 encoded window title. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @remark @macos The window title will not be updated until the next time you * process events. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_title * @sa @ref glfwGetWindowTitle * * @since Added in version 1.0. * @glfw3 Added window handle parameter. * * @ingroup window */ GLFWAPI void glfwSetWindowTitle(GLFWwindow* window, const char* title); /*! @brief Sets the icon for the specified window. * * This function sets the icon of the specified window. If passed an array of * candidate images, those of or closest to the sizes desired by the system are * selected. If no images are specified, the window reverts to its default * icon. * * The pixels are 32-bit, little-endian, non-premultiplied RGBA, i.e. eight * bits per channel with the red channel first. They are arranged canonically * as packed sequential rows, starting from the top-left corner. * * The desired image sizes varies depending on platform and system settings. * The selected images will be rescaled as needed. Good sizes include 16x16, * 32x32 and 48x48. * * @param[in] window The window whose icon to set. * @param[in] count The number of images in the specified array, or zero to * revert to the default window icon. * @param[in] images The images to create the icon from. This is ignored if * count is zero. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_VALUE, @ref GLFW_PLATFORM_ERROR and @ref * GLFW_FEATURE_UNAVAILABLE (see remarks). * * @pointer_lifetime The specified image data is copied before this function * returns. * * @remark @macos Regular windows do not have icons on macOS. This function * will emit @ref GLFW_FEATURE_UNAVAILABLE. The dock icon will be the same as * the application bundle's icon. For more information on bundles, see the * [Bundle Programming Guide][bundle-guide] in the Mac Developer Library. * * [bundle-guide]: https://developer.apple.com/library/mac/documentation/CoreFoundation/Conceptual/CFBundles/ * * @remark @wayland There is no existing protocol to change an icon, the * window will thus inherit the one defined in the application's desktop file. * This function will emit @ref GLFW_FEATURE_UNAVAILABLE. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_icon * * @since Added in version 3.2. * * @ingroup window */ GLFWAPI void glfwSetWindowIcon(GLFWwindow* window, int count, const GLFWimage* images); /*! @brief Retrieves the position of the content area of the specified window. * * This function retrieves the position, in screen coordinates, of the * upper-left corner of the content area of the specified window. * * Any or all of the position arguments may be `NULL`. If an error occurs, all * non-`NULL` position arguments will be set to zero. * * @param[in] window The window to query. * @param[out] xpos Where to store the x-coordinate of the upper-left corner of * the content area, or `NULL`. * @param[out] ypos Where to store the y-coordinate of the upper-left corner of * the content area, or `NULL`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_PLATFORM_ERROR and @ref GLFW_FEATURE_UNAVAILABLE (see remarks). * * @remark @wayland There is no way for an application to retrieve the global * position of its windows. This function will emit @ref * GLFW_FEATURE_UNAVAILABLE. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_pos * @sa @ref glfwSetWindowPos * * @since Added in version 3.0. * * @ingroup window */ GLFWAPI void glfwGetWindowPos(GLFWwindow* window, int* xpos, int* ypos); /*! @brief Sets the position of the content area of the specified window. * * This function sets the position, in screen coordinates, of the upper-left * corner of the content area of the specified windowed mode window. If the * window is a full screen window, this function does nothing. * * __Do not use this function__ to move an already visible window unless you * have very good reasons for doing so, as it will confuse and annoy the user. * * The window manager may put limits on what positions are allowed. GLFW * cannot and should not override these limits. * * @param[in] window The window to query. * @param[in] xpos The x-coordinate of the upper-left corner of the content area. * @param[in] ypos The y-coordinate of the upper-left corner of the content area. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_PLATFORM_ERROR and @ref GLFW_FEATURE_UNAVAILABLE (see remarks). * * @remark @wayland There is no way for an application to set the global * position of its windows. This function will emit @ref * GLFW_FEATURE_UNAVAILABLE. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_pos * @sa @ref glfwGetWindowPos * * @since Added in version 1.0. * @glfw3 Added window handle parameter. * * @ingroup window */ GLFWAPI void glfwSetWindowPos(GLFWwindow* window, int xpos, int ypos); /*! @brief Retrieves the size of the content area of the specified window. * * This function retrieves the size, in screen coordinates, of the content area * of the specified window. If you wish to retrieve the size of the * framebuffer of the window in pixels, see @ref glfwGetFramebufferSize. * * Any or all of the size arguments may be `NULL`. If an error occurs, all * non-`NULL` size arguments will be set to zero. * * @param[in] window The window whose size to retrieve. * @param[out] width Where to store the width, in screen coordinates, of the * content area, or `NULL`. * @param[out] height Where to store the height, in screen coordinates, of the * content area, or `NULL`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_size * @sa @ref glfwSetWindowSize * * @since Added in version 1.0. * @glfw3 Added window handle parameter. * * @ingroup window */ GLFWAPI void glfwGetWindowSize(GLFWwindow* window, int* width, int* height); /*! @brief Sets the size limits of the specified window. * * This function sets the size limits of the content area of the specified * window. If the window is full screen, the size limits only take effect * once it is made windowed. If the window is not resizable, this function * does nothing. * * The size limits are applied immediately to a windowed mode window and may * cause it to be resized. * * The maximum dimensions must be greater than or equal to the minimum * dimensions and all must be greater than or equal to zero. * * @param[in] window The window to set limits for. * @param[in] minwidth The minimum width, in screen coordinates, of the content * area, or `GLFW_DONT_CARE`. * @param[in] minheight The minimum height, in screen coordinates, of the * content area, or `GLFW_DONT_CARE`. * @param[in] maxwidth The maximum width, in screen coordinates, of the content * area, or `GLFW_DONT_CARE`. * @param[in] maxheight The maximum height, in screen coordinates, of the * content area, or `GLFW_DONT_CARE`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_VALUE and @ref GLFW_PLATFORM_ERROR. * * @remark If you set size limits and an aspect ratio that conflict, the * results are undefined. * * @remark @wayland The size limits will not be applied until the window is * actually resized, either by the user or by the compositor. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_sizelimits * @sa @ref glfwSetWindowAspectRatio * * @since Added in version 3.2. * * @ingroup window */ GLFWAPI void glfwSetWindowSizeLimits(GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight); /*! @brief Sets the aspect ratio of the specified window. * * This function sets the required aspect ratio of the content area of the * specified window. If the window is full screen, the aspect ratio only takes * effect once it is made windowed. If the window is not resizable, this * function does nothing. * * The aspect ratio is specified as a numerator and a denominator and both * values must be greater than zero. For example, the common 16:9 aspect ratio * is specified as 16 and 9, respectively. * * If the numerator and denominator is set to `GLFW_DONT_CARE` then the aspect * ratio limit is disabled. * * The aspect ratio is applied immediately to a windowed mode window and may * cause it to be resized. * * @param[in] window The window to set limits for. * @param[in] numer The numerator of the desired aspect ratio, or * `GLFW_DONT_CARE`. * @param[in] denom The denominator of the desired aspect ratio, or * `GLFW_DONT_CARE`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_VALUE and @ref GLFW_PLATFORM_ERROR. * * @remark If you set size limits and an aspect ratio that conflict, the * results are undefined. * * @remark @wayland The aspect ratio will not be applied until the window is * actually resized, either by the user or by the compositor. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_sizelimits * @sa @ref glfwSetWindowSizeLimits * * @since Added in version 3.2. * * @ingroup window */ GLFWAPI void glfwSetWindowAspectRatio(GLFWwindow* window, int numer, int denom); /*! @brief Sets the size of the content area of the specified window. * * This function sets the size, in screen coordinates, of the content area of * the specified window. * * For full screen windows, this function updates the resolution of its desired * video mode and switches to the video mode closest to it, without affecting * the window's context. As the context is unaffected, the bit depths of the * framebuffer remain unchanged. * * If you wish to update the refresh rate of the desired video mode in addition * to its resolution, see @ref glfwSetWindowMonitor. * * The window manager may put limits on what sizes are allowed. GLFW cannot * and should not override these limits. * * @param[in] window The window to resize. * @param[in] width The desired width, in screen coordinates, of the window * content area. * @param[in] height The desired height, in screen coordinates, of the window * content area. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_size * @sa @ref glfwGetWindowSize * @sa @ref glfwSetWindowMonitor * * @since Added in version 1.0. * @glfw3 Added window handle parameter. * * @ingroup window */ GLFWAPI void glfwSetWindowSize(GLFWwindow* window, int width, int height); /*! @brief Retrieves the size of the framebuffer of the specified window. * * This function retrieves the size, in pixels, of the framebuffer of the * specified window. If you wish to retrieve the size of the window in screen * coordinates, see @ref glfwGetWindowSize. * * Any or all of the size arguments may be `NULL`. If an error occurs, all * non-`NULL` size arguments will be set to zero. * * @param[in] window The window whose framebuffer to query. * @param[out] width Where to store the width, in pixels, of the framebuffer, * or `NULL`. * @param[out] height Where to store the height, in pixels, of the framebuffer, * or `NULL`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_fbsize * @sa @ref glfwSetFramebufferSizeCallback * * @since Added in version 3.0. * * @ingroup window */ GLFWAPI void glfwGetFramebufferSize(GLFWwindow* window, int* width, int* height); /*! @brief Retrieves the size of the frame of the window. * * This function retrieves the size, in screen coordinates, of each edge of the * frame of the specified window. This size includes the title bar, if the * window has one. The size of the frame may vary depending on the * [window-related hints](@ref window_hints_wnd) used to create it. * * Because this function retrieves the size of each window frame edge and not * the offset along a particular coordinate axis, the retrieved values will * always be zero or positive. * * Any or all of the size arguments may be `NULL`. If an error occurs, all * non-`NULL` size arguments will be set to zero. * * @param[in] window The window whose frame size to query. * @param[out] left Where to store the size, in screen coordinates, of the left * edge of the window frame, or `NULL`. * @param[out] top Where to store the size, in screen coordinates, of the top * edge of the window frame, or `NULL`. * @param[out] right Where to store the size, in screen coordinates, of the * right edge of the window frame, or `NULL`. * @param[out] bottom Where to store the size, in screen coordinates, of the * bottom edge of the window frame, or `NULL`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_size * * @since Added in version 3.1. * * @ingroup window */ GLFWAPI void glfwGetWindowFrameSize(GLFWwindow* window, int* left, int* top, int* right, int* bottom); /*! @brief Retrieves the content scale for the specified window. * * This function retrieves the content scale for the specified window. The * content scale is the ratio between the current DPI and the platform's * default DPI. This is especially important for text and any UI elements. If * the pixel dimensions of your UI scaled by this look appropriate on your * machine then it should appear at a reasonable size on other machines * regardless of their DPI and scaling settings. This relies on the system DPI * and scaling settings being somewhat correct. * * On platforms where each monitors can have its own content scale, the window * content scale will depend on which monitor the system considers the window * to be on. * * @param[in] window The window to query. * @param[out] xscale Where to store the x-axis content scale, or `NULL`. * @param[out] yscale Where to store the y-axis content scale, or `NULL`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_scale * @sa @ref glfwSetWindowContentScaleCallback * @sa @ref glfwGetMonitorContentScale * * @since Added in version 3.3. * * @ingroup window */ GLFWAPI void glfwGetWindowContentScale(GLFWwindow* window, float* xscale, float* yscale); /*! @brief Returns the opacity of the whole window. * * This function returns the opacity of the window, including any decorations. * * The opacity (or alpha) value is a positive finite number between zero and * one, where zero is fully transparent and one is fully opaque. If the system * does not support whole window transparency, this function always returns one. * * The initial opacity value for newly created windows is one. * * @param[in] window The window to query. * @return The opacity value of the specified window. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_transparency * @sa @ref glfwSetWindowOpacity * * @since Added in version 3.3. * * @ingroup window */ GLFWAPI float glfwGetWindowOpacity(GLFWwindow* window); /*! @brief Sets the opacity of the whole window. * * This function sets the opacity of the window, including any decorations. * * The opacity (or alpha) value is a positive finite number between zero and * one, where zero is fully transparent and one is fully opaque. * * The initial opacity value for newly created windows is one. * * A window created with framebuffer transparency may not use whole window * transparency. The results of doing this are undefined. * * @param[in] window The window to set the opacity for. * @param[in] opacity The desired opacity of the specified window. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_PLATFORM_ERROR and @ref GLFW_FEATURE_UNAVAILABLE (see remarks). * * @remark @wayland There is no way to set an opacity factor for a window. * This function will emit @ref GLFW_FEATURE_UNAVAILABLE. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_transparency * @sa @ref glfwGetWindowOpacity * * @since Added in version 3.3. * * @ingroup window */ GLFWAPI void glfwSetWindowOpacity(GLFWwindow* window, float opacity); /*! @brief Iconifies the specified window. * * This function iconifies (minimizes) the specified window if it was * previously restored. If the window is already iconified, this function does * nothing. * * If the specified window is a full screen window, GLFW restores the original * video mode of the monitor. The window's desired video mode is set again * when the window is restored. * * @param[in] window The window to iconify. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @remark @wayland Once a window is iconified, @ref glfwRestoreWindow won’t * be able to restore it. This is a design decision of the xdg-shell * protocol. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_iconify * @sa @ref glfwRestoreWindow * @sa @ref glfwMaximizeWindow * * @since Added in version 2.1. * @glfw3 Added window handle parameter. * * @ingroup window */ GLFWAPI void glfwIconifyWindow(GLFWwindow* window); /*! @brief Restores the specified window. * * This function restores the specified window if it was previously iconified * (minimized) or maximized. If the window is already restored, this function * does nothing. * * If the specified window is an iconified full screen window, its desired * video mode is set again for its monitor when the window is restored. * * @param[in] window The window to restore. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_iconify * @sa @ref glfwIconifyWindow * @sa @ref glfwMaximizeWindow * * @since Added in version 2.1. * @glfw3 Added window handle parameter. * * @ingroup window */ GLFWAPI void glfwRestoreWindow(GLFWwindow* window); /*! @brief Maximizes the specified window. * * This function maximizes the specified window if it was previously not * maximized. If the window is already maximized, this function does nothing. * * If the specified window is a full screen window, this function does nothing. * * @param[in] window The window to maximize. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @par Thread Safety * This function may only be called from the main thread. * * @sa @ref window_iconify * @sa @ref glfwIconifyWindow * @sa @ref glfwRestoreWindow * * @since Added in GLFW 3.2. * * @ingroup window */ GLFWAPI void glfwMaximizeWindow(GLFWwindow* window); /*! @brief Makes the specified window visible. * * This function makes the specified window visible if it was previously * hidden. If the window is already visible or is in full screen mode, this * function does nothing. * * By default, windowed mode windows are focused when shown * Set the [GLFW_FOCUS_ON_SHOW](@ref GLFW_FOCUS_ON_SHOW_hint) window hint * to change this behavior for all newly created windows, or change the * behavior for an existing window with @ref glfwSetWindowAttrib. * * @param[in] window The window to make visible. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @remark @wayland Because Wayland wants every frame of the desktop to be * complete, this function does not immediately make the window visible. * Instead it will become visible the next time the window framebuffer is * updated after this call. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_hide * @sa @ref glfwHideWindow * * @since Added in version 3.0. * * @ingroup window */ GLFWAPI void glfwShowWindow(GLFWwindow* window); /*! @brief Hides the specified window. * * This function hides the specified window if it was previously visible. If * the window is already hidden or is in full screen mode, this function does * nothing. * * @param[in] window The window to hide. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_hide * @sa @ref glfwShowWindow * * @since Added in version 3.0. * * @ingroup window */ GLFWAPI void glfwHideWindow(GLFWwindow* window); /*! @brief Brings the specified window to front and sets input focus. * * This function brings the specified window to front and sets input focus. * The window should already be visible and not iconified. * * By default, both windowed and full screen mode windows are focused when * initially created. Set the [GLFW_FOCUSED](@ref GLFW_FOCUSED_hint) to * disable this behavior. * * Also by default, windowed mode windows are focused when shown * with @ref glfwShowWindow. Set the * [GLFW_FOCUS_ON_SHOW](@ref GLFW_FOCUS_ON_SHOW_hint) to disable this behavior. * * __Do not use this function__ to steal focus from other applications unless * you are certain that is what the user wants. Focus stealing can be * extremely disruptive. * * For a less disruptive way of getting the user's attention, see * [attention requests](@ref window_attention). * * @param[in] window The window to give input focus. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @remark @wayland The compositor will likely ignore focus requests unless * another window created by the same application already has input focus. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_focus * @sa @ref window_attention * * @since Added in version 3.2. * * @ingroup window */ GLFWAPI void glfwFocusWindow(GLFWwindow* window); /*! @brief Requests user attention to the specified window. * * This function requests user attention to the specified window. On * platforms where this is not supported, attention is requested to the * application as a whole. * * Once the user has given attention, usually by focusing the window or * application, the system will end the request automatically. * * @param[in] window The window to request attention to. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @remark @macos Attention is requested to the application as a whole, not the * specific window. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_attention * * @since Added in version 3.3. * * @ingroup window */ GLFWAPI void glfwRequestWindowAttention(GLFWwindow* window); /*! @brief Returns the monitor that the window uses for full screen mode. * * This function returns the handle of the monitor that the specified window is * in full screen on. * * @param[in] window The window to query. * @return The monitor, or `NULL` if the window is in windowed mode or an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_monitor * @sa @ref glfwSetWindowMonitor * * @since Added in version 3.0. * * @ingroup window */ GLFWAPI GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* window); /*! @brief Sets the mode, monitor, video mode and placement of a window. * * This function sets the monitor that the window uses for full screen mode or, * if the monitor is `NULL`, makes it windowed mode. * * When setting a monitor, this function updates the width, height and refresh * rate of the desired video mode and switches to the video mode closest to it. * The window position is ignored when setting a monitor. * * When the monitor is `NULL`, the position, width and height are used to * place the window content area. The refresh rate is ignored when no monitor * is specified. * * If you only wish to update the resolution of a full screen window or the * size of a windowed mode window, see @ref glfwSetWindowSize. * * When a window transitions from full screen to windowed mode, this function * restores any previous window settings such as whether it is decorated, * floating, resizable, has size or aspect ratio limits, etc. * * @param[in] window The window whose monitor, size or video mode to set. * @param[in] monitor The desired monitor, or `NULL` to set windowed mode. * @param[in] xpos The desired x-coordinate of the upper-left corner of the * content area. * @param[in] ypos The desired y-coordinate of the upper-left corner of the * content area. * @param[in] width The desired with, in screen coordinates, of the content * area or video mode. * @param[in] height The desired height, in screen coordinates, of the content * area or video mode. * @param[in] refreshRate The desired refresh rate, in Hz, of the video mode, * or `GLFW_DONT_CARE`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @remark The OpenGL or OpenGL ES context will not be destroyed or otherwise * affected by any resizing or mode switching, although you may need to update * your viewport if the framebuffer size has changed. * * @remark @wayland The desired window position is ignored, as there is no way * for an application to set this property. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_monitor * @sa @ref window_full_screen * @sa @ref glfwGetWindowMonitor * @sa @ref glfwSetWindowSize * * @since Added in version 3.2. * * @ingroup window */ GLFWAPI void glfwSetWindowMonitor(GLFWwindow* window, GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); /*! @brief Returns an attribute of the specified window. * * This function returns the value of an attribute of the specified window or * its OpenGL or OpenGL ES context. * * @param[in] window The window to query. * @param[in] attrib The [window attribute](@ref window_attribs) whose value to * return. * @return The value of the attribute, or zero if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. * * @remark Framebuffer related hints are not window attributes. See @ref * window_attribs_fb for more information. * * @remark Zero is a valid value for many window and context related * attributes so you cannot use a return value of zero as an indication of * errors. However, this function should not fail as long as it is passed * valid arguments and the library has been [initialized](@ref intro_init). * * @remark @wayland The Wayland protocol provides no way to check whether a * window is iconfied, so @ref GLFW_ICONIFIED always returns `GLFW_FALSE`. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_attribs * @sa @ref glfwSetWindowAttrib * * @since Added in version 3.0. Replaces `glfwGetWindowParam` and * `glfwGetGLVersion`. * * @ingroup window */ GLFWAPI int glfwGetWindowAttrib(GLFWwindow* window, int attrib); /*! @brief Sets an attribute of the specified window. * * This function sets the value of an attribute of the specified window. * * The supported attributes are [GLFW_DECORATED](@ref GLFW_DECORATED_attrib), * [GLFW_RESIZABLE](@ref GLFW_RESIZABLE_attrib), * [GLFW_FLOATING](@ref GLFW_FLOATING_attrib), * [GLFW_AUTO_ICONIFY](@ref GLFW_AUTO_ICONIFY_attrib) and * [GLFW_FOCUS_ON_SHOW](@ref GLFW_FOCUS_ON_SHOW_attrib). * [GLFW_MOUSE_PASSTHROUGH](@ref GLFW_MOUSE_PASSTHROUGH_attrib) * * Some of these attributes are ignored for full screen windows. The new * value will take effect if the window is later made windowed. * * Some of these attributes are ignored for windowed mode windows. The new * value will take effect if the window is later made full screen. * * @param[in] window The window to set the attribute for. * @param[in] attrib A supported window attribute. * @param[in] value `GLFW_TRUE` or `GLFW_FALSE`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_ENUM, @ref GLFW_INVALID_VALUE, @ref GLFW_PLATFORM_ERROR and @ref * GLFW_FEATURE_UNAVAILABLE (see remarks). * * @remark Calling @ref glfwGetWindowAttrib will always return the latest * value, even if that value is ignored by the current mode of the window. * * @remark @wayland The [GLFW_FLOATING](@ref GLFW_FLOATING_attrib) window attribute is * not supported. Setting this will emit @ref GLFW_FEATURE_UNAVAILABLE. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_attribs * @sa @ref glfwGetWindowAttrib * * @since Added in version 3.3. * * @ingroup window */ GLFWAPI void glfwSetWindowAttrib(GLFWwindow* window, int attrib, int value); /*! @brief Sets the user pointer of the specified window. * * This function sets the user-defined pointer of the specified window. The * current value is retained until the window is destroyed. The initial value * is `NULL`. * * @param[in] window The window whose pointer to set. * @param[in] pointer The new value. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @sa @ref window_userptr * @sa @ref glfwGetWindowUserPointer * * @since Added in version 3.0. * * @ingroup window */ GLFWAPI void glfwSetWindowUserPointer(GLFWwindow* window, void* pointer); /*! @brief Returns the user pointer of the specified window. * * This function returns the current value of the user-defined pointer of the * specified window. The initial value is `NULL`. * * @param[in] window The window whose pointer to return. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @sa @ref window_userptr * @sa @ref glfwSetWindowUserPointer * * @since Added in version 3.0. * * @ingroup window */ GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* window); /*! @brief Sets the position callback for the specified window. * * This function sets the position callback of the specified window, which is * called when the window is moved. The callback is provided with the * position, in screen coordinates, of the upper-left corner of the content * area of the window. * * @param[in] window The window whose callback to set. * @param[in] callback The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(GLFWwindow* window, int xpos, int ypos) * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWwindowposfun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @remark @wayland This callback will never be called, as there is no way for * an application to know its global position. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_pos * * @since Added in version 3.0. * * @ingroup window */ GLFWAPI GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* window, GLFWwindowposfun callback); /*! @brief Sets the size callback for the specified window. * * This function sets the size callback of the specified window, which is * called when the window is resized. The callback is provided with the size, * in screen coordinates, of the content area of the window. * * @param[in] window The window whose callback to set. * @param[in] callback The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(GLFWwindow* window, int width, int height) * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWwindowsizefun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_size * * @since Added in version 1.0. * @glfw3 Added window handle parameter and return value. * * @ingroup window */ GLFWAPI GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwindowsizefun callback); /*! @brief Sets the close callback for the specified window. * * This function sets the close callback of the specified window, which is * called when the user attempts to close the window, for example by clicking * the close widget in the title bar. * * The close flag is set before this callback is called, but you can modify it * at any time with @ref glfwSetWindowShouldClose. * * The close callback is not triggered by @ref glfwDestroyWindow. * * @param[in] window The window whose callback to set. * @param[in] callback The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(GLFWwindow* window) * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWwindowclosefun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @remark @macos Selecting Quit from the application menu will trigger the * close callback for all windows. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_close * * @since Added in version 2.5. * @glfw3 Added window handle parameter and return value. * * @ingroup window */ GLFWAPI GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* window, GLFWwindowclosefun callback); /*! @brief Sets the refresh callback for the specified window. * * This function sets the refresh callback of the specified window, which is * called when the content area of the window needs to be redrawn, for example * if the window has been exposed after having been covered by another window. * * On compositing window systems such as Aero, Compiz, Aqua or Wayland, where * the window contents are saved off-screen, this callback may be called only * very infrequently or never at all. * * @param[in] window The window whose callback to set. * @param[in] callback The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(GLFWwindow* window); * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWwindowrefreshfun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_refresh * * @since Added in version 2.5. * @glfw3 Added window handle parameter and return value. * * @ingroup window */ GLFWAPI GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* window, GLFWwindowrefreshfun callback); /*! @brief Sets the focus callback for the specified window. * * This function sets the focus callback of the specified window, which is * called when the window gains or loses input focus. * * After the focus callback is called for a window that lost input focus, * synthetic key and mouse button release events will be generated for all such * that had been pressed. For more information, see @ref glfwSetKeyCallback * and @ref glfwSetMouseButtonCallback. * * @param[in] window The window whose callback to set. * @param[in] callback The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(GLFWwindow* window, int focused) * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWwindowfocusfun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_focus * * @since Added in version 3.0. * * @ingroup window */ GLFWAPI GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwindowfocusfun callback); /*! @brief Sets the iconify callback for the specified window. * * This function sets the iconification callback of the specified window, which * is called when the window is iconified or restored. * * @param[in] window The window whose callback to set. * @param[in] callback The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(GLFWwindow* window, int iconified) * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWwindowiconifyfun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_iconify * * @since Added in version 3.0. * * @ingroup window */ GLFWAPI GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* window, GLFWwindowiconifyfun callback); /*! @brief Sets the maximize callback for the specified window. * * This function sets the maximization callback of the specified window, which * is called when the window is maximized or restored. * * @param[in] window The window whose callback to set. * @param[in] callback The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(GLFWwindow* window, int maximized) * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWwindowmaximizefun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_maximize * * @since Added in version 3.3. * * @ingroup window */ GLFWAPI GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(GLFWwindow* window, GLFWwindowmaximizefun callback); /*! @brief Sets the framebuffer resize callback for the specified window. * * This function sets the framebuffer resize callback of the specified window, * which is called when the framebuffer of the specified window is resized. * * @param[in] window The window whose callback to set. * @param[in] callback The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(GLFWwindow* window, int width, int height) * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWframebuffersizefun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_fbsize * * @since Added in version 3.0. * * @ingroup window */ GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* window, GLFWframebuffersizefun callback); /*! @brief Sets the window content scale callback for the specified window. * * This function sets the window content scale callback of the specified window, * which is called when the content scale of the specified window changes. * * @param[in] window The window whose callback to set. * @param[in] callback The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(GLFWwindow* window, float xscale, float yscale) * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWwindowcontentscalefun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref window_scale * @sa @ref glfwGetWindowContentScale * * @since Added in version 3.3. * * @ingroup window */ GLFWAPI GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(GLFWwindow* window, GLFWwindowcontentscalefun callback); /*! @brief Processes all pending events. * * This function processes only those events that are already in the event * queue and then returns immediately. Processing events will cause the window * and input callbacks associated with those events to be called. * * On some platforms, a window move, resize or menu operation will cause event * processing to block. This is due to how event processing is designed on * those platforms. You can use the * [window refresh callback](@ref window_refresh) to redraw the contents of * your window when necessary during such operations. * * Do not assume that callbacks you set will _only_ be called in response to * event processing functions like this one. While it is necessary to poll for * events, window systems that require GLFW to register callbacks of its own * can pass events to GLFW in response to many window system function calls. * GLFW will pass those events on to the application callbacks before * returning. * * Event processing is not required for joystick input to work. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @reentrancy This function must not be called from a callback. * * @thread_safety This function must only be called from the main thread. * * @sa @ref events * @sa @ref glfwWaitEvents * @sa @ref glfwWaitEventsTimeout * * @since Added in version 1.0. * * @ingroup window */ GLFWAPI void glfwPollEvents(void); /*! @brief Waits until events are queued and processes them. * * This function puts the calling thread to sleep until at least one event is * available in the event queue. Once one or more events are available, * it behaves exactly like @ref glfwPollEvents, i.e. the events in the queue * are processed and the function then returns immediately. Processing events * will cause the window and input callbacks associated with those events to be * called. * * Since not all events are associated with callbacks, this function may return * without a callback having been called even if you are monitoring all * callbacks. * * On some platforms, a window move, resize or menu operation will cause event * processing to block. This is due to how event processing is designed on * those platforms. You can use the * [window refresh callback](@ref window_refresh) to redraw the contents of * your window when necessary during such operations. * * Do not assume that callbacks you set will _only_ be called in response to * event processing functions like this one. While it is necessary to poll for * events, window systems that require GLFW to register callbacks of its own * can pass events to GLFW in response to many window system function calls. * GLFW will pass those events on to the application callbacks before * returning. * * Event processing is not required for joystick input to work. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @reentrancy This function must not be called from a callback. * * @thread_safety This function must only be called from the main thread. * * @sa @ref events * @sa @ref glfwPollEvents * @sa @ref glfwWaitEventsTimeout * * @since Added in version 2.5. * * @ingroup window */ GLFWAPI void glfwWaitEvents(void); /*! @brief Waits with timeout until events are queued and processes them. * * This function puts the calling thread to sleep until at least one event is * available in the event queue, or until the specified timeout is reached. If * one or more events are available, it behaves exactly like @ref * glfwPollEvents, i.e. the events in the queue are processed and the function * then returns immediately. Processing events will cause the window and input * callbacks associated with those events to be called. * * The timeout value must be a positive finite number. * * Since not all events are associated with callbacks, this function may return * without a callback having been called even if you are monitoring all * callbacks. * * On some platforms, a window move, resize or menu operation will cause event * processing to block. This is due to how event processing is designed on * those platforms. You can use the * [window refresh callback](@ref window_refresh) to redraw the contents of * your window when necessary during such operations. * * Do not assume that callbacks you set will _only_ be called in response to * event processing functions like this one. While it is necessary to poll for * events, window systems that require GLFW to register callbacks of its own * can pass events to GLFW in response to many window system function calls. * GLFW will pass those events on to the application callbacks before * returning. * * Event processing is not required for joystick input to work. * * @param[in] timeout The maximum amount of time, in seconds, to wait. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_VALUE and @ref GLFW_PLATFORM_ERROR. * * @reentrancy This function must not be called from a callback. * * @thread_safety This function must only be called from the main thread. * * @sa @ref events * @sa @ref glfwPollEvents * @sa @ref glfwWaitEvents * * @since Added in version 3.2. * * @ingroup window */ GLFWAPI void glfwWaitEventsTimeout(double timeout); /*! @brief Posts an empty event to the event queue. * * This function posts an empty event from the current thread to the event * queue, causing @ref glfwWaitEvents or @ref glfwWaitEventsTimeout to return. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @thread_safety This function may be called from any thread. * * @sa @ref events * @sa @ref glfwWaitEvents * @sa @ref glfwWaitEventsTimeout * * @since Added in version 3.1. * * @ingroup window */ GLFWAPI void glfwPostEmptyEvent(void); /*! @brief Returns the value of an input option for the specified window. * * This function returns the value of an input option for the specified window. * The mode must be one of @ref GLFW_CURSOR, @ref GLFW_STICKY_KEYS, * @ref GLFW_STICKY_MOUSE_BUTTONS, @ref GLFW_LOCK_KEY_MODS or * @ref GLFW_RAW_MOUSE_MOTION. * * @param[in] window The window to query. * @param[in] mode One of `GLFW_CURSOR`, `GLFW_STICKY_KEYS`, * `GLFW_STICKY_MOUSE_BUTTONS`, `GLFW_LOCK_KEY_MODS` or * `GLFW_RAW_MOUSE_MOTION`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_INVALID_ENUM. * * @thread_safety This function must only be called from the main thread. * * @sa @ref glfwSetInputMode * * @since Added in version 3.0. * * @ingroup input */ GLFWAPI int glfwGetInputMode(GLFWwindow* window, int mode); /*! @brief Sets an input option for the specified window. * * This function sets an input mode option for the specified window. The mode * must be one of @ref GLFW_CURSOR, @ref GLFW_STICKY_KEYS, * @ref GLFW_STICKY_MOUSE_BUTTONS, @ref GLFW_LOCK_KEY_MODS or * @ref GLFW_RAW_MOUSE_MOTION. * * If the mode is `GLFW_CURSOR`, the value must be one of the following cursor * modes: * - `GLFW_CURSOR_NORMAL` makes the cursor visible and behaving normally. * - `GLFW_CURSOR_HIDDEN` makes the cursor invisible when it is over the * content area of the window but does not restrict the cursor from leaving. * - `GLFW_CURSOR_DISABLED` hides and grabs the cursor, providing virtual * and unlimited cursor movement. This is useful for implementing for * example 3D camera controls. * - `GLFW_CURSOR_CAPTURED` makes the cursor visible and confines it to the * content area of the window. * * If the mode is `GLFW_STICKY_KEYS`, the value must be either `GLFW_TRUE` to * enable sticky keys, or `GLFW_FALSE` to disable it. If sticky keys are * enabled, a key press will ensure that @ref glfwGetKey returns `GLFW_PRESS` * the next time it is called even if the key had been released before the * call. This is useful when you are only interested in whether keys have been * pressed but not when or in which order. * * If the mode is `GLFW_STICKY_MOUSE_BUTTONS`, the value must be either * `GLFW_TRUE` to enable sticky mouse buttons, or `GLFW_FALSE` to disable it. * If sticky mouse buttons are enabled, a mouse button press will ensure that * @ref glfwGetMouseButton returns `GLFW_PRESS` the next time it is called even * if the mouse button had been released before the call. This is useful when * you are only interested in whether mouse buttons have been pressed but not * when or in which order. * * If the mode is `GLFW_LOCK_KEY_MODS`, the value must be either `GLFW_TRUE` to * enable lock key modifier bits, or `GLFW_FALSE` to disable them. If enabled, * callbacks that receive modifier bits will also have the @ref * GLFW_MOD_CAPS_LOCK bit set when the event was generated with Caps Lock on, * and the @ref GLFW_MOD_NUM_LOCK bit when Num Lock was on. * * If the mode is `GLFW_RAW_MOUSE_MOTION`, the value must be either `GLFW_TRUE` * to enable raw (unscaled and unaccelerated) mouse motion when the cursor is * disabled, or `GLFW_FALSE` to disable it. If raw motion is not supported, * attempting to set this will emit @ref GLFW_FEATURE_UNAVAILABLE. Call @ref * glfwRawMouseMotionSupported to check for support. * * @param[in] window The window whose input mode to set. * @param[in] mode One of `GLFW_CURSOR`, `GLFW_STICKY_KEYS`, * `GLFW_STICKY_MOUSE_BUTTONS`, `GLFW_LOCK_KEY_MODS` or * `GLFW_RAW_MOUSE_MOTION`. * @param[in] value The new value of the specified input mode. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_ENUM, @ref GLFW_PLATFORM_ERROR and @ref * GLFW_FEATURE_UNAVAILABLE (see above). * * @thread_safety This function must only be called from the main thread. * * @sa @ref glfwGetInputMode * * @since Added in version 3.0. Replaces `glfwEnable` and `glfwDisable`. * * @ingroup input */ GLFWAPI void glfwSetInputMode(GLFWwindow* window, int mode, int value); /*! @brief Returns whether raw mouse motion is supported. * * This function returns whether raw mouse motion is supported on the current * system. This status does not change after GLFW has been initialized so you * only need to check this once. If you attempt to enable raw motion on * a system that does not support it, @ref GLFW_PLATFORM_ERROR will be emitted. * * Raw mouse motion is closer to the actual motion of the mouse across * a surface. It is not affected by the scaling and acceleration applied to * the motion of the desktop cursor. That processing is suitable for a cursor * while raw motion is better for controlling for example a 3D camera. Because * of this, raw mouse motion is only provided when the cursor is disabled. * * @return `GLFW_TRUE` if raw mouse motion is supported on the current machine, * or `GLFW_FALSE` otherwise. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref raw_mouse_motion * @sa @ref glfwSetInputMode * * @since Added in version 3.3. * * @ingroup input */ GLFWAPI int glfwRawMouseMotionSupported(void); /*! @brief Returns the layout-specific name of the specified printable key. * * This function returns the name of the specified printable key, encoded as * UTF-8. This is typically the character that key would produce without any * modifier keys, intended for displaying key bindings to the user. For dead * keys, it is typically the diacritic it would add to a character. * * __Do not use this function__ for [text input](@ref input_char). You will * break text input for many languages even if it happens to work for yours. * * If the key is `GLFW_KEY_UNKNOWN`, the scancode is used to identify the key, * otherwise the scancode is ignored. If you specify a non-printable key, or * `GLFW_KEY_UNKNOWN` and a scancode that maps to a non-printable key, this * function returns `NULL` but does not emit an error. * * This behavior allows you to always pass in the arguments in the * [key callback](@ref input_key) without modification. * * The printable keys are: * - `GLFW_KEY_APOSTROPHE` * - `GLFW_KEY_COMMA` * - `GLFW_KEY_MINUS` * - `GLFW_KEY_PERIOD` * - `GLFW_KEY_SLASH` * - `GLFW_KEY_SEMICOLON` * - `GLFW_KEY_EQUAL` * - `GLFW_KEY_LEFT_BRACKET` * - `GLFW_KEY_RIGHT_BRACKET` * - `GLFW_KEY_BACKSLASH` * - `GLFW_KEY_WORLD_1` * - `GLFW_KEY_WORLD_2` * - `GLFW_KEY_0` to `GLFW_KEY_9` * - `GLFW_KEY_A` to `GLFW_KEY_Z` * - `GLFW_KEY_KP_0` to `GLFW_KEY_KP_9` * - `GLFW_KEY_KP_DECIMAL` * - `GLFW_KEY_KP_DIVIDE` * - `GLFW_KEY_KP_MULTIPLY` * - `GLFW_KEY_KP_SUBTRACT` * - `GLFW_KEY_KP_ADD` * - `GLFW_KEY_KP_EQUAL` * * Names for printable keys depend on keyboard layout, while names for * non-printable keys are the same across layouts but depend on the application * language and should be localized along with other user interface text. * * @param[in] key The key to query, or `GLFW_KEY_UNKNOWN`. * @param[in] scancode The scancode of the key to query. * @return The UTF-8 encoded, layout-specific name of the key, or `NULL`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_VALUE, @ref GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. * * @remark The contents of the returned string may change when a keyboard * layout change event is received. * * @pointer_lifetime The returned string is allocated and freed by GLFW. You * should not free it yourself. It is valid until the library is terminated. * * @thread_safety This function must only be called from the main thread. * * @sa @ref input_key_name * * @since Added in version 3.2. * * @ingroup input */ GLFWAPI const char* glfwGetKeyName(int key, int scancode); /*! @brief Returns the platform-specific scancode of the specified key. * * This function returns the platform-specific scancode of the specified key. * * If the specified [key token](@ref keys) corresponds to a physical key not * supported on the current platform then this method will return `-1`. * Calling this function with anything other than a key token will return `-1` * and generate a @ref GLFW_INVALID_ENUM error. * * @param[in] key Any [key token](@ref keys). * @return The platform-specific scancode for the key, or `-1` if the key is * not supported on the current platform or an [error](@ref error_handling) * occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_INVALID_ENUM. * * @thread_safety This function may be called from any thread. * * @sa @ref input_key * * @since Added in version 3.3. * * @ingroup input */ GLFWAPI int glfwGetKeyScancode(int key); /*! @brief Returns the last reported state of a keyboard key for the specified * window. * * This function returns the last state reported for the specified key to the * specified window. The returned state is one of `GLFW_PRESS` or * `GLFW_RELEASE`. The action `GLFW_REPEAT` is only reported to the key callback. * * If the @ref GLFW_STICKY_KEYS input mode is enabled, this function returns * `GLFW_PRESS` the first time you call it for a key that was pressed, even if * that key has already been released. * * The key functions deal with physical keys, with [key tokens](@ref keys) * named after their use on the standard US keyboard layout. If you want to * input text, use the Unicode character callback instead. * * The [modifier key bit masks](@ref mods) are not key tokens and cannot be * used with this function. * * __Do not use this function__ to implement [text input](@ref input_char). * * @param[in] window The desired window. * @param[in] key The desired [keyboard key](@ref keys). `GLFW_KEY_UNKNOWN` is * not a valid key for this function. * @return One of `GLFW_PRESS` or `GLFW_RELEASE`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_INVALID_ENUM. * * @thread_safety This function must only be called from the main thread. * * @sa @ref input_key * * @since Added in version 1.0. * @glfw3 Added window handle parameter. * * @ingroup input */ GLFWAPI int glfwGetKey(GLFWwindow* window, int key); /*! @brief Returns the last reported state of a mouse button for the specified * window. * * This function returns the last state reported for the specified mouse button * to the specified window. The returned state is one of `GLFW_PRESS` or * `GLFW_RELEASE`. * * If the @ref GLFW_STICKY_MOUSE_BUTTONS input mode is enabled, this function * returns `GLFW_PRESS` the first time you call it for a mouse button that was * pressed, even if that mouse button has already been released. * * @param[in] window The desired window. * @param[in] button The desired [mouse button](@ref buttons). * @return One of `GLFW_PRESS` or `GLFW_RELEASE`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_INVALID_ENUM. * * @thread_safety This function must only be called from the main thread. * * @sa @ref input_mouse_button * * @since Added in version 1.0. * @glfw3 Added window handle parameter. * * @ingroup input */ GLFWAPI int glfwGetMouseButton(GLFWwindow* window, int button); /*! @brief Retrieves the position of the cursor relative to the content area of * the window. * * This function returns the position of the cursor, in screen coordinates, * relative to the upper-left corner of the content area of the specified * window. * * If the cursor is disabled (with `GLFW_CURSOR_DISABLED`) then the cursor * position is unbounded and limited only by the minimum and maximum values of * a `double`. * * The coordinate can be converted to their integer equivalents with the * `floor` function. Casting directly to an integer type works for positive * coordinates, but fails for negative ones. * * Any or all of the position arguments may be `NULL`. If an error occurs, all * non-`NULL` position arguments will be set to zero. * * @param[in] window The desired window. * @param[out] xpos Where to store the cursor x-coordinate, relative to the * left edge of the content area, or `NULL`. * @param[out] ypos Where to store the cursor y-coordinate, relative to the to * top edge of the content area, or `NULL`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @thread_safety This function must only be called from the main thread. * * @sa @ref cursor_pos * @sa @ref glfwSetCursorPos * * @since Added in version 3.0. Replaces `glfwGetMousePos`. * * @ingroup input */ GLFWAPI void glfwGetCursorPos(GLFWwindow* window, double* xpos, double* ypos); /*! @brief Sets the position of the cursor, relative to the content area of the * window. * * This function sets the position, in screen coordinates, of the cursor * relative to the upper-left corner of the content area of the specified * window. The window must have input focus. If the window does not have * input focus when this function is called, it fails silently. * * __Do not use this function__ to implement things like camera controls. GLFW * already provides the `GLFW_CURSOR_DISABLED` cursor mode that hides the * cursor, transparently re-centers it and provides unconstrained cursor * motion. See @ref glfwSetInputMode for more information. * * If the cursor mode is `GLFW_CURSOR_DISABLED` then the cursor position is * unconstrained and limited only by the minimum and maximum values of * a `double`. * * @param[in] window The desired window. * @param[in] xpos The desired x-coordinate, relative to the left edge of the * content area. * @param[in] ypos The desired y-coordinate, relative to the top edge of the * content area. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_PLATFORM_ERROR and @ref GLFW_FEATURE_UNAVAILABLE (see remarks). * * @remark @wayland This function will only work when the cursor mode is * `GLFW_CURSOR_DISABLED`, otherwise it will emit @ref GLFW_FEATURE_UNAVAILABLE. * * @thread_safety This function must only be called from the main thread. * * @sa @ref cursor_pos * @sa @ref glfwGetCursorPos * * @since Added in version 3.0. Replaces `glfwSetMousePos`. * * @ingroup input */ GLFWAPI void glfwSetCursorPos(GLFWwindow* window, double xpos, double ypos); /*! @brief Creates a custom cursor. * * Creates a new custom cursor image that can be set for a window with @ref * glfwSetCursor. The cursor can be destroyed with @ref glfwDestroyCursor. * Any remaining cursors are destroyed by @ref glfwTerminate. * * The pixels are 32-bit, little-endian, non-premultiplied RGBA, i.e. eight * bits per channel with the red channel first. They are arranged canonically * as packed sequential rows, starting from the top-left corner. * * The cursor hotspot is specified in pixels, relative to the upper-left corner * of the cursor image. Like all other coordinate systems in GLFW, the X-axis * points to the right and the Y-axis points down. * * @param[in] image The desired cursor image. * @param[in] xhot The desired x-coordinate, in pixels, of the cursor hotspot. * @param[in] yhot The desired y-coordinate, in pixels, of the cursor hotspot. * @return The handle of the created cursor, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_VALUE and @ref GLFW_PLATFORM_ERROR. * * @pointer_lifetime The specified image data is copied before this function * returns. * * @thread_safety This function must only be called from the main thread. * * @sa @ref cursor_object * @sa @ref glfwDestroyCursor * @sa @ref glfwCreateStandardCursor * * @since Added in version 3.1. * * @ingroup input */ GLFWAPI GLFWcursor* glfwCreateCursor(const GLFWimage* image, int xhot, int yhot); /*! @brief Creates a cursor with a standard shape. * * Returns a cursor with a standard shape, that can be set for a window with * @ref glfwSetCursor. The images for these cursors come from the system * cursor theme and their exact appearance will vary between platforms. * * Most of these shapes are guaranteed to exist on every supported platform but * a few may not be present. See the table below for details. * * Cursor shape | Windows | macOS | X11 | Wayland * ------------------------------ | ------- | ----- | ------ | ------- * @ref GLFW_ARROW_CURSOR | Yes | Yes | Yes | Yes * @ref GLFW_IBEAM_CURSOR | Yes | Yes | Yes | Yes * @ref GLFW_CROSSHAIR_CURSOR | Yes | Yes | Yes | Yes * @ref GLFW_POINTING_HAND_CURSOR | Yes | Yes | Yes | Yes * @ref GLFW_RESIZE_EW_CURSOR | Yes | Yes | Yes | Yes * @ref GLFW_RESIZE_NS_CURSOR | Yes | Yes | Yes | Yes * @ref GLFW_RESIZE_NWSE_CURSOR | Yes | Yes<sup>1</sup> | Maybe<sup>2</sup> | Maybe<sup>2</sup> * @ref GLFW_RESIZE_NESW_CURSOR | Yes | Yes<sup>1</sup> | Maybe<sup>2</sup> | Maybe<sup>2</sup> * @ref GLFW_RESIZE_ALL_CURSOR | Yes | Yes | Yes | Yes * @ref GLFW_NOT_ALLOWED_CURSOR | Yes | Yes | Maybe<sup>2</sup> | Maybe<sup>2</sup> * * 1) This uses a private system API and may fail in the future. * * 2) This uses a newer standard that not all cursor themes support. * * If the requested shape is not available, this function emits a @ref * GLFW_CURSOR_UNAVAILABLE error and returns `NULL`. * * @param[in] shape One of the [standard shapes](@ref shapes). * @return A new cursor ready to use or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_ENUM, @ref GLFW_CURSOR_UNAVAILABLE and @ref * GLFW_PLATFORM_ERROR. * * @thread_safety This function must only be called from the main thread. * * @sa @ref cursor_standard * @sa @ref glfwCreateCursor * * @since Added in version 3.1. * * @ingroup input */ GLFWAPI GLFWcursor* glfwCreateStandardCursor(int shape); /*! @brief Destroys a cursor. * * This function destroys a cursor previously created with @ref * glfwCreateCursor. Any remaining cursors will be destroyed by @ref * glfwTerminate. * * If the specified cursor is current for any window, that window will be * reverted to the default cursor. This does not affect the cursor mode. * * @param[in] cursor The cursor object to destroy. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @reentrancy This function must not be called from a callback. * * @thread_safety This function must only be called from the main thread. * * @sa @ref cursor_object * @sa @ref glfwCreateCursor * * @since Added in version 3.1. * * @ingroup input */ GLFWAPI void glfwDestroyCursor(GLFWcursor* cursor); /*! @brief Sets the cursor for the window. * * This function sets the cursor image to be used when the cursor is over the * content area of the specified window. The set cursor will only be visible * when the [cursor mode](@ref cursor_mode) of the window is * `GLFW_CURSOR_NORMAL`. * * On some platforms, the set cursor may not be visible unless the window also * has input focus. * * @param[in] window The window to set the cursor for. * @param[in] cursor The cursor to set, or `NULL` to switch back to the default * arrow cursor. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @thread_safety This function must only be called from the main thread. * * @sa @ref cursor_object * * @since Added in version 3.1. * * @ingroup input */ GLFWAPI void glfwSetCursor(GLFWwindow* window, GLFWcursor* cursor); /*! @brief Sets the key callback. * * This function sets the key callback of the specified window, which is called * when a key is pressed, repeated or released. * * The key functions deal with physical keys, with layout independent * [key tokens](@ref keys) named after their values in the standard US keyboard * layout. If you want to input text, use the * [character callback](@ref glfwSetCharCallback) instead. * * When a window loses input focus, it will generate synthetic key release * events for all pressed keys with associated key tokens. You can tell these * events from user-generated events by the fact that the synthetic ones are * generated after the focus loss event has been processed, i.e. after the * [window focus callback](@ref glfwSetWindowFocusCallback) has been called. * * The scancode of a key is specific to that platform or sometimes even to that * machine. Scancodes are intended to allow users to bind keys that don't have * a GLFW key token. Such keys have `key` set to `GLFW_KEY_UNKNOWN`, their * state is not saved and so it cannot be queried with @ref glfwGetKey. * * Sometimes GLFW needs to generate synthetic key events, in which case the * scancode may be zero. * * @param[in] window The window whose callback to set. * @param[in] callback The new key callback, or `NULL` to remove the currently * set callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(GLFWwindow* window, int key, int scancode, int action, int mods) * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWkeyfun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref input_key * * @since Added in version 1.0. * @glfw3 Added window handle parameter and return value. * * @ingroup input */ GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow* window, GLFWkeyfun callback); /*! @brief Sets the Unicode character callback. * * This function sets the character callback of the specified window, which is * called when a Unicode character is input. * * The character callback is intended for Unicode text input. As it deals with * characters, it is keyboard layout dependent, whereas the * [key callback](@ref glfwSetKeyCallback) is not. Characters do not map 1:1 * to physical keys, as a key may produce zero, one or more characters. If you * want to know whether a specific physical key was pressed or released, see * the key callback instead. * * The character callback behaves as system text input normally does and will * not be called if modifier keys are held down that would prevent normal text * input on that platform, for example a Super (Command) key on macOS or Alt key * on Windows. * * @param[in] window The window whose callback to set. * @param[in] callback The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(GLFWwindow* window, unsigned int codepoint) * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWcharfun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref input_char * * @since Added in version 2.4. * @glfw3 Added window handle parameter and return value. * * @ingroup input */ GLFWAPI GLFWcharfun glfwSetCharCallback(GLFWwindow* window, GLFWcharfun callback); /*! @brief Sets the Unicode character with modifiers callback. * * This function sets the character with modifiers callback of the specified * window, which is called when a Unicode character is input regardless of what * modifier keys are used. * * The character with modifiers callback is intended for implementing custom * Unicode character input. For regular Unicode text input, see the * [character callback](@ref glfwSetCharCallback). Like the character * callback, the character with modifiers callback deals with characters and is * keyboard layout dependent. Characters do not map 1:1 to physical keys, as * a key may produce zero, one or more characters. If you want to know whether * a specific physical key was pressed or released, see the * [key callback](@ref glfwSetKeyCallback) instead. * * @param[in] window The window whose callback to set. * @param[in] callback The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set or an * [error](@ref error_handling) occurred. * * @callback_signature * @code * void function_name(GLFWwindow* window, unsigned int codepoint, int mods) * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWcharmodsfun). * * @deprecated Scheduled for removal in version 4.0. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref input_char * * @since Added in version 3.1. * * @ingroup input */ GLFWAPI GLFWcharmodsfun glfwSetCharModsCallback(GLFWwindow* window, GLFWcharmodsfun callback); /*! @brief Sets the mouse button callback. * * This function sets the mouse button callback of the specified window, which * is called when a mouse button is pressed or released. * * When a window loses input focus, it will generate synthetic mouse button * release events for all pressed mouse buttons. You can tell these events * from user-generated events by the fact that the synthetic ones are generated * after the focus loss event has been processed, i.e. after the * [window focus callback](@ref glfwSetWindowFocusCallback) has been called. * * @param[in] window The window whose callback to set. * @param[in] callback The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(GLFWwindow* window, int button, int action, int mods) * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWmousebuttonfun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref input_mouse_button * * @since Added in version 1.0. * @glfw3 Added window handle parameter and return value. * * @ingroup input */ GLFWAPI GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun callback); /*! @brief Sets the cursor position callback. * * This function sets the cursor position callback of the specified window, * which is called when the cursor is moved. The callback is provided with the * position, in screen coordinates, relative to the upper-left corner of the * content area of the window. * * @param[in] window The window whose callback to set. * @param[in] callback The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(GLFWwindow* window, double xpos, double ypos); * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWcursorposfun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref cursor_pos * * @since Added in version 3.0. Replaces `glfwSetMousePosCallback`. * * @ingroup input */ GLFWAPI GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* window, GLFWcursorposfun callback); /*! @brief Sets the cursor enter/leave callback. * * This function sets the cursor boundary crossing callback of the specified * window, which is called when the cursor enters or leaves the content area of * the window. * * @param[in] window The window whose callback to set. * @param[in] callback The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(GLFWwindow* window, int entered) * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWcursorenterfun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref cursor_enter * * @since Added in version 3.0. * * @ingroup input */ GLFWAPI GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow* window, GLFWcursorenterfun callback); /*! @brief Sets the scroll callback. * * This function sets the scroll callback of the specified window, which is * called when a scrolling device is used, such as a mouse wheel or scrolling * area of a touchpad. * * The scroll callback receives all scrolling input, like that from a mouse * wheel or a touchpad scrolling area. * * @param[in] window The window whose callback to set. * @param[in] callback The new scroll callback, or `NULL` to remove the * currently set callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(GLFWwindow* window, double xoffset, double yoffset) * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWscrollfun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref scrolling * * @since Added in version 3.0. Replaces `glfwSetMouseWheelCallback`. * * @ingroup input */ GLFWAPI GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun callback); /*! @brief Sets the path drop callback. * * This function sets the path drop callback of the specified window, which is * called when one or more dragged paths are dropped on the window. * * Because the path array and its strings may have been generated specifically * for that event, they are not guaranteed to be valid after the callback has * returned. If you wish to use them after the callback returns, you need to * make a deep copy. * * @param[in] window The window whose callback to set. * @param[in] callback The new file drop callback, or `NULL` to remove the * currently set callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(GLFWwindow* window, int path_count, const char* paths[]) * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWdropfun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref path_drop * * @since Added in version 3.1. * * @ingroup input */ GLFWAPI GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun callback); /*! @brief Returns whether the specified joystick is present. * * This function returns whether the specified joystick is present. * * There is no need to call this function before other functions that accept * a joystick ID, as they all check for presence before performing any other * work. * * @param[in] jid The [joystick](@ref joysticks) to query. * @return `GLFW_TRUE` if the joystick is present, or `GLFW_FALSE` otherwise. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. * * @thread_safety This function must only be called from the main thread. * * @sa @ref joystick * * @since Added in version 3.0. Replaces `glfwGetJoystickParam`. * * @ingroup input */ GLFWAPI int glfwJoystickPresent(int jid); /*! @brief Returns the values of all axes of the specified joystick. * * This function returns the values of all axes of the specified joystick. * Each element in the array is a value between -1.0 and 1.0. * * If the specified joystick is not present this function will return `NULL` * but will not generate an error. This can be used instead of first calling * @ref glfwJoystickPresent. * * @param[in] jid The [joystick](@ref joysticks) to query. * @param[out] count Where to store the number of axis values in the returned * array. This is set to zero if the joystick is not present or an error * occurred. * @return An array of axis values, or `NULL` if the joystick is not present or * an [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. * * @pointer_lifetime The returned array is allocated and freed by GLFW. You * should not free it yourself. It is valid until the specified joystick is * disconnected or the library is terminated. * * @thread_safety This function must only be called from the main thread. * * @sa @ref joystick_axis * * @since Added in version 3.0. Replaces `glfwGetJoystickPos`. * * @ingroup input */ GLFWAPI const float* glfwGetJoystickAxes(int jid, int* count); /*! @brief Returns the state of all buttons of the specified joystick. * * This function returns the state of all buttons of the specified joystick. * Each element in the array is either `GLFW_PRESS` or `GLFW_RELEASE`. * * For backward compatibility with earlier versions that did not have @ref * glfwGetJoystickHats, the button array also includes all hats, each * represented as four buttons. The hats are in the same order as returned by * __glfwGetJoystickHats__ and are in the order _up_, _right_, _down_ and * _left_. To disable these extra buttons, set the @ref * GLFW_JOYSTICK_HAT_BUTTONS init hint before initialization. * * If the specified joystick is not present this function will return `NULL` * but will not generate an error. This can be used instead of first calling * @ref glfwJoystickPresent. * * @param[in] jid The [joystick](@ref joysticks) to query. * @param[out] count Where to store the number of button states in the returned * array. This is set to zero if the joystick is not present or an error * occurred. * @return An array of button states, or `NULL` if the joystick is not present * or an [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. * * @pointer_lifetime The returned array is allocated and freed by GLFW. You * should not free it yourself. It is valid until the specified joystick is * disconnected or the library is terminated. * * @thread_safety This function must only be called from the main thread. * * @sa @ref joystick_button * * @since Added in version 2.2. * @glfw3 Changed to return a dynamic array. * * @ingroup input */ GLFWAPI const unsigned char* glfwGetJoystickButtons(int jid, int* count); /*! @brief Returns the state of all hats of the specified joystick. * * This function returns the state of all hats of the specified joystick. * Each element in the array is one of the following values: * * Name | Value * ---- | ----- * `GLFW_HAT_CENTERED` | 0 * `GLFW_HAT_UP` | 1 * `GLFW_HAT_RIGHT` | 2 * `GLFW_HAT_DOWN` | 4 * `GLFW_HAT_LEFT` | 8 * `GLFW_HAT_RIGHT_UP` | `GLFW_HAT_RIGHT` \| `GLFW_HAT_UP` * `GLFW_HAT_RIGHT_DOWN` | `GLFW_HAT_RIGHT` \| `GLFW_HAT_DOWN` * `GLFW_HAT_LEFT_UP` | `GLFW_HAT_LEFT` \| `GLFW_HAT_UP` * `GLFW_HAT_LEFT_DOWN` | `GLFW_HAT_LEFT` \| `GLFW_HAT_DOWN` * * The diagonal directions are bitwise combinations of the primary (up, right, * down and left) directions and you can test for these individually by ANDing * it with the corresponding direction. * * @code * if (hats[2] & GLFW_HAT_RIGHT) * { * // State of hat 2 could be right-up, right or right-down * } * @endcode * * If the specified joystick is not present this function will return `NULL` * but will not generate an error. This can be used instead of first calling * @ref glfwJoystickPresent. * * @param[in] jid The [joystick](@ref joysticks) to query. * @param[out] count Where to store the number of hat states in the returned * array. This is set to zero if the joystick is not present or an error * occurred. * @return An array of hat states, or `NULL` if the joystick is not present * or an [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. * * @pointer_lifetime The returned array is allocated and freed by GLFW. You * should not free it yourself. It is valid until the specified joystick is * disconnected, this function is called again for that joystick or the library * is terminated. * * @thread_safety This function must only be called from the main thread. * * @sa @ref joystick_hat * * @since Added in version 3.3. * * @ingroup input */ GLFWAPI const unsigned char* glfwGetJoystickHats(int jid, int* count); /*! @brief Returns the name of the specified joystick. * * This function returns the name, encoded as UTF-8, of the specified joystick. * The returned string is allocated and freed by GLFW. You should not free it * yourself. * * If the specified joystick is not present this function will return `NULL` * but will not generate an error. This can be used instead of first calling * @ref glfwJoystickPresent. * * @param[in] jid The [joystick](@ref joysticks) to query. * @return The UTF-8 encoded name of the joystick, or `NULL` if the joystick * is not present or an [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. * * @pointer_lifetime The returned string is allocated and freed by GLFW. You * should not free it yourself. It is valid until the specified joystick is * disconnected or the library is terminated. * * @thread_safety This function must only be called from the main thread. * * @sa @ref joystick_name * * @since Added in version 3.0. * * @ingroup input */ GLFWAPI const char* glfwGetJoystickName(int jid); /*! @brief Returns the SDL compatible GUID of the specified joystick. * * This function returns the SDL compatible GUID, as a UTF-8 encoded * hexadecimal string, of the specified joystick. The returned string is * allocated and freed by GLFW. You should not free it yourself. * * The GUID is what connects a joystick to a gamepad mapping. A connected * joystick will always have a GUID even if there is no gamepad mapping * assigned to it. * * If the specified joystick is not present this function will return `NULL` * but will not generate an error. This can be used instead of first calling * @ref glfwJoystickPresent. * * The GUID uses the format introduced in SDL 2.0.5. This GUID tries to * uniquely identify the make and model of a joystick but does not identify * a specific unit, e.g. all wired Xbox 360 controllers will have the same * GUID on that platform. The GUID for a unit may vary between platforms * depending on what hardware information the platform specific APIs provide. * * @param[in] jid The [joystick](@ref joysticks) to query. * @return The UTF-8 encoded GUID of the joystick, or `NULL` if the joystick * is not present or an [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_INVALID_ENUM and @ref GLFW_PLATFORM_ERROR. * * @pointer_lifetime The returned string is allocated and freed by GLFW. You * should not free it yourself. It is valid until the specified joystick is * disconnected or the library is terminated. * * @thread_safety This function must only be called from the main thread. * * @sa @ref gamepad * * @since Added in version 3.3. * * @ingroup input */ GLFWAPI const char* glfwGetJoystickGUID(int jid); /*! @brief Sets the user pointer of the specified joystick. * * This function sets the user-defined pointer of the specified joystick. The * current value is retained until the joystick is disconnected. The initial * value is `NULL`. * * This function may be called from the joystick callback, even for a joystick * that is being disconnected. * * @param[in] jid The joystick whose pointer to set. * @param[in] pointer The new value. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @sa @ref joystick_userptr * @sa @ref glfwGetJoystickUserPointer * * @since Added in version 3.3. * * @ingroup input */ GLFWAPI void glfwSetJoystickUserPointer(int jid, void* pointer); /*! @brief Returns the user pointer of the specified joystick. * * This function returns the current value of the user-defined pointer of the * specified joystick. The initial value is `NULL`. * * This function may be called from the joystick callback, even for a joystick * that is being disconnected. * * @param[in] jid The joystick whose pointer to return. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function may be called from any thread. Access is not * synchronized. * * @sa @ref joystick_userptr * @sa @ref glfwSetJoystickUserPointer * * @since Added in version 3.3. * * @ingroup input */ GLFWAPI void* glfwGetJoystickUserPointer(int jid); /*! @brief Returns whether the specified joystick has a gamepad mapping. * * This function returns whether the specified joystick is both present and has * a gamepad mapping. * * If the specified joystick is present but does not have a gamepad mapping * this function will return `GLFW_FALSE` but will not generate an error. Call * @ref glfwJoystickPresent to check if a joystick is present regardless of * whether it has a mapping. * * @param[in] jid The [joystick](@ref joysticks) to query. * @return `GLFW_TRUE` if a joystick is both present and has a gamepad mapping, * or `GLFW_FALSE` otherwise. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_INVALID_ENUM. * * @thread_safety This function must only be called from the main thread. * * @sa @ref gamepad * @sa @ref glfwGetGamepadState * * @since Added in version 3.3. * * @ingroup input */ GLFWAPI int glfwJoystickIsGamepad(int jid); /*! @brief Sets the joystick configuration callback. * * This function sets the joystick configuration callback, or removes the * currently set callback. This is called when a joystick is connected to or * disconnected from the system. * * For joystick connection and disconnection events to be delivered on all * platforms, you need to call one of the [event processing](@ref events) * functions. Joystick disconnection may also be detected and the callback * called by joystick functions. The function will then return whatever it * returns if the joystick is not present. * * @param[in] callback The new callback, or `NULL` to remove the currently set * callback. * @return The previously set callback, or `NULL` if no callback was set or the * library had not been [initialized](@ref intro_init). * * @callback_signature * @code * void function_name(int jid, int event) * @endcode * For more information about the callback parameters, see the * [function pointer type](@ref GLFWjoystickfun). * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function must only be called from the main thread. * * @sa @ref joystick_event * * @since Added in version 3.2. * * @ingroup input */ GLFWAPI GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun callback); /*! @brief Adds the specified SDL_GameControllerDB gamepad mappings. * * This function parses the specified ASCII encoded string and updates the * internal list with any gamepad mappings it finds. This string may * contain either a single gamepad mapping or many mappings separated by * newlines. The parser supports the full format of the `gamecontrollerdb.txt` * source file including empty lines and comments. * * See @ref gamepad_mapping for a description of the format. * * If there is already a gamepad mapping for a given GUID in the internal list, * it will be replaced by the one passed to this function. If the library is * terminated and re-initialized the internal list will revert to the built-in * default. * * @param[in] string The string containing the gamepad mappings. * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_INVALID_VALUE. * * @thread_safety This function must only be called from the main thread. * * @sa @ref gamepad * @sa @ref glfwJoystickIsGamepad * @sa @ref glfwGetGamepadName * * @since Added in version 3.3. * * @ingroup input */ GLFWAPI int glfwUpdateGamepadMappings(const char* string); /*! @brief Returns the human-readable gamepad name for the specified joystick. * * This function returns the human-readable name of the gamepad from the * gamepad mapping assigned to the specified joystick. * * If the specified joystick is not present or does not have a gamepad mapping * this function will return `NULL` but will not generate an error. Call * @ref glfwJoystickPresent to check whether it is present regardless of * whether it has a mapping. * * @param[in] jid The [joystick](@ref joysticks) to query. * @return The UTF-8 encoded name of the gamepad, or `NULL` if the * joystick is not present, does not have a mapping or an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref GLFW_INVALID_ENUM. * * @pointer_lifetime The returned string is allocated and freed by GLFW. You * should not free it yourself. It is valid until the specified joystick is * disconnected, the gamepad mappings are updated or the library is terminated. * * @thread_safety This function must only be called from the main thread. * * @sa @ref gamepad * @sa @ref glfwJoystickIsGamepad * * @since Added in version 3.3. * * @ingroup input */ GLFWAPI const char* glfwGetGamepadName(int jid); /*! @brief Retrieves the state of the specified joystick remapped as a gamepad. * * This function retrieves the state of the specified joystick remapped to * an Xbox-like gamepad. * * If the specified joystick is not present or does not have a gamepad mapping * this function will return `GLFW_FALSE` but will not generate an error. Call * @ref glfwJoystickPresent to check whether it is present regardless of * whether it has a mapping. * * The Guide button may not be available for input as it is often hooked by the * system or the Steam client. * * Not all devices have all the buttons or axes provided by @ref * GLFWgamepadstate. Unavailable buttons and axes will always report * `GLFW_RELEASE` and 0.0 respectively. * * @param[in] jid The [joystick](@ref joysticks) to query. * @param[out] state The gamepad input state of the joystick. * @return `GLFW_TRUE` if successful, or `GLFW_FALSE` if no joystick is * connected, it has no gamepad mapping or an [error](@ref error_handling) * occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_INVALID_ENUM. * * @thread_safety This function must only be called from the main thread. * * @sa @ref gamepad * @sa @ref glfwUpdateGamepadMappings * @sa @ref glfwJoystickIsGamepad * * @since Added in version 3.3. * * @ingroup input */ GLFWAPI int glfwGetGamepadState(int jid, GLFWgamepadstate* state); /*! @brief Sets the clipboard to the specified string. * * This function sets the system clipboard to the specified, UTF-8 encoded * string. * * @param[in] window Deprecated. Any valid window or `NULL`. * @param[in] string A UTF-8 encoded string. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_PLATFORM_ERROR. * * @remark @win32 The clipboard on Windows has a single global lock for reading and * writing. GLFW tries to acquire it a few times, which is almost always enough. If it * cannot acquire the lock then this function emits @ref GLFW_PLATFORM_ERROR and returns. * It is safe to try this multiple times. * * @pointer_lifetime The specified string is copied before this function * returns. * * @thread_safety This function must only be called from the main thread. * * @sa @ref clipboard * @sa @ref glfwGetClipboardString * * @since Added in version 3.0. * * @ingroup input */ GLFWAPI void glfwSetClipboardString(GLFWwindow* window, const char* string); /*! @brief Returns the contents of the clipboard as a string. * * This function returns the contents of the system clipboard, if it contains * or is convertible to a UTF-8 encoded string. If the clipboard is empty or * if its contents cannot be converted, `NULL` is returned and a @ref * GLFW_FORMAT_UNAVAILABLE error is generated. * * @param[in] window Deprecated. Any valid window or `NULL`. * @return The contents of the clipboard as a UTF-8 encoded string, or `NULL` * if an [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_FORMAT_UNAVAILABLE and @ref GLFW_PLATFORM_ERROR. * * @remark @win32 The clipboard on Windows has a single global lock for reading and * writing. GLFW tries to acquire it a few times, which is almost always enough. If it * cannot acquire the lock then this function emits @ref GLFW_PLATFORM_ERROR and returns. * It is safe to try this multiple times. * * @pointer_lifetime The returned string is allocated and freed by GLFW. You * should not free it yourself. It is valid until the next call to @ref * glfwGetClipboardString or @ref glfwSetClipboardString, or until the library * is terminated. * * @thread_safety This function must only be called from the main thread. * * @sa @ref clipboard * @sa @ref glfwSetClipboardString * * @since Added in version 3.0. * * @ingroup input */ GLFWAPI const char* glfwGetClipboardString(GLFWwindow* window); /*! @brief Returns the GLFW time. * * This function returns the current GLFW time, in seconds. Unless the time * has been set using @ref glfwSetTime it measures time elapsed since GLFW was * initialized. * * This function and @ref glfwSetTime are helper functions on top of @ref * glfwGetTimerFrequency and @ref glfwGetTimerValue. * * The resolution of the timer is system dependent, but is usually on the order * of a few micro- or nanoseconds. It uses the highest-resolution monotonic * time source on each operating system. * * @return The current time, in seconds, or zero if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function may be called from any thread. Reading and * writing of the internal base time is not atomic, so it needs to be * externally synchronized with calls to @ref glfwSetTime. * * @sa @ref time * * @since Added in version 1.0. * * @ingroup input */ GLFWAPI double glfwGetTime(void); /*! @brief Sets the GLFW time. * * This function sets the current GLFW time, in seconds. The value must be * a positive finite number less than or equal to 18446744073.0, which is * approximately 584.5 years. * * This function and @ref glfwGetTime are helper functions on top of @ref * glfwGetTimerFrequency and @ref glfwGetTimerValue. * * @param[in] time The new value, in seconds. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_INVALID_VALUE. * * @remark The upper limit of GLFW time is calculated as * floor((2<sup>64</sup> - 1) / 10<sup>9</sup>) and is due to implementations * storing nanoseconds in 64 bits. The limit may be increased in the future. * * @thread_safety This function may be called from any thread. Reading and * writing of the internal base time is not atomic, so it needs to be * externally synchronized with calls to @ref glfwGetTime. * * @sa @ref time * * @since Added in version 2.2. * * @ingroup input */ GLFWAPI void glfwSetTime(double time); /*! @brief Returns the current value of the raw timer. * * This function returns the current value of the raw timer, measured in * 1&nbsp;/&nbsp;frequency seconds. To get the frequency, call @ref * glfwGetTimerFrequency. * * @return The value of the timer, or zero if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function may be called from any thread. * * @sa @ref time * @sa @ref glfwGetTimerFrequency * * @since Added in version 3.2. * * @ingroup input */ GLFWAPI uint64_t glfwGetTimerValue(void); /*! @brief Returns the frequency, in Hz, of the raw timer. * * This function returns the frequency, in Hz, of the raw timer. * * @return The frequency of the timer, in Hz, or zero if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function may be called from any thread. * * @sa @ref time * @sa @ref glfwGetTimerValue * * @since Added in version 3.2. * * @ingroup input */ GLFWAPI uint64_t glfwGetTimerFrequency(void); /*! @brief Makes the context of the specified window current for the calling * thread. * * This function makes the OpenGL or OpenGL ES context of the specified window * current on the calling thread. It can also detach the current context from * the calling thread without making a new one current by passing in `NULL`. * * A context must only be made current on a single thread at a time and each * thread can have only a single current context at a time. Making a context * current detaches any previously current context on the calling thread. * * When moving a context between threads, you must detach it (make it * non-current) on the old thread before making it current on the new one. * * By default, making a context non-current implicitly forces a pipeline flush. * On machines that support `GL_KHR_context_flush_control`, you can control * whether a context performs this flush by setting the * [GLFW_CONTEXT_RELEASE_BEHAVIOR](@ref GLFW_CONTEXT_RELEASE_BEHAVIOR_hint) * hint. * * The specified window must have an OpenGL or OpenGL ES context. Specifying * a window without a context will generate a @ref GLFW_NO_WINDOW_CONTEXT * error. * * @param[in] window The window whose context to make current, or `NULL` to * detach the current context. * * @remarks If the previously current context was created via a different * context creation API than the one passed to this function, GLFW will still * detach the previous one from its API before making the new one current. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_NO_WINDOW_CONTEXT and @ref GLFW_PLATFORM_ERROR. * * @thread_safety This function may be called from any thread. * * @sa @ref context_current * @sa @ref glfwGetCurrentContext * * @since Added in version 3.0. * * @ingroup context */ GLFWAPI void glfwMakeContextCurrent(GLFWwindow* window); /*! @brief Returns the window whose context is current on the calling thread. * * This function returns the window whose OpenGL or OpenGL ES context is * current on the calling thread. * * @return The window whose context is current, or `NULL` if no window's * context is current. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function may be called from any thread. * * @sa @ref context_current * @sa @ref glfwMakeContextCurrent * * @since Added in version 3.0. * * @ingroup context */ GLFWAPI GLFWwindow* glfwGetCurrentContext(void); /*! @brief Swaps the front and back buffers of the specified window. * * This function swaps the front and back buffers of the specified window when * rendering with OpenGL or OpenGL ES. If the swap interval is greater than * zero, the GPU driver waits the specified number of screen updates before * swapping the buffers. * * The specified window must have an OpenGL or OpenGL ES context. Specifying * a window without a context will generate a @ref GLFW_NO_WINDOW_CONTEXT * error. * * This function does not apply to Vulkan. If you are rendering with Vulkan, * see `vkQueuePresentKHR` instead. * * @param[in] window The window whose buffers to swap. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_NO_WINDOW_CONTEXT and @ref GLFW_PLATFORM_ERROR. * * @remark __EGL:__ The context of the specified window must be current on the * calling thread. * * @thread_safety This function may be called from any thread. * * @sa @ref buffer_swap * @sa @ref glfwSwapInterval * * @since Added in version 1.0. * @glfw3 Added window handle parameter. * * @ingroup window */ GLFWAPI void glfwSwapBuffers(GLFWwindow* window); /*! @brief Sets the swap interval for the current context. * * This function sets the swap interval for the current OpenGL or OpenGL ES * context, i.e. the number of screen updates to wait from the time @ref * glfwSwapBuffers was called before swapping the buffers and returning. This * is sometimes called _vertical synchronization_, _vertical retrace * synchronization_ or just _vsync_. * * A context that supports either of the `WGL_EXT_swap_control_tear` and * `GLX_EXT_swap_control_tear` extensions also accepts _negative_ swap * intervals, which allows the driver to swap immediately even if a frame * arrives a little bit late. You can check for these extensions with @ref * glfwExtensionSupported. * * A context must be current on the calling thread. Calling this function * without a current context will cause a @ref GLFW_NO_CURRENT_CONTEXT error. * * This function does not apply to Vulkan. If you are rendering with Vulkan, * see the present mode of your swapchain instead. * * @param[in] interval The minimum number of screen updates to wait for * until the buffers are swapped by @ref glfwSwapBuffers. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_NO_CURRENT_CONTEXT and @ref GLFW_PLATFORM_ERROR. * * @remark This function is not called during context creation, leaving the * swap interval set to whatever is the default for that API. This is done * because some swap interval extensions used by GLFW do not allow the swap * interval to be reset to zero once it has been set to a non-zero value. * * @remark Some GPU drivers do not honor the requested swap interval, either * because of a user setting that overrides the application's request or due to * bugs in the driver. * * @thread_safety This function may be called from any thread. * * @sa @ref buffer_swap * @sa @ref glfwSwapBuffers * * @since Added in version 1.0. * * @ingroup context */ GLFWAPI void glfwSwapInterval(int interval); /*! @brief Returns whether the specified extension is available. * * This function returns whether the specified * [API extension](@ref context_glext) is supported by the current OpenGL or * OpenGL ES context. It searches both for client API extension and context * creation API extensions. * * A context must be current on the calling thread. Calling this function * without a current context will cause a @ref GLFW_NO_CURRENT_CONTEXT error. * * As this functions retrieves and searches one or more extension strings each * call, it is recommended that you cache its results if it is going to be used * frequently. The extension strings will not change during the lifetime of * a context, so there is no danger in doing this. * * This function does not apply to Vulkan. If you are using Vulkan, see @ref * glfwGetRequiredInstanceExtensions, `vkEnumerateInstanceExtensionProperties` * and `vkEnumerateDeviceExtensionProperties` instead. * * @param[in] extension The ASCII encoded name of the extension. * @return `GLFW_TRUE` if the extension is available, or `GLFW_FALSE` * otherwise. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_NO_CURRENT_CONTEXT, @ref GLFW_INVALID_VALUE and @ref * GLFW_PLATFORM_ERROR. * * @thread_safety This function may be called from any thread. * * @sa @ref context_glext * @sa @ref glfwGetProcAddress * * @since Added in version 1.0. * * @ingroup context */ GLFWAPI int glfwExtensionSupported(const char* extension); /*! @brief Returns the address of the specified function for the current * context. * * This function returns the address of the specified OpenGL or OpenGL ES * [core or extension function](@ref context_glext), if it is supported * by the current context. * * A context must be current on the calling thread. Calling this function * without a current context will cause a @ref GLFW_NO_CURRENT_CONTEXT error. * * This function does not apply to Vulkan. If you are rendering with Vulkan, * see @ref glfwGetInstanceProcAddress, `vkGetInstanceProcAddr` and * `vkGetDeviceProcAddr` instead. * * @param[in] procname The ASCII encoded name of the function. * @return The address of the function, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_NO_CURRENT_CONTEXT and @ref GLFW_PLATFORM_ERROR. * * @remark The address of a given function is not guaranteed to be the same * between contexts. * * @remark This function may return a non-`NULL` address despite the * associated version or extension not being available. Always check the * context version or extension string first. * * @pointer_lifetime The returned function pointer is valid until the context * is destroyed or the library is terminated. * * @thread_safety This function may be called from any thread. * * @sa @ref context_glext * @sa @ref glfwExtensionSupported * * @since Added in version 1.0. * * @ingroup context */ GLFWAPI GLFWglproc glfwGetProcAddress(const char* procname); /*! @brief Returns whether the Vulkan loader and an ICD have been found. * * This function returns whether the Vulkan loader and any minimally functional * ICD have been found. * * The availability of a Vulkan loader and even an ICD does not by itself guarantee that * surface creation or even instance creation is possible. Call @ref * glfwGetRequiredInstanceExtensions to check whether the extensions necessary for Vulkan * surface creation are available and @ref glfwGetPhysicalDevicePresentationSupport to * check whether a queue family of a physical device supports image presentation. * * @return `GLFW_TRUE` if Vulkan is minimally available, or `GLFW_FALSE` * otherwise. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. * * @thread_safety This function may be called from any thread. * * @sa @ref vulkan_support * * @since Added in version 3.2. * * @ingroup vulkan */ GLFWAPI int glfwVulkanSupported(void); /*! @brief Returns the Vulkan instance extensions required by GLFW. * * This function returns an array of names of Vulkan instance extensions required * by GLFW for creating Vulkan surfaces for GLFW windows. If successful, the * list will always contain `VK_KHR_surface`, so if you don't require any * additional extensions you can pass this list directly to the * `VkInstanceCreateInfo` struct. * * If Vulkan is not available on the machine, this function returns `NULL` and * generates a @ref GLFW_API_UNAVAILABLE error. Call @ref glfwVulkanSupported * to check whether Vulkan is at least minimally available. * * If Vulkan is available but no set of extensions allowing window surface * creation was found, this function returns `NULL`. You may still use Vulkan * for off-screen rendering and compute work. * * @param[out] count Where to store the number of extensions in the returned * array. This is set to zero if an error occurred. * @return An array of ASCII encoded extension names, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_API_UNAVAILABLE. * * @remark Additional extensions may be required by future versions of GLFW. * You should check if any extensions you wish to enable are already in the * returned array, as it is an error to specify an extension more than once in * the `VkInstanceCreateInfo` struct. * * @pointer_lifetime The returned array is allocated and freed by GLFW. You * should not free it yourself. It is guaranteed to be valid only until the * library is terminated. * * @thread_safety This function may be called from any thread. * * @sa @ref vulkan_ext * @sa @ref glfwCreateWindowSurface * * @since Added in version 3.2. * * @ingroup vulkan */ GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count); #if defined(VK_VERSION_1_0) /*! @brief Returns the address of the specified Vulkan instance function. * * This function returns the address of the specified Vulkan core or extension * function for the specified instance. If instance is set to `NULL` it can * return any function exported from the Vulkan loader, including at least the * following functions: * * - `vkEnumerateInstanceExtensionProperties` * - `vkEnumerateInstanceLayerProperties` * - `vkCreateInstance` * - `vkGetInstanceProcAddr` * * If Vulkan is not available on the machine, this function returns `NULL` and * generates a @ref GLFW_API_UNAVAILABLE error. Call @ref glfwVulkanSupported * to check whether Vulkan is at least minimally available. * * This function is equivalent to calling `vkGetInstanceProcAddr` with * a platform-specific query of the Vulkan loader as a fallback. * * @param[in] instance The Vulkan instance to query, or `NULL` to retrieve * functions related to instance creation. * @param[in] procname The ASCII encoded name of the function. * @return The address of the function, or `NULL` if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * GLFW_API_UNAVAILABLE. * * @pointer_lifetime The returned function pointer is valid until the library * is terminated. * * @thread_safety This function may be called from any thread. * * @sa @ref vulkan_proc * * @since Added in version 3.2. * * @ingroup vulkan */ GLFWAPI GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, const char* procname); /*! @brief Returns whether the specified queue family can present images. * * This function returns whether the specified queue family of the specified * physical device supports presentation to the platform GLFW was built for. * * If Vulkan or the required window surface creation instance extensions are * not available on the machine, or if the specified instance was not created * with the required extensions, this function returns `GLFW_FALSE` and * generates a @ref GLFW_API_UNAVAILABLE error. Call @ref glfwVulkanSupported * to check whether Vulkan is at least minimally available and @ref * glfwGetRequiredInstanceExtensions to check what instance extensions are * required. * * @param[in] instance The instance that the physical device belongs to. * @param[in] device The physical device that the queue family belongs to. * @param[in] queuefamily The index of the queue family to query. * @return `GLFW_TRUE` if the queue family supports presentation, or * `GLFW_FALSE` otherwise. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_API_UNAVAILABLE and @ref GLFW_PLATFORM_ERROR. * * @remark @macos This function currently always returns `GLFW_TRUE`, as the * `VK_MVK_macos_surface` and `VK_EXT_metal_surface` extensions do not provide * a `vkGetPhysicalDevice*PresentationSupport` type function. * * @thread_safety This function may be called from any thread. For * synchronization details of Vulkan objects, see the Vulkan specification. * * @sa @ref vulkan_present * * @since Added in version 3.2. * * @ingroup vulkan */ GLFWAPI int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily); /*! @brief Creates a Vulkan surface for the specified window. * * This function creates a Vulkan surface for the specified window. * * If the Vulkan loader or at least one minimally functional ICD were not found, * this function returns `VK_ERROR_INITIALIZATION_FAILED` and generates a @ref * GLFW_API_UNAVAILABLE error. Call @ref glfwVulkanSupported to check whether * Vulkan is at least minimally available. * * If the required window surface creation instance extensions are not * available or if the specified instance was not created with these extensions * enabled, this function returns `VK_ERROR_EXTENSION_NOT_PRESENT` and * generates a @ref GLFW_API_UNAVAILABLE error. Call @ref * glfwGetRequiredInstanceExtensions to check what instance extensions are * required. * * The window surface cannot be shared with another API so the window must * have been created with the [client api hint](@ref GLFW_CLIENT_API_attrib) * set to `GLFW_NO_API` otherwise it generates a @ref GLFW_INVALID_VALUE error * and returns `VK_ERROR_NATIVE_WINDOW_IN_USE_KHR`. * * The window surface must be destroyed before the specified Vulkan instance. * It is the responsibility of the caller to destroy the window surface. GLFW * does not destroy it for you. Call `vkDestroySurfaceKHR` to destroy the * surface. * * @param[in] instance The Vulkan instance to create the surface in. * @param[in] window The window to create the surface for. * @param[in] allocator The allocator to use, or `NULL` to use the default * allocator. * @param[out] surface Where to store the handle of the surface. This is set * to `VK_NULL_HANDLE` if an error occurred. * @return `VK_SUCCESS` if successful, or a Vulkan error code if an * [error](@ref error_handling) occurred. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED, @ref * GLFW_API_UNAVAILABLE, @ref GLFW_PLATFORM_ERROR and @ref GLFW_INVALID_VALUE * * @remark If an error occurs before the creation call is made, GLFW returns * the Vulkan error code most appropriate for the error. Appropriate use of * @ref glfwVulkanSupported and @ref glfwGetRequiredInstanceExtensions should * eliminate almost all occurrences of these errors. * * @remark @macos GLFW prefers the `VK_EXT_metal_surface` extension, with the * `VK_MVK_macos_surface` extension as a fallback. The name of the selected * extension, if any, is included in the array returned by @ref * glfwGetRequiredInstanceExtensions. * * @remark @macos This function creates and sets a `CAMetalLayer` instance for * the window content view, which is required for MoltenVK to function. * * @remark @x11 By default GLFW prefers the `VK_KHR_xcb_surface` extension, * with the `VK_KHR_xlib_surface` extension as a fallback. You can make * `VK_KHR_xlib_surface` the preferred extension by setting the * [GLFW_X11_XCB_VULKAN_SURFACE](@ref GLFW_X11_XCB_VULKAN_SURFACE_hint) init * hint. The name of the selected extension, if any, is included in the array * returned by @ref glfwGetRequiredInstanceExtensions. * * @thread_safety This function may be called from any thread. For * synchronization details of Vulkan objects, see the Vulkan specification. * * @sa @ref vulkan_surface * @sa @ref glfwGetRequiredInstanceExtensions * * @since Added in version 3.2. * * @ingroup vulkan */ GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); #endif /*VK_VERSION_1_0*/ /************************************************************************* * Global definition cleanup *************************************************************************/ /* ------------------- BEGIN SYSTEM/COMPILER SPECIFIC -------------------- */ #ifdef GLFW_WINGDIAPI_DEFINED #undef WINGDIAPI #undef GLFW_WINGDIAPI_DEFINED #endif #ifdef GLFW_CALLBACK_DEFINED #undef CALLBACK #undef GLFW_CALLBACK_DEFINED #endif /* Some OpenGL related headers need GLAPIENTRY, but it is unconditionally * defined by some gl.h variants (OpenBSD) so define it after if needed. */ #ifndef GLAPIENTRY #define GLAPIENTRY APIENTRY #define GLFW_GLAPIENTRY_DEFINED #endif /* -------------------- END SYSTEM/COMPILER SPECIFIC --------------------- */ #ifdef __cplusplus } #endif #endif /* _glfw3_h_ */
0
repos
repos/raylib-zig-examples/build_example.sh
#!/bin/sh if [ $# -eq 0 ]; then echo echo "Syntax: build_example <example number>" >&2 echo "Note: example number must include leading 0, e.g. 03" >&2 echo " If the number matches more than one example folder (e.g. 54 matches 54a and 54b)," >&2 echo " all matching examples will be built." >&2 echo " If example number is \"all\" (without quotation marks), all examples will be built." >&2 echo exit 1 fi # These variables are used if examples are built using this bat file # If you invoke build.bat files in examples' folders manually, values set in # those files are used instead. RAYLIB_PATH='/home/my_user/raylib' RAYLIB_INCLUDE_PATH="${RAYLIB_PATH}/zig-out/include" RAYLIB_EXTERNAL_INCLUDE_PATH="${RAYLIB_PATH}/src/external" RAYLIB_LIB_PATH="${RAYLIB_PATH}/zig-out/lib" # If raylib is installed in a standard location (e.g. /usr/include and /usr/lib/), set these to # empty strings ('') #RAYLIB_PATH='' #RAYLIB_INCLUDE_PATH='' #RAYLIB_EXTERNAL_INCLUDE_PATH='' #RAYLIB_LIB_PATH='' # One of: # -O Debug # -O ReleaseFast # -O ReleaseSafe # -O ReleaseSmall RAYLIB_ZIG_BUILD_MODE='-O Debug' if [ "$1" = 'all' ]; then for dir in ./zig-raylib-*/ # list directories do dir=${dir%*/} # remove the trailing "/" echo echo "Building ${dir##*/} .." cd ${dir} # Pass something as the first parameter, as a flag, to signal to build.bat to use variables set here source ./build.sh dontuselocals cd .. done else for dir in ./zig-raylib-$1*/ # list directories do dir=${dir%*/} # remove the trailing "/" echo echo "Building ${dir##*/} .." cd ${dir} # Pass something as the first parameter, as a flag, to signal to build.bat to use variables set here source ./build.sh dontuselocals cd .. done fi
0
repos
repos/raylib-zig-examples/clean_all.sh
#!/bin/sh for dir in ./zig-raylib-*/ # list directories do dir=${dir%*/} # remove the trailing "/" echo echo "Cleaning ${dir##*/} .." cd ${dir} source ./clean.sh cd .. done echo 'Done'
0
repos
repos/raylib-zig-examples/build_example.bat
@echo off if "%~1"=="" ( echo. echo Syntax: build_example ^<example number^> echo Note: example number must include leading 0, e.g. 03 echo If the number matches more than one example folder (e.g. 54 matches 54a and 54b^), echo all matching examples will be built. echo If example number is "all" (without quotation marks^), all examples will be built. exit /b ) REM These variables are used if examples are built using this bat file REM If you invoke build.bat files in examples' folders manually, values set in REM those files are used instead. SET RAYLIB_PATH=D:\libs\raylib-4.5.0 SET RAYLIB_INCLUDE_PATH=%RAYLIB_PATH%\zig-out\include SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_PATH%\src\external SET RAYLIB_LIB_PATH=%RAYLIB_PATH%\zig-out\lib REM One of: REM -O Debug REM -O ReleaseFast REM -O ReleaseSafe REM -O ReleaseSmall SET RAYLIB_ZIG_BUILD_MODE=-O Debug echo. REM If parameter is 'all', build all examples if %1==all ( echo -- Building all examples -- echo. for /F %%f in ('dir /B /A:D "zig-raylib-*"') do ( echo Building %%f .. cd %%f REM Pass something as the first parameter, as a flag, to signal to build.bat to use variables set here call build.bat dontuselocals cd .. echo. ) ) else ( REM We assume there's just one zig-raylib-%1* folder, REM but if there are more, build them all. REM For example, 54a and 54b are built if the user passed '54'. for /F %%f in ('dir /B /A:D "zig-raylib-%1*"') do ( echo Building %%f .. cd %%f REM Pass something as the first parameter, as a flag, to signal to build.bat to use variables set here call build.bat dontuselocals cd .. echo. ) )
0
repos
repos/raylib-zig-examples/README.md
#### Raylib Zig Examples These are some of [raylib](https://www.raylib.com/) ([raylib on github](https://github.com/raysan5/raylib)) [examples](https://www.raylib.com/examples.html) ported to [Zig](https://ziglang.org/). [See the screenshot gallery](sshots/sshots.md)! Please note these are **raylib 4.5** examples, they have been updated to compile with either raylib **4.5** or raylib **5.0**, but the content of example programs has not been updated to match raylib 5.0 examples. The examples don't use any bindings or some other intermediate layer between Zig code and raylib. Instead, Zig's built-in translate-C feature takes care of everything (well, almost, see below). For whatever reason, example [27](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-27-core-custom-frame-control) (custom frame control) does not work properly on Windows, and runs with certain jerkiness on Linux. My knowledge of raylib is not enough to figure out why. I have done some minor modifications to the code, like changing *camelCase* variable names to *snake_case*, to fit Zig naming conventions. Some of the examples are presented in multiple versions ([14a](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-14a-core-3d-picking-(original)) and [14b](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-14b-core-3d-picking-(2-cubes)); [54a](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-54a-textures-texture-from-raw-data-(comptime-init)) and [54b](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-54b-textures-texture-from-raw-data-(runtime-init)); [87a](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-87a-models-mesh-generation-(MemAlloc-calloc)) and [87b](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-87b-models-mesh-generation-(Zig-allocator))), see the comments in the Zig code. To make things easier, some of the examples come with resource files, necessary to run them. Their authors are credited below: | resource | examples | author | licence | notes | | ------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ----------------------------------------------------------- | ------------------------------------------------------------ | | raylib_logo.png | [46](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-46-textures-logo-raylib), [50](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-50-textures-image-loading), [53](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-53-textures-to-image) | [@raysan5](https://github.com/raysan5) (?) | ? | | | fudesumi.raw | [54a](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-54a-textures-texture-from-raw-data-(comptime-init)), [54b](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-54b-textures-texture-from-raw-data-(runtime-init)) | [Eiden Marsal](https://www.artstation.com/marshall_z) | [CC-BY-NC](https://creativecommons.org/licenses/by-nc/4.0/) | | | road.png | [68](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-68-textures-textured-curve) | ? | ? | | | fonts/alagard.png | [69](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-69-text-raylib-fonts) | Hewett Tsoi | [Freeware](https://www.dafont.com/es/alagard.font) | Atlas created by [@raysan5](https://github.com/raysan5) | | fonts/alpha_beta.png | [69](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-69-text-raylib-fonts) | [Brian Kent (AEnigma)](https://www.dafont.com/es/aenigma.d188) | [Freeware](https://www.dafont.com/es/alpha-beta.font) | Atlas created by [@raysan5](https://github.com/raysan5) | | fonts/jupiter_crash.png | [69](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-69-text-raylib-fonts) | [Brian Kent (AEnigma)](https://www.dafont.com/es/aenigma.d188) | [Freeware](https://www.dafont.com/es/jupiter-crash.font) | Atlas created by [@raysan5](https://github.com/raysan5) | | fonts/mecha.png | [69](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-69-text-raylib-fonts) | Captain Falcon | [Freeware](https://www.dafont.com/es/mecha-cf.font) | Atlas created by [@raysan5](https://github.com/raysan5) | | fonts/pixantiqua.ttf | [69](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-69-text-raylib-fonts) | Gerhard Großmann | [Freeware](https://www.dafont.com/es/pixantiqua.font) | Atlas created by [@raysan5](https://github.com/raysan5) | | fonts/pixelplay.png | [69](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-69-text-raylib-fonts) | Aleksander Shevchuk | [Freeware](https://www.dafont.com/es/pixelplay.font) | Atlas created by [@raysan5](https://github.com/raysan5) | | fonts/romulus.png | [69](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-69-text-raylib-fonts) | Hewett Tsoi | [Freeware](https://www.dafont.com/es/romulus.font) | Atlas created by [@raysan5](https://github.com/raysan5) | | fonts/setback.png | [69](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-69-text-raylib-fonts) | [Brian Kent (AEnigma)](https://www.dafont.com/es/aenigma.d188) | [Freeware](https://www.dafont.com/es/setback.font) | Atlas created by [@raysan5](https://github.com/raysan5) | | custom_alagard.png | [70](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-70-text-font-spritefont) | [Brian Kent (AEnigma)](https://www.dafont.com/es/aenigma.d188) | [Freeware](https://www.dafont.com/es/jupiter-crash.font) | Atlas created by [@raysan5](https://github.com/raysan5) | | custom_jupiter_crash.png | [70](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-70-text-font-spritefont) | [Brian Kent (AEnigma)](https://www.dafont.com/es/aenigma.d188) | [Freeware](https://www.dafont.com/es/jupiter-crash.font) | Atlas created by [@raysan5](https://github.com/raysan5) | | custom_mecha.png | [70](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-70-text-font-spritefont) | [Brian Kent (AEnigma)](https://www.dafont.com/es/aenigma.d188) | [Freeware](https://www.dafont.com/es/jupiter-crash.font) | Atlas created by [@raysan5](https://github.com/raysan5) | | KAISG.ttf | [71](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-71-text-font-filters) | [Dieter Steffmann](http://www.steffmann.de/wordpress/) | [Freeware](https://www.1001fonts.com/users/steffmann/) | [Kaiserzeit Gotisch](https://www.dafont.com/es/kaiserzeit-gotisch.font) font | | pixantiqua.fnt, pixantiqua.png | [72](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-72-text-font-loading) | Gerhard Großmann | [Freeware](https://www.dafont.com/es/pixantiqua.font) | Atlas made with [BMFont](https://www.angelcode.com/products/bmfont/) by [@raysan5](https://github.com/raysan5) | | pixantiqua.ttf | [72](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-72-text-font-loading) | Gerhard Großmann | [Freeware](https://www.dafont.com/es/pixantiqua.font) | | | cubicmap.png | [84](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-84-models-cubicmap), [85](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-85-models-first-person-maze) | [@raysan5](https://github.com/raysan5) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | | | cubicmap_atlas.png | [84](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-84-models-cubicmap), [85](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-85-models-first-person-maze) | [@emegeme](https://github.com/emegeme) | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | | #### Building the examples **Note**: some examples require additional header files. I recommend downloading them to the corresponding example's folder, as described in the comments in Zig code. Examples [39](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-39-shapes-easings-ball_anim), [40](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-40-shapes-easings-box_anim), [41](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-41-shapes-easings-rectangle_array) need `reasings.h` from https://github.com/raysan5/raylib/blob/master/examples/others/reasings.h; examples [42](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-42-shapes-draw-ring), [43](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-43-shapes-draw-circle_sector), [44](https://github.com/Durobot/raylib-zig-examples/tree/main/zig-raylib-44-shapes-draw-rectangle_rounded) need `raygui.h` from https://github.com/raysan5/raygui/blob/master/src/raygui.h. In other words, the following additional header files are necessary for their respective examples to build: ``` zig-raylib-39-shapes-easings-ball_anim/reasings.h zig-raylib-40-shapes-easings-box_anim/reasings.h zig-raylib-41-shapes-easings-rectangle_array/reasings.h zig-raylib-42-shapes-draw-ring/raygui.h zig-raylib-43-shapes-draw-circle_sector/raygui.h zig-raylib-44-shapes-draw-rectangle_rounded/raygui.h ``` **On Linux**: 1. Install Zig - download from https://ziglang.org/download/. Versions that work are **0.12.0**, **0.12.1**, **0.13.0** (current stable release), and **0.14.0** (nightly development build). **0.11.0** works too so far, but this may change in the future. Latest version of Zig **0.14.0** I have tested the project with was **0.14.0-dev.367+a57479afc**. Later versions may or may not work, you're welcome to try them and raise an issue on github if they don't. Unpack your version of Zig and add its folder to environment variable PATH. In many Linux distributions this is done by adding the following line to the end of `.bashrc` file in your home folder (replace /path/to/zig with the `actual` path, of course): `export PATH="$PATH:/path/to/zig"` Alternatively, you can install Zig from your distribution's repositories, if they contain Zig 0.11. 2. Install raylib. Versions 4.5 and 5.0 do work. Earlier or later version may work too. Use one of the following methods: 1. Install it from your distribution's repositories. For example on Arch you can do it with `pacman -S raylib` command. You then should be able to build examples by running `zig build-exe main.zig -lc -lraylib` in each example's folder. To build using `build_example.sh`, (optionally) edit this file, setting `RAYLIB_PATH`, `RAYLIB_INCLUDE_PATH`, `RAYLIB_EXTERNAL_INCLUDE_PATH` and `RAYLIB_LIB_PATH` variables to '' (empty string). To build using `build.sh` found in each folder, (optionally) edit build.sh, setting `tmp_raylib_path`, `tmp_raylib_include_path`, `tmp_raylib_external_include_path` and `tmp_raylib_lib_path` variables to '' (empty string) at lines 12 - 15. Alternatively, you can 2. Build raylib from source code. Download raylib [from github](https://github.com/raysan5/raylib/tags). Click "tar.gz" under the release you want to download, or click "Downloads", then scroll down and click "Source code (tar.gz)". Unpack the downloaded archive. Now, in order to make raylib and/or raylib-zig-examples compile without errors, do one of the following, depending on your version of raylib: 1. **If** you're using raylib **5.0**, open `src\build.zig`, find lines containing `lib.installHeader` (they should be in `pub fn build`), and add the following line after them: ```zig lib.installHeader("src/rcamera.h", "rcamera.h"); ``` Otherwise example 13 won't compile. 2. **If** you're using raylib **4.5**, do one of the following: a. **If** `build.zig` in raylib root folder **contains** the following lines: ```zig const lib = raylib.addRaylib(b, target, optimize); lib.installHeader("src/raylib.h", "raylib.h"); lib.install(); ``` then edit this file - remove or comment out this line: `lib.install();` Add these lines below it, before the closing `}`: ```zig lib.installHeader("src/rlgl.h", "rlgl.h"); lib.installHeader("src/raymath.h", "raymath.h"); lib.installHeader("src/rcamera.h", "rcamera.h"); b.installArtifact(lib); ``` b. **If**, on the other hand, `build.zig` in raylib's root folder **does not** contain `lib.install();` (see [this commit](https://github.com/raysan5/raylib/commit/6b92d71ea1c4e3072b26f25e7b8bd1d1aa8e781f)), then in `src/build.zig`, in function `pub fn build(b: *std.Build) void`, after `lib.installHeader("src/raylib.h", "raylib.h");`, add these lines: ```zig lib.installHeader("src/rlgl.h", "rlgl.h"); lib.installHeader("src/raymath.h", "raymath.h"); lib.installHeader("src/rcamera.h", "rcamera.h"); ``` In raylib root folder, run `zig build -Doptimize=ReleaseSmall` or `zig build -Doptimize=ReleaseFast`. You could also use `-Doptimize=ReleaseSafe`, `-Doptimize=Debug` or simply run `zig build`. This should create `zig-out` folder, with two folders inside: `include` and `lib`, these contain raylib header files and static library, respectively. In `raylib-zig-examples`, in `build_example.sh`set `RAYLIB_PATH` variable to the correct raylib path and make sure the values of `RAYLIB_INCLUDE_PATH`, `RAYLIB_EXTERNAL_INCLUDE_PATH` and `RAYLIB_LIB_PATH` make sense. 3. Build the examples. You can use `build_example.sh` to either build individual examples by providing the example number, e.g. `./build_example.sh 03`, or build them all: `./build_example.sh all`. You can also run `build.sh` contained in each example's folder. raylib paths and Zig build mode set within each build.sh are used in this case. `clean_all.sh` and `clean.sh` in examples' folders can be used to delete binaries generated by the compiler. **On Windows**: 1. Install Zig - download from https://ziglang.org/download/. Versions that work are **0.12.0**, **0.12.1**, **0.13.0** (current stable release), and **0.14.0** (nightly development build). **0.11.0** works too so far, but this may change in the future. Latest version of Zig **0.14.0** I have tested the project with was **0.14.0-dev.367+a57479afc**. Later versions may or may not work, you're welcome to try them and raise an issue on github if they don't. Unpack your version of Zig and add its folder to environment variable PATH. 2. Install raylib. These examples were built using raylib 4.5.0, but an earlier or later version may work too. Build raylib from source code. Download raylib [from github](https://github.com/raysan5/raylib/tags). Click "zip" under the release you want to download, or click "Downloads", then scroll down and click "Source code (zip)". Unpack the downloaded archive. Now, in order to make raylib and/or raylib-zig-examples compile without errors, do one of the following, depending on your version of raylib: 1. **If** you're using raylib **5.0**, open `src\build.zig`, find lines containing `lib.installHeader` (they should be in `pub fn build`), and add the following line after them: ```zig lib.installHeader("src/rcamera.h", "rcamera.h"); ``` Otherwise example 13 won't compile. 2. **If** you're using raylib **4.5**, do one of the following: a. **If** `build.zig` in raylib root folder **contains** the following lines: ```zig const lib = raylib.addRaylib(b, target, optimize); lib.installHeader("src/raylib.h", "raylib.h"); lib.install(); ``` then edit this file - remove or comment out this line: `lib.install();` Add these lines below it, before the closing `}`: ```zig lib.installHeader("src/rlgl.h", "rlgl.h"); lib.installHeader("src/raymath.h", "raymath.h"); lib.installHeader("src/rcamera.h", "rcamera.h"); b.installArtifact(lib); ``` b. **If**, on the other hand, `build.zig` in raylib's root folder **does not** contain `lib.install();` (see [this commit](https://github.com/raysan5/raylib/commit/6b92d71ea1c4e3072b26f25e7b8bd1d1aa8e781f)), then in `src/build.zig`, in function `pub fn build(b: *std.Build) void`, after `lib.installHeader("src/raylib.h", "raylib.h");`, add these lines: ```zig lib.installHeader("src/rlgl.h", "rlgl.h"); lib.installHeader("src/raymath.h", "raymath.h"); lib.installHeader("src/rcamera.h", "rcamera.h"); ``` In raylib root folder, run `zig build -Doptimize=ReleaseSmall` or `zig build -Doptimize=ReleaseFast`. **Warning**: leaving out `-Doptimize` parameter, using `-Doptimize=Debug` or `-Doptimize=ReleaseSafe` currently causes compilation of raylib-zig-examples to fail in ReleaseSmall and ReleaseFast modes down the road. You will see errors similar to these: ``` error: lld-link: undefined symbol: __stack_chk_fail error: lld-link: undefined symbol: __stack_chk_guard ``` Running zig build... should create `zig-out` folder, with two folders inside: `include` and `lib`, these contain raylib header files and static library, respectively. In `raylib-zig-examples`, in `build_example.bat`set `RAYLIB_PATH` variable to the correct raylib path and make sure the values of `RAYLIB_INCLUDE_PATH`, `RAYLIB_EXTERNAL_INCLUDE_PATH` and `RAYLIB_LIB_PATH` make sense. 3. Build the examples. You can use `build_example.bat` to either build individual examples by providing the example number, e.g. `build_example.bat 03`, or build them all: `build_example.bat all`. You can also run `build.bat` contained in each example's folder. raylib paths and Zig build mode set within each build.bat are used in this case. `clean_all.bat` and `clean.bat` in examples' folders can be used to delete binaries generated by the compiler.
0
repos
repos/raylib-zig-examples/clean_all.bat
@echo off for /F %%f in ('dir /B /A:D "zig-raylib-*"') do ( echo Cleaning %%f .. cd %%f call clean.bat cd .. echo. ) echo Done @echo on
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-32-shapes-colors-palette/clean.sh
rm ./main rm ./main.o
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-32-shapes-colors-palette/main.zig
// build with `zig build-exe main.zig -lc -lraylib` // This is a Zig version of a raylib example from // https://github.com/raysan5/raylib/ // It is distributed under the same license as the original - unmodified zlib/libpng license // Header from the original source code follows below: ///******************************************************************************************* //* //* raylib [shapes] example - Colors palette //* //* Example originally created with raylib 1.0, last time updated with raylib 2.5 //* //* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, //* BSD-like license that allows static linking with closed source software //* //* Copyright (c) 2014-2023 Ramon Santamaria (@raysan5) //* //********************************************************************************************/ const c = @cImport( { @cInclude("raylib.h"); }); pub fn main() void { const screen_width = 800; const screen_height = 450; const max_colors_count = 21; // Number of colors available c.InitWindow(screen_width, screen_height, "raylib [shapes] example - colors palette"); defer c.CloseWindow(); // Close window and OpenGL context const clrs = [max_colors_count]c.Color { c.DARKGRAY, c.MAROON, c.ORANGE, c.DARKGREEN, c.DARKBLUE, c.DARKPURPLE, c.DARKBROWN, c.GRAY, c.RED, c.GOLD, c.LIME, c.BLUE, c.VIOLET, c.BROWN, c.LIGHTGRAY, c.PINK, c.YELLOW, c.GREEN, c.SKYBLUE, c.PURPLE, c.BEIGE }; const clr_names = [max_colors_count][*:0]const u8 { "DARKGRAY", "MAROON", "ORANGE", "DARKGREEN", "DARKBLUE", "DARKPURPLE", "DARKBROWN", "GRAY", "RED", "GOLD", "LIME", "BLUE", "VIOLET", "BROWN", "LIGHTGRAY", "PINK", "YELLOW", "GREEN", "SKYBLUE", "PURPLE", "BEIGE" }; // Fills colorsRecs data (for every rectangle) const clr_rects = comptime init_rects: { var rects: [max_colors_count]c.Rectangle = undefined; for (0..max_colors_count) |i| { rects[i].x = 20.0 + 100.0 * @as(comptime_float, @floatFromInt(i % 7)) + 10.0 * @as(comptime_float, @floatFromInt(i % 7)); rects[i].y = 80.0 + 100.0 * @as(comptime_float, @floatFromInt(i / 7)) + 10.0 * @as(comptime_float, @floatFromInt(i / 7)); rects[i].width = 100.0; rects[i].height = 100.0; } break :init_rects rects; }; var clr_states = [_]c_int{ 0 } ** max_colors_count; // Color state: 0-DEFAULT, 1-MOUSE_HOVER c.SetTargetFPS(60); // Set our game to run at 60 frames-per-second while (!c.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- const mouse_point = c.GetMousePosition(); for (0..max_colors_count) |i| { if (c.CheckCollisionPointRec(mouse_point, clr_rects[i])) { clr_states[i] = 1; } else clr_states[i] = 0; } //---------------------------------------------------------------------------------- // Draw //--------------------------------------------------------------------------------- c.BeginDrawing(); defer c.EndDrawing(); c.ClearBackground(c.RAYWHITE); c.DrawText("raylib colors palette", 28, 42, 20, c.BLACK); c.DrawText("press SPACE to see all colors", c.GetScreenWidth() - 180, c.GetScreenHeight() - 40, 10, c.GRAY); for (0..max_colors_count) |i| // Draw all rectangles { c.DrawRectangleRec(clr_rects[i], c.Fade(clrs[i], if (clr_states[i] != 0) 0.6 else 1.0)); if (c.IsKeyDown(c.KEY_SPACE) or clr_states[i] != 0) { c.DrawRectangle(@intFromFloat(clr_rects[i].x), @as(c_int, @intFromFloat(clr_rects[i].y + clr_rects[i].height)) - 26, @intFromFloat(clr_rects[i].width), 20, c.BLACK); c.DrawRectangleLinesEx(clr_rects[i], 6, c.Fade(c.BLACK, 0.3)); c.DrawText(clr_names[i], @as(c_int, @intFromFloat(clr_rects[i].x + clr_rects[i].width)) - c.MeasureText(clr_names[i], 10) - 12, @as(c_int, @intFromFloat(clr_rects[i].y + clr_rects[i].height)) - 20, 10, clrs[i]); } } //--------------------------------------------------------------------------------- } } //inline fn initRects(comptime siz: usize) [siz]c.Rectangle //{ // var rects: [siz]c.Rectangle = undefined; // inline for (0..siz) |i| // { // rects[i].x = 20.0 + 100.0 * @floatFromInt(comptime_float, i % 7) + 10.0 * @floatFromInt(comptime_float, i % 7); // rects[i].y = 80.0 + 100.0 * (@floatFromInt(comptime_float, i) / 7.0) + 10.0 * (@floatFromInt(comptime_float, i) / 7.0); // rects[i].width = 100.0; // rects[i].height = 100.0; // } // return rects; //}
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-32-shapes-colors-palette/build.sh
#!/bin/sh tmp_raylib_include_path='' tmp_raylib_external_include_path='' tmp_raylib_lib_path='' tmp_raylib_zig_build_mode='' # No command line arguments => use local variables if [ $# -eq 0 ]; then echo echo 'Using locally defined build variables and paths' # Set the paths here if you invoke this build.sh manually tmp_raylib_path='~/ray' tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include" tmp_raylib_external_include_path="${tmp_raylib_path}/src/external" tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib" # One of: # -O Debug # -O ReleaseFast # -O ReleaseSafe # -O ReleaseSmall tmp_raylib_zig_build_mode='-O ReleaseSmall' else # Using variables set in ../build_example.sh tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH tmp_raylib_lib_path=$RAYLIB_LIB_PATH tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE fi tmp_raylib_include_arg='' if [ -n "$tmp_raylib_include_path" ]; then # Not empty tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}" fi if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}" fi #echo 'tmp_raylib_include_arg = ' #echo "$tmp_raylib_include_arg" tmp_raylib_lib_arg='' if [ -n "$tmp_raylib_lib_path" ]; then # Not empty tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib" else tmp_raylib_lib_arg='-lc -lraylib' fi #echo 'tmp_raylib_lib_arg = ' #echo "$tmp_raylib_lib_arg" echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}" zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-32-shapes-colors-palette/build.bat
@echo off REM First parameter not set = build.bat launched manually if "%~1"=="" ( echo. echo Using locally defined build variables and paths setlocal enableDelayedExpansion REM These values are used if you invoke this build.bat file manualy. REM If you use build_example.bat in the root folder, values set in that file are used. SET RAYLIB_PATH=D:\libs\raylib-4.5.0 SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib REM One of: REM -O Debug REM -O ReleaseFast REM -O ReleaseSafe REM -O ReleaseSmall SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall ) REM echo RAYLIB_PATH: %RAYLIB_PATH% REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH% REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH% REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH% REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE% @echo on zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc @echo off REM End local variables scope if not called from the main script if "%~1"=="" ( endlocal & ( SET RAYLIB_PATH=%RAYLIB_PATH% SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH% SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH% SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH% SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE% ) )
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-32-shapes-colors-palette/clean.bat
del main.exe del main.exe.obj del main.pdb
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-41-shapes-easings-rectangle_array/clean.sh
rm ./main rm ./main.o
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-41-shapes-easings-rectangle_array/main.zig
// This is a Zig version of a raylib example from // https://github.com/raysan5/raylib/ // It is distributed under the same license as the original - unmodified zlib/libpng license // Header from the original source code follows below: ///******************************************************************************************* //* //* raylib [shapes] example - easings rectangle array //* //* NOTE: This example requires 'easings.h' library, provided on raylib/src. Just copy //* the library to same directory as example or make sure it's available on include path. //* //* Example originally created with raylib 2.0, last time updated with raylib 2.5 //* //* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, //* BSD-like license that allows static linking with closed source software //* //* Copyright (c) 2014-2023 Ramon Santamaria (@raysan5) //* //********************************************************************************************/ // Download reasings.h from // https://github.com/raysan5/raylib/blob/master/examples/others/reasings.h // and copy it to this project's folder. // Build with `zig build-exe main.zig -idirafter ./ -lc -lraylib` const c = @cImport( { @cInclude("raylib.h"); @cInclude("reasings.h"); }); pub fn main() void { const screen_width = 800; const screen_height = 450; const recs_width = 50; const recs_height = 50; const max_recs_x = screen_width / recs_width; const max_recs_y = screen_height / recs_height; const play_time_in_frames = 240; // At 60 fps = 4 seconds c.InitWindow(screen_width, screen_height, "raylib [shapes] example - easings rectangle array"); defer c.CloseWindow(); // Close window and OpenGL context // Box variables to be animated with easings var recs: [max_recs_x * max_recs_y]c.Rectangle = comptime init_rectangles: { var init_rec: [max_recs_x * max_recs_y]c.Rectangle = undefined; for (0..max_recs_y) |y| { for (0..max_recs_x) |x| { init_rec[y * max_recs_x + x].x = recs_width / 2.0 + @as(comptime_float, @floatFromInt(recs_width * x)); init_rec[y * max_recs_x + x].y = recs_height / 2.0 + @as(comptime_float, @floatFromInt(recs_height * y)); init_rec[y * max_recs_x + x].width = recs_width; init_rec[y * max_recs_x + x].height = recs_height; } } break :init_rectangles init_rec; }; var rotation: f32 = 0.0; var frames_counter: u32 = 0; var state: u32 = 0; // Rectangles animation state: 0-Playing, 1-Finished c.SetTargetFPS(60); while (!c.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if (state == 0) { frames_counter += 1; for (0..max_recs_x * max_recs_y) |i| { recs[i].height = c.EaseCircOut(@floatFromInt(frames_counter), recs_height, -recs_height, play_time_in_frames); recs[i].width = c.EaseCircOut(@floatFromInt(frames_counter), recs_width, -recs_width, play_time_in_frames); if (recs[i].height < 0) recs[i].height = 0.0; if (recs[i].width < 0) recs[i].width = 0.0; if ((recs[i].height == 0) and (recs[i].width == 0)) state = 1; // Finish playing rotation = c.EaseLinearIn(@floatFromInt(frames_counter), 0.0, 360.0, play_time_in_frames); } } else if ((state == 1) and c.IsKeyPressed(c.KEY_SPACE)) { // When animation has finished, press space to restart frames_counter = 0; for (0..max_recs_x * max_recs_y) |i| { recs[i].height = recs_height; recs[i].width = recs_width; } state = 0; } //---------------------------------------------------------------------------------- // Draw //--------------------------------------------------------------------------------- c.BeginDrawing(); defer c.EndDrawing(); c.ClearBackground(c.RAYWHITE); if (state == 0) { for (0..max_recs_x * max_recs_y) |i| c.DrawRectanglePro(recs[i], .{ .x = recs[i].width / 2.0, .y = recs[i].height / 2.0 }, rotation, c.RED); } else if (state == 1) c.DrawText("PRESS [SPACE] TO PLAY AGAIN!", 240, 200, 20, c.GRAY); //--------------------------------------------------------------------------------- } }
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-41-shapes-easings-rectangle_array/build.sh
#!/bin/sh tmp_raylib_include_path='' tmp_raylib_external_include_path='' tmp_raylib_lib_path='' tmp_raylib_zig_build_mode='' # No command line arguments => use local variables if [ $# -eq 0 ]; then echo echo 'Using locally defined build variables and paths' # Set the paths here if you invoke this build.sh manually tmp_raylib_path='~/ray' tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include" tmp_raylib_external_include_path="${tmp_raylib_path}/src/external" tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib" # One of: # -O Debug # -O ReleaseFast # -O ReleaseSafe # -O ReleaseSmall tmp_raylib_zig_build_mode='-O ReleaseSmall' else # Using variables set in ../build_example.sh tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH tmp_raylib_lib_path=$RAYLIB_LIB_PATH tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE fi tmp_raylib_include_arg='' if [ -n "$tmp_raylib_include_path" ]; then # Not empty tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}" fi if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}" fi #echo 'tmp_raylib_include_arg = ' #echo "$tmp_raylib_include_arg" tmp_raylib_lib_arg='' if [ -n "$tmp_raylib_lib_path" ]; then # Not empty tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib" else tmp_raylib_lib_arg='-lc -lraylib' fi #echo 'tmp_raylib_lib_arg = ' #echo "$tmp_raylib_lib_arg" echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}" zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-41-shapes-easings-rectangle_array/build.bat
@echo off REM First parameter not set = build.bat launched manually if "%~1"=="" ( echo. echo Using locally defined build variables and paths setlocal enableDelayedExpansion REM These values are used if you invoke this build.bat file manualy. REM If you use build_example.bat in the root folder, values set in that file are used. SET RAYLIB_PATH=D:\libs\raylib-4.5.0 SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib REM One of: REM -O Debug REM -O ReleaseFast REM -O ReleaseSafe REM -O ReleaseSmall SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall ) REM echo RAYLIB_PATH: %RAYLIB_PATH% REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH% REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH% REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH% REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE% @echo on zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc @echo off REM End local variables scope if not called from the main script if "%~1"=="" ( endlocal & ( SET RAYLIB_PATH=%RAYLIB_PATH% SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH% SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH% SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH% SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE% ) )
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-41-shapes-easings-rectangle_array/clean.bat
del main.exe del main.exe.obj del main.pdb
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-39-shapes-easings-ball_anim/clean.sh
rm ./main rm ./main.o
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-39-shapes-easings-ball_anim/main.zig
// This is a Zig version of a raylib example from // https://github.com/raysan5/raylib/ // It is distributed under the same license as the original - unmodified zlib/libpng license // Header from the original source code follows below: ///******************************************************************************************* //* //* raylib [shapes] example - easings ball anim //* //* Example originally created with raylib 2.5, last time updated with raylib 2.5 //* //* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, //* BSD-like license that allows static linking with closed source software //* //* Copyright (c) 2014-2023 Ramon Santamaria (@raysan5) //* //********************************************************************************************/ // Download reasings.h from // https://github.com/raysan5/raylib/blob/master/examples/others/reasings.h // and copy it to this project's folder. // Build with `zig build-exe main.zig -idirafter ./ -lc -lraylib` const c = @cImport( { @cInclude("raylib.h"); @cInclude("reasings.h"); }); pub fn main() void { const screen_width = 800; const screen_height = 450; c.InitWindow(screen_width, screen_height, "raylib [shapes] example - easings ball anim"); defer c.CloseWindow(); // Close window and OpenGL context // Ball variable value to be animated with easings var ball_pos_x: i32 = -100; var ball_radius: i32 = 20; var ball_alpha: f32 = 0.0; var state: u32 = 0; var frames_counter: u32 = 0; c.SetTargetFPS(60); while (!c.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if (state == 0) // Move ball position X with easing { frames_counter += 1; ball_pos_x = @intFromFloat(c.EaseElasticOut(@floatFromInt(frames_counter), -100, screen_width/2.0 + 100, 120)); if (frames_counter >= 120) { frames_counter = 0; state = 1; } } else if (state == 1) // Increase ball radius with easing { frames_counter += 1; ball_radius = @intFromFloat(c.EaseElasticIn(@floatFromInt(frames_counter), 20, 500, 200)); if (frames_counter >= 200) { frames_counter = 0; state = 2; } } else if (state == 2) // Change ball alpha with easing (background color blending) { frames_counter += 1; ball_alpha = c.EaseCubicOut(@floatFromInt(frames_counter), 0.0, 1.0, 200); if (frames_counter >= 200) { frames_counter = 0; state = 3; } } else if (state == 3) // Reset state to play again { if (c.IsKeyPressed(c.KEY_ENTER)) { // Reset required variables to play again ball_pos_x = -100; ball_radius = 20; ball_alpha = 0.0; state = 0; } } if (c.IsKeyPressed(c.KEY_R)) frames_counter = 0; //---------------------------------------------------------------------------------- // Draw //--------------------------------------------------------------------------------- c.BeginDrawing(); defer c.EndDrawing(); c.ClearBackground(c.RAYWHITE); if (state >= 2) c.DrawRectangle(0, 0, screen_width, screen_height, c.GREEN); c.DrawCircle(ball_pos_x, 200, @floatFromInt(ball_radius), c.Fade(c.RED, 1.0 - ball_alpha)); if (state == 3) c.DrawText("PRESS [ENTER] TO PLAY AGAIN!", 240, 200, 20, c.BLACK); //--------------------------------------------------------------------------------- } }
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-39-shapes-easings-ball_anim/build.sh
#!/bin/sh tmp_raylib_include_path='' tmp_raylib_external_include_path='' tmp_raylib_lib_path='' tmp_raylib_zig_build_mode='' # No command line arguments => use local variables if [ $# -eq 0 ]; then echo echo 'Using locally defined build variables and paths' # Set the paths here if you invoke this build.sh manually tmp_raylib_path='~/ray' tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include" tmp_raylib_external_include_path="${tmp_raylib_path}/src/external" tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib" # One of: # -O Debug # -O ReleaseFast # -O ReleaseSafe # -O ReleaseSmall tmp_raylib_zig_build_mode='-O ReleaseSmall' else # Using variables set in ../build_example.sh tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH tmp_raylib_lib_path=$RAYLIB_LIB_PATH tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE fi tmp_raylib_include_arg='' if [ -n "$tmp_raylib_include_path" ]; then # Not empty tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}" fi if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}" fi #echo 'tmp_raylib_include_arg = ' #echo "$tmp_raylib_include_arg" tmp_raylib_lib_arg='' if [ -n "$tmp_raylib_lib_path" ]; then # Not empty tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib" else tmp_raylib_lib_arg='-lc -lraylib' fi #echo 'tmp_raylib_lib_arg = ' #echo "$tmp_raylib_lib_arg" echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}" zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-39-shapes-easings-ball_anim/build.bat
@echo off REM First parameter not set = build.bat launched manually if "%~1"=="" ( echo. echo Using locally defined build variables and paths setlocal enableDelayedExpansion REM These values are used if you invoke this build.bat file manualy. REM If you use build_example.bat in the root folder, values set in that file are used. SET RAYLIB_PATH=D:\libs\raylib-4.5.0 SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib REM One of: REM -O Debug REM -O ReleaseFast REM -O ReleaseSafe REM -O ReleaseSmall SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall ) REM echo RAYLIB_PATH: %RAYLIB_PATH% REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH% REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH% REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH% REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE% @echo on zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc @echo off REM End local variables scope if not called from the main script if "%~1"=="" ( endlocal & ( SET RAYLIB_PATH=%RAYLIB_PATH% SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH% SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH% SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH% SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE% ) )
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-39-shapes-easings-ball_anim/clean.bat
del main.exe del main.exe.obj del main.pdb
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-17-core-window-flags/clean.sh
rm ./main rm ./main.o
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-17-core-window-flags/main.zig
// build with `zig build-exe main.zig -lc -lraylib` // This is a Zig version of a raylib example from // https://github.com/raysan5/raylib/ // It is distributed under the same license as the original - unmodified zlib/libpng license // Header from the original source code follows below: ///******************************************************************************************* //* //* raylib [core] example - window flags //* //* Example originally created with raylib 3.5, last time updated with raylib 3.5 //* //* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, //* BSD-like license that allows static linking with closed source software //* //* Copyright (c) 2020-2023 Ramon Santamaria (@raysan5) //* //********************************************************************************************/ const c = @cImport( { @cInclude("raylib.h"); }); pub fn main() void { const screen_width = 800; const screen_height = 450; // Possible window flags // // FLAG_VSYNC_HINT // FLAG_FULLSCREEN_MODE -> not working properly -> wrong scaling! // FLAG_WINDOW_RESIZABLE // FLAG_WINDOW_UNDECORATED // FLAG_WINDOW_TRANSPARENT // FLAG_WINDOW_HIDDEN // FLAG_WINDOW_MINIMIZED -> Not supported on window creation // FLAG_WINDOW_MAXIMIZED -> Not supported on window creation // FLAG_WINDOW_UNFOCUSED // FLAG_WINDOW_TOPMOST // FLAG_WINDOW_HIGHDPI -> errors after minimize-resize, fb size is recalculated // FLAG_WINDOW_ALWAYS_RUN // FLAG_MSAA_4X_HINT // Set configuration flags for window creation //SetConfigFlags(FLAG_VSYNC_HINT | FLAG_MSAA_4X_HINT | FLAG_WINDOW_HIGHDPI); c.InitWindow(screen_width, screen_height, "raylib [core] example - window flags"); defer c.CloseWindow(); // Close window and OpenGL context var ball_pos = c.Vector2{ .x = @as(f32, @floatFromInt(c.GetScreenWidth())) / 2.0, // f32 .y = @as(f32, @floatFromInt(c.GetScreenHeight())) / 2.0 }; // f32 var ball_speed = c.Vector2{ .x = 5.0, .y = 4.0 }; const ball_radius = 20.0; var frames_counter: c_int = 0; //c.SetTargetFPS(60); // Set our game to run at 60 frames-per-second while (!c.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if (c.IsKeyPressed(c.KEY_F)) c.ToggleFullscreen(); // modifies window size when scaling! if (c.IsKeyPressed(c.KEY_R)) { if (c.IsWindowState(c.FLAG_WINDOW_RESIZABLE)) { c.ClearWindowState(c.FLAG_WINDOW_RESIZABLE); } else c.SetWindowState(c.FLAG_WINDOW_RESIZABLE); } if (c.IsKeyPressed(c.KEY_D)) { if (c.IsWindowState(c.FLAG_WINDOW_UNDECORATED)) { c.ClearWindowState(c.FLAG_WINDOW_UNDECORATED); } else c.SetWindowState(c.FLAG_WINDOW_UNDECORATED); } if (c.IsKeyPressed(c.KEY_H)) { if (!c.IsWindowState(c.FLAG_WINDOW_HIDDEN)) c.SetWindowState(c.FLAG_WINDOW_HIDDEN); frames_counter = 0; } if (c.IsWindowState(c.FLAG_WINDOW_HIDDEN)) { frames_counter += 1; if (frames_counter >= 240) c.ClearWindowState(c.FLAG_WINDOW_HIDDEN); // Show window after 3 seconds } if (c.IsKeyPressed(c.KEY_N)) { if (!c.IsWindowState(c.FLAG_WINDOW_MINIMIZED)) c.MinimizeWindow(); frames_counter = 0; } if (c.IsWindowState(c.FLAG_WINDOW_MINIMIZED)) { frames_counter += 1; if (frames_counter >= 240) c.RestoreWindow(); // Restore window after 3 seconds } if (c.IsKeyPressed(c.KEY_M)) { // NOTE: Requires FLAG_WINDOW_RESIZABLE enabled! if (c.IsWindowState(c.FLAG_WINDOW_MAXIMIZED)) { c.RestoreWindow(); } else c.MaximizeWindow(); } if (c.IsKeyPressed(c.KEY_U)) { if (c.IsWindowState(c.FLAG_WINDOW_UNFOCUSED)) { c.ClearWindowState(c.FLAG_WINDOW_UNFOCUSED); } else c.SetWindowState(c.FLAG_WINDOW_UNFOCUSED); } if (c.IsKeyPressed(c.KEY_T)) { if (c.IsWindowState(c.FLAG_WINDOW_TOPMOST)) { c.ClearWindowState(c.FLAG_WINDOW_TOPMOST); } else c.SetWindowState(c.FLAG_WINDOW_TOPMOST); } if (c.IsKeyPressed(c.KEY_A)) { if (c.IsWindowState(c.FLAG_WINDOW_ALWAYS_RUN)) { c.ClearWindowState(c.FLAG_WINDOW_ALWAYS_RUN); } else c.SetWindowState(c.FLAG_WINDOW_ALWAYS_RUN); } if (c.IsKeyPressed(c.KEY_V)) { if (c.IsWindowState(c.FLAG_VSYNC_HINT)) { c.ClearWindowState(c.FLAG_VSYNC_HINT); } else c.SetWindowState(c.FLAG_VSYNC_HINT); } // Bouncing ball logic ball_pos.x += ball_speed.x; ball_pos.y += ball_speed.y; if ((ball_pos.x >= (@as(f32, @floatFromInt(c.GetScreenWidth())) - ball_radius)) or (ball_pos.x <= ball_radius)) ball_speed.x = -ball_speed.x; if ((ball_pos.y >= (@as(f32, @floatFromInt(c.GetScreenHeight())) - ball_radius)) or (ball_pos.y <= ball_radius)) ball_speed.y = -ball_speed.y; //---------------------------------------------------------------------------------- // Draw //--------------------------------------------------------------------------------- c.BeginDrawing(); defer c.EndDrawing(); if (c.IsWindowState(c.FLAG_WINDOW_TRANSPARENT)) { c.ClearBackground(c.BLANK); } else c.ClearBackground(c.RAYWHITE); c.DrawCircleV(ball_pos, ball_radius, c.MAROON); c.DrawRectangleLinesEx(.{ .x = 0.0, .y = 0, .width = @floatFromInt(c.GetScreenWidth()), .height = @floatFromInt(c.GetScreenHeight()) }, 4, c.RAYWHITE); c.DrawCircleV(c.GetMousePosition(), 10, c.DARKBLUE); c.DrawFPS(10, 10); c.DrawText(c.TextFormat("Screen Size: [%i, %i]", c.GetScreenWidth(), c.GetScreenHeight()), 10, 40, 10, c.GREEN); // Draw window state info c.DrawText("Following flags can be set after window creation:", 10, 60, 10, c.GRAY); if (c.IsWindowState(c.FLAG_FULLSCREEN_MODE)) { c.DrawText("[F] FLAG_FULLSCREEN_MODE: on", 10, 80, 10, c.LIME); } else c.DrawText("[F] FLAG_FULLSCREEN_MODE: off", 10, 80, 10, c.MAROON); if (c.IsWindowState(c.FLAG_WINDOW_RESIZABLE)) { c.DrawText("[R] FLAG_WINDOW_RESIZABLE: on", 10, 100, 10, c.LIME); } else c.DrawText("[R] FLAG_WINDOW_RESIZABLE: off", 10, 100, 10, c.MAROON); if (c.IsWindowState(c.FLAG_WINDOW_UNDECORATED)) { c.DrawText("[D] FLAG_WINDOW_UNDECORATED: on", 10, 120, 10, c.LIME); } else c.DrawText("[D] FLAG_WINDOW_UNDECORATED: off", 10, 120, 10, c.MAROON); if (c.IsWindowState(c.FLAG_WINDOW_HIDDEN)) { c.DrawText("[H] FLAG_WINDOW_HIDDEN: on", 10, 140, 10, c.LIME); } else c.DrawText("[H] FLAG_WINDOW_HIDDEN: off", 10, 140, 10, c.MAROON); if (c.IsWindowState(c.FLAG_WINDOW_MINIMIZED)) { c.DrawText("[N] FLAG_WINDOW_MINIMIZED: on", 10, 160, 10, c.LIME); } else c.DrawText("[N] FLAG_WINDOW_MINIMIZED: off", 10, 160, 10, c.MAROON); if (c.IsWindowState(c.FLAG_WINDOW_MAXIMIZED)) { c.DrawText("[M] FLAG_WINDOW_MAXIMIZED: on", 10, 180, 10, c.LIME); } else c.DrawText("[M] FLAG_WINDOW_MAXIMIZED: off", 10, 180, 10, c.MAROON); if (c.IsWindowState(c.FLAG_WINDOW_UNFOCUSED)) { c.DrawText("[G] FLAG_WINDOW_UNFOCUSED: on", 10, 200, 10, c.LIME); } else c.DrawText("[U] FLAG_WINDOW_UNFOCUSED: off", 10, 200, 10, c.MAROON); if (c.IsWindowState(c.FLAG_WINDOW_TOPMOST)) { c.DrawText("[T] FLAG_WINDOW_TOPMOST: on", 10, 220, 10, c.LIME); } else c.DrawText("[T] FLAG_WINDOW_TOPMOST: off", 10, 220, 10, c.MAROON); if (c.IsWindowState(c.FLAG_WINDOW_ALWAYS_RUN)) { c.DrawText("[A] FLAG_WINDOW_ALWAYS_RUN: on", 10, 240, 10, c.LIME); } else c.DrawText("[A] FLAG_WINDOW_ALWAYS_RUN: off", 10, 240, 10, c.MAROON); if (c.IsWindowState(c.FLAG_VSYNC_HINT)) { c.DrawText("[V] FLAG_VSYNC_HINT: on", 10, 260, 10, c.LIME); } else c.DrawText("[V] FLAG_VSYNC_HINT: off", 10, 260, 10, c.MAROON); c.DrawText("Following flags can only be set before window creation:", 10, 300, 10, c.GRAY); if (c.IsWindowState(c.FLAG_WINDOW_HIGHDPI)) { c.DrawText("FLAG_WINDOW_HIGHDPI: on", 10, 320, 10, c.LIME); } else c.DrawText("FLAG_WINDOW_HIGHDPI: off", 10, 320, 10, c.MAROON); if (c.IsWindowState(c.FLAG_WINDOW_TRANSPARENT)) { c.DrawText("FLAG_WINDOW_TRANSPARENT: on", 10, 340, 10, c.LIME); } else c.DrawText("FLAG_WINDOW_TRANSPARENT: off", 10, 340, 10, c.MAROON); if (c.IsWindowState(c.FLAG_MSAA_4X_HINT)) { c.DrawText("FLAG_MSAA_4X_HINT: on", 10, 360, 10, c.LIME); } else c.DrawText("FLAG_MSAA_4X_HINT: off", 10, 360, 10, c.MAROON); //--------------------------------------------------------------------------------- } }
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-17-core-window-flags/build.sh
#!/bin/sh tmp_raylib_include_path='' tmp_raylib_external_include_path='' tmp_raylib_lib_path='' tmp_raylib_zig_build_mode='' # No command line arguments => use local variables if [ $# -eq 0 ]; then echo echo 'Using locally defined build variables and paths' # Set the paths here if you invoke this build.sh manually tmp_raylib_path='~/ray' tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include" tmp_raylib_external_include_path="${tmp_raylib_path}/src/external" tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib" # One of: # -O Debug # -O ReleaseFast # -O ReleaseSafe # -O ReleaseSmall tmp_raylib_zig_build_mode='-O ReleaseSmall' else # Using variables set in ../build_example.sh tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH tmp_raylib_lib_path=$RAYLIB_LIB_PATH tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE fi tmp_raylib_include_arg='' if [ -n "$tmp_raylib_include_path" ]; then # Not empty tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}" fi if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}" fi #echo 'tmp_raylib_include_arg = ' #echo "$tmp_raylib_include_arg" tmp_raylib_lib_arg='' if [ -n "$tmp_raylib_lib_path" ]; then # Not empty tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib" else tmp_raylib_lib_arg='-lc -lraylib' fi #echo 'tmp_raylib_lib_arg = ' #echo "$tmp_raylib_lib_arg" echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}" zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-17-core-window-flags/build.bat
@echo off REM First parameter not set = build.bat launched manually if "%~1"=="" ( echo. echo Using locally defined build variables and paths setlocal enableDelayedExpansion REM These values are used if you invoke this build.bat file manualy. REM If you use build_example.bat in the root folder, values set in that file are used. SET RAYLIB_PATH=D:\libs\raylib-4.5.0 SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib REM One of: REM -O Debug REM -O ReleaseFast REM -O ReleaseSafe REM -O ReleaseSmall SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall ) REM echo RAYLIB_PATH: %RAYLIB_PATH% REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH% REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH% REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH% REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE% @echo on zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc @echo off REM End local variables scope if not called from the main script if "%~1"=="" ( endlocal & ( SET RAYLIB_PATH=%RAYLIB_PATH% SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH% SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH% SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH% SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE% ) )
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-17-core-window-flags/clean.bat
del main.exe del main.exe.obj del main.pdb
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-54b-textures-texture-from-raw-data-(runtime-init)/clean.sh
rm ./main rm ./main.o
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-54b-textures-texture-from-raw-data-(runtime-init)/main.zig
// build with `zig build-exe main.zig -lc -lraylib` // This is a Zig version of a raylib example from // https://github.com/raysan5/raylib/ // It is distributed under the same license as the original - unmodified zlib/libpng license // Header from the original source code follows below: ///******************************************************************************************* //* //* raylib [textures] example - Load textures from raw data //* //* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) //* //* Example originally created with raylib 1.3, last time updated with raylib 3.5 //* //* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, //* BSD-like license that allows static linking with closed source software //* //* Copyright (c) 2015-2023 Ramon Santamaria (@raysan5) //* //********************************************************************************************/ // This version generates the texture at runtime, like the original C example. // See version 54a for the version that generates the texture at comptime (compilation time). const std = @import("std"); // std.heap.page_allocator const c = @cImport( { @cInclude("raylib.h"); }); pub fn main() void { const screen_width = 800; const screen_height = 450; c.InitWindow(screen_width, screen_height, "raylib [textures] example - texture from raw data"); defer c.CloseWindow(); // Close window and OpenGL context // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // Load RAW image data (512x512, 32bit RGBA, no file header). // Allocates required memory using malloc(). const fudesumi_raw = c.LoadImageRaw("resources/fudesumi.raw", 384, 512, c.PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 0); const fudesumi = c.LoadTextureFromImage(fudesumi_raw); // Upload CPU (RAM) image to GPU (VRAM) - Texture2D defer c.UnloadTexture(fudesumi); // Unload texture from GPU memory (VRAM) c.UnloadImage(fudesumi_raw); // Free the image.data using free() - see below for explanation if you need one // Generate a checked texture by code const width = 960; const height = 480; // Dynamic memory allocation to store pixels data (Color type). // Since we want just one large buffer, using OS kernel functions is OK. const alloc8r = std.heap.page_allocator; //pub const struct_Color = extern struct { r: u8, g: u8, b: u8, a: u8, }; //pub const Color = struct_Color; var pixels = alloc8r.alloc(c.Color, width * height) catch |err| { std.debug.print("\nERROR: could not allocate {} bytes for the texture in RAM\n", .{width * height * @sizeOf(c.Color)}); std.debug.print("{}\n", .{err}); return; }; // Generate texture data in the allocated memory for (0..height) |y| { for (0..width) |x| { if (((x / 32 + y / 32) / 1) % 2 == 0) { pixels[y * width + x] = c.ORANGE; } else pixels[y * width + x] = c.GOLD; } } // Load pixels data into an image structure and create texture const checked_im = c.Image { // pixels is a pointer already, unlike in 54a // @ptrCast -> ?*anyopaque .data = @ptrCast(pixels), // We can assign pixels directly to data .width = width, .height = height, .format = c.PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, .mipmaps = 1 }; // NOTE: image is not unloaded, it must be done manually const checked = c.LoadTextureFromImage(checked_im); // Texture2D // The following call // --- c.UnloadImage(checked_im); // Unload CPU (RAM) image data (pixels) // does this - //void UnloadImage(Image image) //{ // RL_FREE(image.data); //} // RL_FREE is defined in raylib.h as //#ifndef RL_FREE // #define RL_FREE(ptr) free(ptr) //#endif // Translated to Zig as //pub inline fn RL_FREE(ptr: anytype) @TypeOf(free(ptr)) { // return free(ptr); //} // Which means we're not to call UnloadImage(), unless we use malloc() to allocate image pixels, // like in the original C code. // Instead, we call alloc8r.free(pixels); //c.SetTargetFPS(60); - Don't need this since we really only display a static image while (!c.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- // TODO: Update your variables here //---------------------------------------------------------------------------------- // Draw //--------------------------------------------------------------------------------- { c.BeginDrawing(); defer c.EndDrawing(); c.ClearBackground(c.RAYWHITE); c.DrawTexture(checked, screen_width / 2 - @divTrunc(checked.width, 2), screen_height/2 - @divTrunc(checked.height, 2), c.Fade(c.WHITE, 0.5)); c.DrawTexture(fudesumi, 430, -30, c.WHITE); c.DrawText("CHECKED TEXTURE ", 84, 85, 30, c.BROWN); c.DrawText("GENERATED by CODE", 72, 148, 30, c.BROWN); c.DrawText("and RAW IMAGE LOADING", 46, 210, 30, c.BROWN); c.DrawText("(c) Fudesumi sprite by Eiden Marsal", 310, screen_height - 20, 10, c.BROWN); } //--------------------------------------------------------------------------------- } }
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-54b-textures-texture-from-raw-data-(runtime-init)/build.sh
#!/bin/sh tmp_raylib_include_path='' tmp_raylib_external_include_path='' tmp_raylib_lib_path='' tmp_raylib_zig_build_mode='' # No command line arguments => use local variables if [ $# -eq 0 ]; then echo echo 'Using locally defined build variables and paths' # Set the paths here if you invoke this build.sh manually tmp_raylib_path='~/ray' tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include" tmp_raylib_external_include_path="${tmp_raylib_path}/src/external" tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib" # One of: # -O Debug # -O ReleaseFast # -O ReleaseSafe # -O ReleaseSmall tmp_raylib_zig_build_mode='-O ReleaseSmall' else # Using variables set in ../build_example.sh tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH tmp_raylib_lib_path=$RAYLIB_LIB_PATH tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE fi tmp_raylib_include_arg='' if [ -n "$tmp_raylib_include_path" ]; then # Not empty tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}" fi if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}" fi #echo 'tmp_raylib_include_arg = ' #echo "$tmp_raylib_include_arg" tmp_raylib_lib_arg='' if [ -n "$tmp_raylib_lib_path" ]; then # Not empty tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib" else tmp_raylib_lib_arg='-lc -lraylib' fi #echo 'tmp_raylib_lib_arg = ' #echo "$tmp_raylib_lib_arg" echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}" zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-54b-textures-texture-from-raw-data-(runtime-init)/build.bat
@echo off REM First parameter not set = build.bat launched manually if "%~1"=="" ( echo. echo Using locally defined build variables and paths setlocal enableDelayedExpansion REM These values are used if you invoke this build.bat file manualy. REM If you use build_example.bat in the root folder, values set in that file are used. SET RAYLIB_PATH=D:\libs\raylib-4.5.0 SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib REM One of: REM -O Debug REM -O ReleaseFast REM -O ReleaseSafe REM -O ReleaseSmall SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall ) REM echo RAYLIB_PATH: %RAYLIB_PATH% REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH% REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH% REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH% REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE% @echo on zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc @echo off REM End local variables scope if not called from the main script if "%~1"=="" ( endlocal & ( SET RAYLIB_PATH=%RAYLIB_PATH% SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH% SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH% SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH% SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE% ) )
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-54b-textures-texture-from-raw-data-(runtime-init)/clean.bat
del main.exe del main.exe.obj del main.pdb
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-34-shapes-logo-raylib_anim/clean.sh
rm ./main rm ./main.o
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-34-shapes-logo-raylib_anim/main.zig
// build with `zig build-exe main.zig -lc -lraylib` // This is a Zig version of a raylib example from // https://github.com/raysan5/raylib/ // It is distributed under the same license as the original - unmodified zlib/libpng license // Header from the original source code follows below: ///******************************************************************************************* //* //* raylib [shapes] example - raylib logo animation //* //* Example originally created with raylib 2.5, last time updated with raylib 4.0 //* //* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, //* BSD-like license that allows static linking with closed source software //* //* Copyright (c) 2014-2023 Ramon Santamaria (@raysan5) //* //********************************************************************************************/ const c = @cImport( { @cInclude("raylib.h"); }); pub fn main() void { const screen_width = 800; const screen_height = 450; c.InitWindow(screen_width, screen_height, "raylib [shapes] example - raylib logo animation"); defer c.CloseWindow(); // Close window and OpenGL context const logo_pos_x = screen_width / 2 - 128; const logo_pos_y = screen_height / 2 - 128; var frames_counter: u32 = 0; var letters_count: u32 = 0; var top_side_rec_width: c_int = 16; // Easier to go with c_int than coerce other type to it many var left_side_rec_height: c_int = 16; // times. var bottom_side_rec_width: c_int = 16; var right_side_rec_height: c_int = 16; var state: u32 = 0; // Tracking animation states (State Machine) var alpha: f32 = 1.0; // Useful for fading c.SetTargetFPS(60); // Set our game to run at 60 frames-per-second while (!c.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- if (state == 0) // State 0: Small box blinking { frames_counter += 1; if (frames_counter == 120) { state = 1; frames_counter = 0; // Reset counter... will be used later... } } else if (state == 1) // State 1: Top and left bars growing { top_side_rec_width += 4; left_side_rec_height += 4; if (top_side_rec_width == 256) state = 2; } else if (state == 2) // State 2: Bottom and right bars growing { bottom_side_rec_width += 4; right_side_rec_height += 4; if (bottom_side_rec_width == 256) state = 3; } else if (state == 3) // State 3: Letters appearing (one by one) { frames_counter += 1; //if (frames_counter/12 != 0) // Every 12 frames, one more letter! if (frames_counter >= 12) // Dividing frames_counter by 12 to check if it is >= 12 is kinda weird { letters_count += 1; frames_counter = 0; } if (letters_count >= 10) // When all letters have appeared, just fade out everything { alpha -= 0.02; if (alpha <= 0.0) { alpha = 0.0; state = 4; } } } else if (state == 4) // State 4: Reset and Replay { if (c.IsKeyPressed(c.KEY_R)) { frames_counter = 0; letters_count = 0; top_side_rec_width = 16; left_side_rec_height = 16; bottom_side_rec_width = 16; right_side_rec_height = 16; alpha = 1.0; state = 0; // Return to State 0 } } //---------------------------------------------------------------------------------- // Draw //--------------------------------------------------------------------------------- c.BeginDrawing(); defer c.EndDrawing(); c.ClearBackground(c.RAYWHITE); // I have switched from ifs to switch here. // Pun intented. switch (state) { 0 => { if ((frames_counter / 15) % 2 != 0) c.DrawRectangle(logo_pos_x, logo_pos_y, 16, 16, c.BLACK); }, 1 => { c.DrawRectangle(logo_pos_x, logo_pos_y, top_side_rec_width, 16, c.BLACK); c.DrawRectangle(logo_pos_x, logo_pos_y, 16, left_side_rec_height, c.BLACK); }, 2 => { c.DrawRectangle(logo_pos_x, logo_pos_y, top_side_rec_width, 16, c.BLACK); c.DrawRectangle(logo_pos_x, logo_pos_y, 16, left_side_rec_height, c.BLACK); c.DrawRectangle(logo_pos_x + 240, logo_pos_y, 16, right_side_rec_height, c.BLACK); c.DrawRectangle(logo_pos_x, logo_pos_y + 240, bottom_side_rec_width, 16, c.BLACK); }, 3 => { c.DrawRectangle(logo_pos_x, logo_pos_y, top_side_rec_width, 16, c.Fade(c.BLACK, alpha)); c.DrawRectangle(logo_pos_x, logo_pos_y + 16, 16, left_side_rec_height - 32, c.Fade(c.BLACK, alpha)); c.DrawRectangle(logo_pos_x + 240, logo_pos_y + 16, 16, right_side_rec_height - 32, c.Fade(c.BLACK, alpha)); c.DrawRectangle(logo_pos_x, logo_pos_y + 240, bottom_side_rec_width, 16, c.Fade(c.BLACK, alpha)); c.DrawRectangle(@divTrunc(c.GetScreenWidth(), 2) - 112, @divTrunc(c.GetScreenHeight(), 2) - 112, 224, 224, c.Fade(c.RAYWHITE, alpha)); c.DrawText(c.TextSubtext("raylib", 0, @intCast(letters_count)), // c_int @divTrunc(c.GetScreenWidth(), 2) - 44, @divTrunc(c.GetScreenHeight(), 2) + 48, 50, c.Fade(c.BLACK, alpha)); }, 4 => c.DrawText("[R] REPLAY", 340, 200, 20, c.GRAY), else => {} // switches in Zig must be exhaustive } //--------------------------------------------------------------------------------- } }
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-34-shapes-logo-raylib_anim/build.sh
#!/bin/sh tmp_raylib_include_path='' tmp_raylib_external_include_path='' tmp_raylib_lib_path='' tmp_raylib_zig_build_mode='' # No command line arguments => use local variables if [ $# -eq 0 ]; then echo echo 'Using locally defined build variables and paths' # Set the paths here if you invoke this build.sh manually tmp_raylib_path='~/ray' tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include" tmp_raylib_external_include_path="${tmp_raylib_path}/src/external" tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib" # One of: # -O Debug # -O ReleaseFast # -O ReleaseSafe # -O ReleaseSmall tmp_raylib_zig_build_mode='-O ReleaseSmall' else # Using variables set in ../build_example.sh tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH tmp_raylib_lib_path=$RAYLIB_LIB_PATH tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE fi tmp_raylib_include_arg='' if [ -n "$tmp_raylib_include_path" ]; then # Not empty tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}" fi if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}" fi #echo 'tmp_raylib_include_arg = ' #echo "$tmp_raylib_include_arg" tmp_raylib_lib_arg='' if [ -n "$tmp_raylib_lib_path" ]; then # Not empty tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib" else tmp_raylib_lib_arg='-lc -lraylib' fi #echo 'tmp_raylib_lib_arg = ' #echo "$tmp_raylib_lib_arg" echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}" zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-34-shapes-logo-raylib_anim/build.bat
@echo off REM First parameter not set = build.bat launched manually if "%~1"=="" ( echo. echo Using locally defined build variables and paths setlocal enableDelayedExpansion REM These values are used if you invoke this build.bat file manualy. REM If you use build_example.bat in the root folder, values set in that file are used. SET RAYLIB_PATH=D:\libs\raylib-4.5.0 SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib REM One of: REM -O Debug REM -O ReleaseFast REM -O ReleaseSafe REM -O ReleaseSmall SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall ) REM echo RAYLIB_PATH: %RAYLIB_PATH% REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH% REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH% REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH% REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE% @echo on zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc @echo off REM End local variables scope if not called from the main script if "%~1"=="" ( endlocal & ( SET RAYLIB_PATH=%RAYLIB_PATH% SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH% SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH% SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH% SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE% ) )
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-34-shapes-logo-raylib_anim/clean.bat
del main.exe del main.exe.obj del main.pdb
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-40-shapes-easings-box_anim/clean.sh
rm ./main rm ./main.o
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-40-shapes-easings-box_anim/main.zig
// This is a Zig version of a raylib example from // https://github.com/raysan5/raylib/ // It is distributed under the same license as the original - unmodified zlib/libpng license // Header from the original source code follows below: ///******************************************************************************************* //* //* raylib [shapes] example - easings box anim //* //* Example originally created with raylib 2.5, last time updated with raylib 2.5 //* //* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, //* BSD-like license that allows static linking with closed source software //* //* Copyright (c) 2014-2023 Ramon Santamaria (@raysan5) //* //********************************************************************************************/ // Download reasings.h from // https://github.com/raysan5/raylib/blob/master/examples/others/reasings.h // and copy it to this project's folder. // Build with `zig build-exe main.zig -idirafter ./ -lc -lraylib` const c = @cImport( { @cInclude("raylib.h"); @cInclude("reasings.h"); }); pub fn main() void { const screen_width = 800; const screen_height = 450; c.InitWindow(screen_width, screen_height, "raylib [shapes] example - easings box anim"); defer c.CloseWindow(); // Close window and OpenGL context // Box variables to be animated with easings var rec = c.Rectangle{ .x = @as(f32, @floatFromInt(c.GetScreenWidth())) / 2.0, .y = -100, .width = 100, .height = 100 }; var rotation: f32 = 0.0; var alpha: f32 = 1.0; var state: u32 = 0; var frames_counter: u32 = 0; c.SetTargetFPS(60); while (!c.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- switch (state) { 0 => // Move box down to center of screen { frames_counter += 1; // NOTE: Remember that 3rd parameter of easing function refers to // desired value variation, do not confuse it with expected final value! rec.y = c.EaseElasticOut(@floatFromInt(frames_counter), -100, @as(f32, @floatFromInt(c.GetScreenHeight())) / 2.0 + 100.0, 120); if (frames_counter >= 120) { frames_counter = 0; state = 1; } }, 1 => // Scale box to an horizontal bar { frames_counter += 1; rec.height = c.EaseBounceOut(@floatFromInt(frames_counter), 100, -90, 120); rec.width = c.EaseBounceOut(@floatFromInt(frames_counter), 100, @floatFromInt(c.GetScreenWidth()), 120); if (frames_counter >= 120) { frames_counter = 0; state = 2; } }, 2 => // Rotate horizontal bar rectangle { frames_counter += 1; rotation = c.EaseQuadOut(@floatFromInt(frames_counter), 0.0, 270.0, 240); if (frames_counter >= 240) { frames_counter = 0; state = 3; } }, 3 => // Increase bar size to fill all screen { frames_counter += 1; rec.height = c.EaseCircOut(@floatFromInt(frames_counter), 10, @floatFromInt(c.GetScreenWidth()), 120); if (frames_counter >= 120) { frames_counter = 0; state = 4; } }, 4 => // Fade out animation { frames_counter += 1; alpha = c.EaseSineOut(@floatFromInt(frames_counter), 1.0, -1.0, 160); if (frames_counter >= 160) { frames_counter = 0; state = 5; } }, else => {} } // Reset animation at any moment if (c.IsKeyPressed(c.KEY_SPACE)) { rec = .{ .x = @as(f32, @floatFromInt(c.GetScreenWidth())) / 2.0, .y = -100.0, .width = 100.0, .height = 100.0 }; rotation = 0.0; alpha = 1.0; state = 0; frames_counter = 0; } //---------------------------------------------------------------------------------- // Draw //--------------------------------------------------------------------------------- c.BeginDrawing(); defer c.EndDrawing(); c.ClearBackground(c.RAYWHITE); c.DrawRectanglePro(rec, .{ .x = rec.width / 2.0, .y = rec.height / 2.0 }, rotation, c.Fade(c.BLACK, alpha)); c.DrawText("PRESS [SPACE] TO RESET BOX ANIMATION!", 10, c.GetScreenHeight() - 25, 20, c.LIGHTGRAY); //--------------------------------------------------------------------------------- } }
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-40-shapes-easings-box_anim/build.sh
#!/bin/sh tmp_raylib_include_path='' tmp_raylib_external_include_path='' tmp_raylib_lib_path='' tmp_raylib_zig_build_mode='' # No command line arguments => use local variables if [ $# -eq 0 ]; then echo echo 'Using locally defined build variables and paths' # Set the paths here if you invoke this build.sh manually tmp_raylib_path='~/ray' tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include" tmp_raylib_external_include_path="${tmp_raylib_path}/src/external" tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib" # One of: # -O Debug # -O ReleaseFast # -O ReleaseSafe # -O ReleaseSmall tmp_raylib_zig_build_mode='-O ReleaseSmall' else # Using variables set in ../build_example.sh tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH tmp_raylib_lib_path=$RAYLIB_LIB_PATH tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE fi tmp_raylib_include_arg='' if [ -n "$tmp_raylib_include_path" ]; then # Not empty tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}" fi if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}" fi #echo 'tmp_raylib_include_arg = ' #echo "$tmp_raylib_include_arg" tmp_raylib_lib_arg='' if [ -n "$tmp_raylib_lib_path" ]; then # Not empty tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib" else tmp_raylib_lib_arg='-lc -lraylib' fi #echo 'tmp_raylib_lib_arg = ' #echo "$tmp_raylib_lib_arg" echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}" zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-40-shapes-easings-box_anim/build.bat
@echo off REM First parameter not set = build.bat launched manually if "%~1"=="" ( echo. echo Using locally defined build variables and paths setlocal enableDelayedExpansion REM These values are used if you invoke this build.bat file manualy. REM If you use build_example.bat in the root folder, values set in that file are used. SET RAYLIB_PATH=D:\libs\raylib-4.5.0 SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib REM One of: REM -O Debug REM -O ReleaseFast REM -O ReleaseSafe REM -O ReleaseSmall SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall ) REM echo RAYLIB_PATH: %RAYLIB_PATH% REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH% REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH% REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH% REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE% @echo on zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc @echo off REM End local variables scope if not called from the main script if "%~1"=="" ( endlocal & ( SET RAYLIB_PATH=%RAYLIB_PATH% SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH% SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH% SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH% SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE% ) )
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-40-shapes-easings-box_anim/clean.bat
del main.exe del main.exe.obj del main.pdb
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-04-core-input-mouse-wheel/clean.sh
rm ./main rm ./main.o
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-04-core-input-mouse-wheel/main.zig
// build with `zig build-exe main.zig -lc -lraylib` // This is a Zig version of a raylib example from // https://github.com/raysan5/raylib/ // It is distributed under the same license as the original - unmodified zlib/libpng license // Header from the original source code follows below: ///******************************************************************************************* //* //* raylib [core] examples - Mouse wheel input //* //* Example originally created with raylib 1.1, last time updated with raylib 1.3 //* //* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, //* BSD-like license that allows static linking with closed source software //* //* Copyright (c) 2014-2023 Ramon Santamaria (@raysan5) //* //********************************************************************************************/ const c = @cImport( { @cInclude("raylib.h"); }); pub fn main() void { const screen_width = 800; const screen_height = 450; const scroll_speed = 4; c.InitWindow(screen_width, screen_height, "raylib [core] example - input mouse wheel"); defer c.CloseWindow(); // Close window and OpenGL context c.SetTargetFPS(60); var ball_pos_y: c_int = screen_height / 2 - 40; while (!c.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- // @round() is optional, i guess? // Since scroll_speed is an integer constant, there's no sense in coercing it to f32, // multiplying GetMouseWheelMove()'s result (f32) by it and then coercing the result // back to integer (c_int). //ball_pos_y -= @intFromFloat(@round(c.GetMouseWheelMove())) * scroll_speed; ball_pos_y -= @as(c_int, @intFromFloat(@round(c.GetMouseWheelMove()))) * scroll_speed; //---------------------------------------------------------------------------------- // Draw //--------------------------------------------------------------------------------- c.BeginDrawing(); defer c.EndDrawing(); c.ClearBackground(c.RAYWHITE); c.DrawRectangle(screen_width / 2 - 40, ball_pos_y, 80, 80, c.MAROON); c.DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, c.GRAY); c.DrawText(c.TextFormat("Box position Y: %03i", ball_pos_y), 10, 40, 20, c.LIGHTGRAY); //--------------------------------------------------------------------------------- } }
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-04-core-input-mouse-wheel/build.sh
#!/bin/sh tmp_raylib_include_path='' tmp_raylib_external_include_path='' tmp_raylib_lib_path='' tmp_raylib_zig_build_mode='' # No command line arguments => use local variables if [ $# -eq 0 ]; then echo echo 'Using locally defined build variables and paths' # Set the paths here if you invoke this build.sh manually tmp_raylib_path='~/ray' tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include" tmp_raylib_external_include_path="${tmp_raylib_path}/src/external" tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib" # One of: # -O Debug # -O ReleaseFast # -O ReleaseSafe # -O ReleaseSmall tmp_raylib_zig_build_mode='-O ReleaseSmall' else # Using variables set in ../build_example.sh tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH tmp_raylib_lib_path=$RAYLIB_LIB_PATH tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE fi tmp_raylib_include_arg='' if [ -n "$tmp_raylib_include_path" ]; then # Not empty tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}" fi if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}" fi #echo 'tmp_raylib_include_arg = ' #echo "$tmp_raylib_include_arg" tmp_raylib_lib_arg='' if [ -n "$tmp_raylib_lib_path" ]; then # Not empty tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib" else tmp_raylib_lib_arg='-lc -lraylib' fi #echo 'tmp_raylib_lib_arg = ' #echo "$tmp_raylib_lib_arg" echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}" zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-04-core-input-mouse-wheel/build.bat
@echo off REM First parameter not set = build.bat launched manually if "%~1"=="" ( echo. echo Using locally defined build variables and paths setlocal enableDelayedExpansion REM These values are used if you invoke this build.bat file manualy. REM If you use build_example.bat in the root folder, values set in that file are used. SET RAYLIB_PATH=D:\libs\raylib-4.5.0 SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib REM One of: REM -O Debug REM -O ReleaseFast REM -O ReleaseSafe REM -O ReleaseSmall SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall ) REM echo RAYLIB_PATH: %RAYLIB_PATH% REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH% REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH% REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH% REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE% @echo on zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc @echo off REM End local variables scope if not called from the main script if "%~1"=="" ( endlocal & ( SET RAYLIB_PATH=%RAYLIB_PATH% SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH% SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH% SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH% SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE% ) )
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-04-core-input-mouse-wheel/clean.bat
del main.exe del main.exe.obj del main.pdb
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-33-shapes-logo-raylib/clean.sh
rm ./main rm ./main.o
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-33-shapes-logo-raylib/main.zig
// build with `zig build-exe main.zig -lc -lraylib` // This is a Zig version of a raylib example from // https://github.com/raysan5/raylib/ // It is distributed under the same license as the original - unmodified zlib/libpng license // Header from the original source code follows below: ///******************************************************************************************* //* //* raylib [shapes] example - Draw raylib logo using basic shapes //* //* Example originally created with raylib 1.0, last time updated with raylib 1.0 //* //* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, //* BSD-like license that allows static linking with closed source software //* //* Copyright (c) 2014-2023 Ramon Santamaria (@raysan5) //* //********************************************************************************************/ const c = @cImport( { @cInclude("raylib.h"); }); pub fn main() void { const screen_width = 800; const screen_height = 450; c.InitWindow(screen_width, screen_height, "raylib [shapes] example - raylib logo using shapes"); defer c.CloseWindow(); // Close window and OpenGL context c.SetTargetFPS(60); // Set our game to run at 60 frames-per-second while (!c.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- //---------------------------------------------------------------------------------- // Draw //--------------------------------------------------------------------------------- c.BeginDrawing(); defer c.EndDrawing(); c.ClearBackground(c.RAYWHITE); c.DrawRectangle(screen_width/2 - 128, screen_height/2 - 128, 256, 256, c.BLACK); c.DrawRectangle(screen_width/2 - 112, screen_height/2 - 112, 224, 224, c.RAYWHITE); c.DrawText("raylib", screen_width/2 - 44, screen_height/2 + 48, 50, c.BLACK); c.DrawText("this is NOT a texture!", 350, 370, 10, c.GRAY); //--------------------------------------------------------------------------------- } }
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-33-shapes-logo-raylib/build.sh
#!/bin/sh tmp_raylib_include_path='' tmp_raylib_external_include_path='' tmp_raylib_lib_path='' tmp_raylib_zig_build_mode='' # No command line arguments => use local variables if [ $# -eq 0 ]; then echo echo 'Using locally defined build variables and paths' # Set the paths here if you invoke this build.sh manually tmp_raylib_path='~/ray' tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include" tmp_raylib_external_include_path="${tmp_raylib_path}/src/external" tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib" # One of: # -O Debug # -O ReleaseFast # -O ReleaseSafe # -O ReleaseSmall tmp_raylib_zig_build_mode='-O ReleaseSmall' else # Using variables set in ../build_example.sh tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH tmp_raylib_lib_path=$RAYLIB_LIB_PATH tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE fi tmp_raylib_include_arg='' if [ -n "$tmp_raylib_include_path" ]; then # Not empty tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}" fi if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}" fi #echo 'tmp_raylib_include_arg = ' #echo "$tmp_raylib_include_arg" tmp_raylib_lib_arg='' if [ -n "$tmp_raylib_lib_path" ]; then # Not empty tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib" else tmp_raylib_lib_arg='-lc -lraylib' fi #echo 'tmp_raylib_lib_arg = ' #echo "$tmp_raylib_lib_arg" echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}" zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-33-shapes-logo-raylib/build.bat
@echo off REM First parameter not set = build.bat launched manually if "%~1"=="" ( echo. echo Using locally defined build variables and paths setlocal enableDelayedExpansion REM These values are used if you invoke this build.bat file manualy. REM If you use build_example.bat in the root folder, values set in that file are used. SET RAYLIB_PATH=D:\libs\raylib-4.5.0 SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib REM One of: REM -O Debug REM -O ReleaseFast REM -O ReleaseSafe REM -O ReleaseSmall SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall ) REM echo RAYLIB_PATH: %RAYLIB_PATH% REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH% REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH% REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH% REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE% @echo on zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc @echo off REM End local variables scope if not called from the main script if "%~1"=="" ( endlocal & ( SET RAYLIB_PATH=%RAYLIB_PATH% SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH% SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH% SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH% SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE% ) )
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-33-shapes-logo-raylib/clean.bat
del main.exe del main.exe.obj del main.pdb
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-12-core-3d-camera-free/clean.sh
rm ./main rm ./main.o
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-12-core-3d-camera-free/main.zig
// build with `zig build-exe main.zig -lc -lraylib` // This is a Zig version of a raylib example from // https://github.com/raysan5/raylib/ // It is distributed under the same license as the original - unmodified zlib/libpng license // Header from the original source code follows below: ///******************************************************************************************* //* //* raylib [core] example - Initialize 3d camera free //* //* Example originally created with raylib 1.3, last time updated with raylib 1.3 //* //* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, //* BSD-like license that allows static linking with closed source software //* //* Copyright (c) 2015-2023 Ramon Santamaria (@raysan5) //* //********************************************************************************************/ const c = @cImport( { @cInclude("raylib.h"); }); pub fn main() void { const screenWidth = 800; const screenHeight = 450; c.InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); defer c.CloseWindow(); // Close window and OpenGL context // Define the camera to look into our 3d world var camera = c.Camera3D { .position = .{ .x = 10.0, .y = 10.0, .z = 10.0 }, // Camera position .target = .{ .x = 0.0, .y = 0.0, .z = 0.0 }, // Camera looking at point .up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera up vector (rotation towards target) .fovy = 45.0, // Camera field-of-view Y .projection = c.CAMERA_PERSPECTIVE // Camera mode type }; const cube_pos = c.Vector3{ .x = 0.0, .y = 0.0, .z = 0.0 }; c.DisableCursor(); // Limit cursor to relative movement inside the window c.SetTargetFPS(60); while (!c.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- c.UpdateCamera(&camera, c.CAMERA_FREE); if (c.IsKeyDown('Z')) camera.target = .{ .x = 0.0, .y = 0.0, .z = 0.0 }; //---------------------------------------------------------------------------------- // Draw //--------------------------------------------------------------------------------- c.BeginDrawing(); defer c.EndDrawing(); c.ClearBackground(c.RAYWHITE); { c.BeginMode3D(camera); defer c.EndMode3D(); c.DrawCube(cube_pos, 2.0, 2.0, 2.0, c.RED); c.DrawCubeWires(cube_pos, 2.0, 2.0, 2.0, c.MAROON); c.DrawGrid(10, 1.0); } c.DrawRectangle(10, 10, 320, 133, c.Fade(c.SKYBLUE, 0.5)); c.DrawRectangleLines(10, 10, 320, 133, c.BLUE); c.DrawText("Free camera default controls:", 20, 20, 10, c.BLACK); c.DrawText("- Mouse Wheel to Zoom in-out", 40, 40, 10, c.DARKGRAY); c.DrawText("- Mouse Wheel Pressed to Pan", 40, 60, 10, c.DARKGRAY); c.DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 80, 10, c.DARKGRAY); c.DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 100, 10, c.DARKGRAY); c.DrawText("- Z to zoom to (0, 0, 0)", 40, 120, 10, c.DARKGRAY); //--------------------------------------------------------------------------------- } }
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-12-core-3d-camera-free/build.sh
#!/bin/sh tmp_raylib_include_path='' tmp_raylib_external_include_path='' tmp_raylib_lib_path='' tmp_raylib_zig_build_mode='' # No command line arguments => use local variables if [ $# -eq 0 ]; then echo echo 'Using locally defined build variables and paths' # Set the paths here if you invoke this build.sh manually tmp_raylib_path='~/ray' tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include" tmp_raylib_external_include_path="${tmp_raylib_path}/src/external" tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib" # One of: # -O Debug # -O ReleaseFast # -O ReleaseSafe # -O ReleaseSmall tmp_raylib_zig_build_mode='-O ReleaseSmall' else # Using variables set in ../build_example.sh tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH tmp_raylib_lib_path=$RAYLIB_LIB_PATH tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE fi tmp_raylib_include_arg='' if [ -n "$tmp_raylib_include_path" ]; then # Not empty tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}" fi if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}" fi #echo 'tmp_raylib_include_arg = ' #echo "$tmp_raylib_include_arg" tmp_raylib_lib_arg='' if [ -n "$tmp_raylib_lib_path" ]; then # Not empty tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib" else tmp_raylib_lib_arg='-lc -lraylib' fi #echo 'tmp_raylib_lib_arg = ' #echo "$tmp_raylib_lib_arg" echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}" zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-12-core-3d-camera-free/build.bat
@echo off REM First parameter not set = build.bat launched manually if "%~1"=="" ( echo. echo Using locally defined build variables and paths setlocal enableDelayedExpansion REM These values are used if you invoke this build.bat file manualy. REM If you use build_example.bat in the root folder, values set in that file are used. SET RAYLIB_PATH=D:\libs\raylib-4.5.0 SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib REM One of: REM -O Debug REM -O ReleaseFast REM -O ReleaseSafe REM -O ReleaseSmall SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall ) REM echo RAYLIB_PATH: %RAYLIB_PATH% REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH% REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH% REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH% REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE% @echo on zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc @echo off REM End local variables scope if not called from the main script if "%~1"=="" ( endlocal & ( SET RAYLIB_PATH=%RAYLIB_PATH% SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH% SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH% SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH% SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE% ) )
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-12-core-3d-camera-free/clean.bat
del main.exe del main.exe.obj del main.pdb
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-54a-textures-texture-from-raw-data-(comptime-init)/clean.sh
rm ./main rm ./main.o
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-54a-textures-texture-from-raw-data-(comptime-init)/main.zig
// build with `zig build-exe main.zig -lc -lraylib` // This is a Zig version of a raylib example from // https://github.com/raysan5/raylib/ // It is distributed under the same license as the original - unmodified zlib/libpng license // Header from the original source code follows below: ///******************************************************************************************* //* //* raylib [textures] example - Load textures from raw data //* //* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) //* //* Example originally created with raylib 1.3, last time updated with raylib 3.5 //* //* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, //* BSD-like license that allows static linking with closed source software //* //* Copyright (c) 2015-2023 Ramon Santamaria (@raysan5) //* //********************************************************************************************/ // This version uses Zig comptime feature to generate the texture. // The texture is generated by the Zig compiler at compilation time (comptime), // and is embedded in the data section of the compiled binary. // Since the texture is 960 * 480 * 4 bytes = 1843200 bytes ~= 1.76 MB, // the resulting binary is quite large. // Compilation time also suffers because of this. // See version 54b for the version that generates the texture at runtime, like the original C example. const c = @cImport( { @cInclude("raylib.h"); }); pub fn main() void { const screen_width = 800; const screen_height = 450; c.InitWindow(screen_width, screen_height, "raylib [textures] example - texture from raw data"); defer c.CloseWindow(); // Close window and OpenGL context // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // Load RAW image data (512x512, 32bit RGBA, no file header). // Allocates required memory using malloc(). const fudesumi_raw = c.LoadImageRaw("resources/fudesumi.raw", 384, 512, c.PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 0); const fudesumi = c.LoadTextureFromImage(fudesumi_raw); // Upload CPU (RAM) image to GPU (VRAM) - Texture2D defer c.UnloadTexture(fudesumi); // Unload texture from GPU memory (VRAM) c.UnloadImage(fudesumi_raw); // Free the image.data using free() - see below for explanation if you need one // Generate a checked texture by code const width = 960; const height = 480; // Dynamic memory allocation to store pixels data (Color type). // We'll just use a buffer on the stack. //pub const struct_Color = extern struct { r: u8, g: u8, b: u8, a: u8, }; //pub const Color = struct_Color; //const pixels: [width * height * @sizeOf(c.Color)]u8 = comptime const pixels: [width * height]c.Color = comptime init_pixels: { var init_px: [width * height]c.Color = undefined; // error: evaluation exceeded 1000 backwards branches // note: use @setEvalBranchQuota() to raise the branch limit from 1000 @setEvalBranchQuota(width * (height + 1)); for (0..height) |y| { for (0..width) |x| { if (((x / 32 + y / 32) / 1) % 2 == 0) { init_px[y * width + x] = c.ORANGE; } else init_px[y * width + x] = c.GOLD; } } break :init_pixels init_px; }; // Load pixels data into an image structure and create texture const checked_im = c.Image { // Using @constCast to discard const qualifier // @ptrCast -> ?*anyopaque is not mandatory anymore .data = @constCast(&pixels), // We can assign pixels directly to data .width = width, .height = height, .format = c.PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, .mipmaps = 1 }; // NOTE: image is not unloaded, it must be done manually const checked = c.LoadTextureFromImage(checked_im); // Texture2D // The following call // --- c.UnloadImage(checked_im); // Unload CPU (RAM) image data (pixels) // does this - //void UnloadImage(Image image) //{ // RL_FREE(image.data); //} // RL_FREE is defined in raylib.h as //#ifndef RL_FREE // #define RL_FREE(ptr) free(ptr) //#endif // Translated to Zig as //pub inline fn RL_FREE(ptr: anytype) @TypeOf(free(ptr)) { // return free(ptr); //} // Which means we're not to call UnloadImage(), unless we use malloc() to allocate image pixels, // like in the original C code. //c.SetTargetFPS(60); - Don't need this since we really only display a static image while (!c.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- // TODO: Update your variables here //---------------------------------------------------------------------------------- // Draw //--------------------------------------------------------------------------------- { c.BeginDrawing(); defer c.EndDrawing(); c.ClearBackground(c.RAYWHITE); c.DrawTexture(checked, screen_width / 2 - @divTrunc(checked.width, 2), screen_height/2 - @divTrunc(checked.height, 2), c.Fade(c.WHITE, 0.5)); c.DrawTexture(fudesumi, 430, -30, c.WHITE); c.DrawText("CHECKED TEXTURE ", 84, 85, 30, c.BROWN); c.DrawText("GENERATED by CODE", 72, 148, 30, c.BROWN); c.DrawText("and RAW IMAGE LOADING", 46, 210, 30, c.BROWN); c.DrawText("(c) Fudesumi sprite by Eiden Marsal", 310, screen_height - 20, 10, c.BROWN); } //--------------------------------------------------------------------------------- } }
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-54a-textures-texture-from-raw-data-(comptime-init)/build.sh
#!/bin/sh tmp_raylib_include_path='' tmp_raylib_external_include_path='' tmp_raylib_lib_path='' tmp_raylib_zig_build_mode='' # No command line arguments => use local variables if [ $# -eq 0 ]; then echo echo 'Using locally defined build variables and paths' # Set the paths here if you invoke this build.sh manually tmp_raylib_path='~/ray' tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include" tmp_raylib_external_include_path="${tmp_raylib_path}/src/external" tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib" # One of: # -O Debug # -O ReleaseFast # -O ReleaseSafe # -O ReleaseSmall tmp_raylib_zig_build_mode='-O ReleaseSmall' else # Using variables set in ../build_example.sh tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH tmp_raylib_lib_path=$RAYLIB_LIB_PATH tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE fi tmp_raylib_include_arg='' if [ -n "$tmp_raylib_include_path" ]; then # Not empty tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}" fi if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}" fi #echo 'tmp_raylib_include_arg = ' #echo "$tmp_raylib_include_arg" tmp_raylib_lib_arg='' if [ -n "$tmp_raylib_lib_path" ]; then # Not empty tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib" else tmp_raylib_lib_arg='-lc -lraylib' fi #echo 'tmp_raylib_lib_arg = ' #echo "$tmp_raylib_lib_arg" echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}" zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-54a-textures-texture-from-raw-data-(comptime-init)/build.bat
@echo off REM First parameter not set = build.bat launched manually if "%~1"=="" ( echo. echo Using locally defined build variables and paths setlocal enableDelayedExpansion REM These values are used if you invoke this build.bat file manualy. REM If you use build_example.bat in the root folder, values set in that file are used. SET RAYLIB_PATH=D:\libs\raylib-4.5.0 SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib REM One of: REM -O Debug REM -O ReleaseFast REM -O ReleaseSafe REM -O ReleaseSmall SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall ) REM echo RAYLIB_PATH: %RAYLIB_PATH% REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH% REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH% REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH% REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE% @echo on zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc @echo off REM End local variables scope if not called from the main script if "%~1"=="" ( endlocal & ( SET RAYLIB_PATH=%RAYLIB_PATH% SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH% SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH% SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH% SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE% ) )
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-54a-textures-texture-from-raw-data-(comptime-init)/clean.bat
del main.exe del main.exe.obj del main.pdb
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-07-core-input-gestures/clean.sh
rm ./main rm ./main.o
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-07-core-input-gestures/main.zig
// build with `zig build-exe main.zig -lc -lraylib` // This is a Zig version of a raylib example from // https://github.com/raysan5/raylib/ // It is distributed under the same license as the original - unmodified zlib/libpng license // Header from the original source code follows below: ///******************************************************************************************* //* //* raylib [core] example - Input Gestures Detection //* //* Example originally created with raylib 1.4, last time updated with raylib 4.2 //* //* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, //* BSD-like license that allows static linking with closed source software //* //* Copyright (c) 2016-2023 Ramon Santamaria (@raysan5) //* //********************************************************************************************/ const c = @cImport( { @cInclude("raylib.h"); }); pub fn main() void { const screen_width = 800; const screen_height = 450; const max_gesture_strings = 20; c.InitWindow(screen_width, screen_height, "raylib [core] example - input gestures"); defer c.CloseWindow(); // Close window and OpenGL context var touch_pos = c.Vector2{ .x = 0.0, .y = 0.0 }; const touch_area = c.Rectangle{ .x = 220, .y = 10, .width = screen_width - 230, .height = screen_height - 20 }; var gestures_count: usize = 0; var gesture_strings: [max_gesture_strings][32]u8 = undefined; var current_gesture: c_int = c.GESTURE_NONE; var last_gesture: c_int = c.GESTURE_NONE; //c.SetGesturesEnabled(0b0000000000001001); // Enable only some gestures to be detected c.SetTargetFPS(60); while (!c.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- last_gesture = current_gesture; current_gesture = c.GetGestureDetected(); touch_pos = c.GetTouchPosition(0); if (c.CheckCollisionPointRec(touch_pos, touch_area) and (current_gesture != c.GESTURE_NONE)) { if (current_gesture != last_gesture) { switch (current_gesture) { c.GESTURE_TAP => _ = c.TextCopy(&gesture_strings[gestures_count], "GESTURE TAP"), c.GESTURE_DOUBLETAP => _ = c.TextCopy(&gesture_strings[gestures_count], "GESTURE DOUBLETAP"), c.GESTURE_HOLD => _ = c.TextCopy(&gesture_strings[gestures_count], "GESTURE HOLD"), c.GESTURE_DRAG => _ = c.TextCopy(&gesture_strings[gestures_count], "GESTURE DRAG"), c.GESTURE_SWIPE_RIGHT => _ = c.TextCopy(&gesture_strings[gestures_count], "GESTURE SWIPE RIGHT"), c.GESTURE_SWIPE_LEFT => _ = c.TextCopy(&gesture_strings[gestures_count], "GESTURE SWIPE LEFT"), c.GESTURE_SWIPE_UP => _ = c.TextCopy(&gesture_strings[gestures_count], "GESTURE SWIPE UP"), c.GESTURE_SWIPE_DOWN => _ = c.TextCopy(&gesture_strings[gestures_count], "GESTURE SWIPE DOWN"), c.GESTURE_PINCH_IN => _ = c.TextCopy(&gesture_strings[gestures_count], "GESTURE PINCH IN"), c.GESTURE_PINCH_OUT => _ = c.TextCopy(&gesture_strings[gestures_count], "GESTURE PINCH OUT"), else => {}, } gestures_count += 1; // Reset gestures strings if (gestures_count >= max_gesture_strings) { // -- !! captured values are immutable !! -- // -- see https://ziglearn.org/chapter-1/#unions -- //for (gesture_strings) |gesture_string| // _ = c.TextCopy(&gesture_string, "\x00"); for (0..gesture_strings.len) |i| _ = c.TextCopy(&gesture_strings[i], "\x00"); gestures_count = 0; } } } //---------------------------------------------------------------------------------- // Draw //--------------------------------------------------------------------------------- c.BeginDrawing(); defer c.EndDrawing(); c.ClearBackground(c.RAYWHITE); c.DrawRectangleRec(touch_area, c.GRAY); c.DrawRectangle(225, 15, screen_width - 240, screen_height - 30, c.RAYWHITE); c.DrawText("GESTURES TEST AREA", screen_width - 270, screen_height - 40, 20, c.Fade(c.GRAY, 0.5)); //for (0..gestures_count) |i| // -- i is usize, must be c_int in calls to c.DrawRectangle var i: c_int = 0; // -- we could use @intCast, but let's go with while loop while (i < gestures_count) : (i += 1) { if (i & 1 == 0) { c.DrawRectangle(10, 30 + 20*i, 200, 20, c.Fade(c.LIGHTGRAY, 0.5)); } else c.DrawRectangle(10, 30 + 20*i, 200, 20, c.Fade(c.LIGHTGRAY, 0.3)); if (i < gestures_count - 1) { c.DrawText(&gesture_strings[@intCast(i)], 35, 36 + 20*i, 10, c.DARKGRAY); } else c.DrawText(&gesture_strings[@intCast(i)], 35, 36 + 20*i, 10, c.MAROON); } c.DrawRectangleLines(10, 29, 200, screen_height - 50, c.GRAY); c.DrawText("DETECTED GESTURES", 50, 15, 10, c.GRAY); if (current_gesture != c.GESTURE_NONE) c.DrawCircleV(touch_pos, 30, c.MAROON); //--------------------------------------------------------------------------------- } }
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-07-core-input-gestures/build.sh
#!/bin/sh tmp_raylib_include_path='' tmp_raylib_external_include_path='' tmp_raylib_lib_path='' tmp_raylib_zig_build_mode='' # No command line arguments => use local variables if [ $# -eq 0 ]; then echo echo 'Using locally defined build variables and paths' # Set the paths here if you invoke this build.sh manually tmp_raylib_path='~/ray' tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include" tmp_raylib_external_include_path="${tmp_raylib_path}/src/external" tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib" # One of: # -O Debug # -O ReleaseFast # -O ReleaseSafe # -O ReleaseSmall tmp_raylib_zig_build_mode='-O ReleaseSmall' else # Using variables set in ../build_example.sh tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH tmp_raylib_lib_path=$RAYLIB_LIB_PATH tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE fi tmp_raylib_include_arg='' if [ -n "$tmp_raylib_include_path" ]; then # Not empty tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}" fi if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}" fi #echo 'tmp_raylib_include_arg = ' #echo "$tmp_raylib_include_arg" tmp_raylib_lib_arg='' if [ -n "$tmp_raylib_lib_path" ]; then # Not empty tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib" else tmp_raylib_lib_arg='-lc -lraylib' fi #echo 'tmp_raylib_lib_arg = ' #echo "$tmp_raylib_lib_arg" echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}" zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-07-core-input-gestures/build.bat
@echo off REM First parameter not set = build.bat launched manually if "%~1"=="" ( echo. echo Using locally defined build variables and paths setlocal enableDelayedExpansion REM These values are used if you invoke this build.bat file manualy. REM If you use build_example.bat in the root folder, values set in that file are used. SET RAYLIB_PATH=D:\libs\raylib-4.5.0 SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib REM One of: REM -O Debug REM -O ReleaseFast REM -O ReleaseSafe REM -O ReleaseSmall SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall ) REM echo RAYLIB_PATH: %RAYLIB_PATH% REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH% REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH% REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH% REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE% @echo on zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc @echo off REM End local variables scope if not called from the main script if "%~1"=="" ( endlocal & ( SET RAYLIB_PATH=%RAYLIB_PATH% SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH% SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH% SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH% SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE% ) )
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-07-core-input-gestures/clean.bat
del main.exe del main.exe.obj del main.pdb
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-87b-models-mesh-generation-(Zig-allocator)/clean.sh
rm ./main rm ./main.o
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-87b-models-mesh-generation-(Zig-allocator)/main.zig
// build with `zig build-exe main.zig -lc -lraylib` // This is a Zig version of a raylib example from // https://github.com/raysan5/raylib/ // It is distributed under the same license as the original - unmodified zlib/libpng license // Header from the original source code follows below: ///******************************************************************************************* //* //* raylib example - procedural mesh generation //* //* Example originally created with raylib 1.8, last time updated with raylib 4.0 //* //* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, //* BSD-like license that allows static linking with closed source software //* //* Copyright (c) 2017-2023 Ramon Santamaria (@raysan5) //* //********************************************************************************************/ // This version's GenMeshCustom() uses native Zig allocators to allocate RAM. // See version 87a for the version that uses raylib's MemAlloc(), which uses // RL_CALLOC(n,sz) macro, which is defined as calloc(n,sz). // See version 87a for the version that uses raylib's MemAlloc() for memory allocation. const std = @import("std"); const c = @cImport( { @cInclude("raylib.h"); @cInclude("rlgl.h"); // rlUnloadVertexArray() }); pub fn main() void { const screen_width = 800; const screen_height = 450; const num_models = 9; c.InitWindow(screen_width, screen_height, "raylib [models] example - mesh-generation"); defer c.CloseWindow(); // Close window and OpenGL context const checked = c.GenImageChecked(2, 2, 1, 1, c.RED, c.GREEN); // c.Image const texture = c.LoadTextureFromImage(checked); // c.Texture2D defer c.UnloadTexture(texture); // Unload texture c.UnloadImage(checked); // Allocator for GenMeshCustom(). // We can use one of the available allocators (uncomment one): // // 1. GeneralPurposeAllocator //var gpa = std.heap.GeneralPurposeAllocator(.{}){}; //const alloc8r = gpa.allocator(); //defer _ = gpa.deinit(); // // 2. C allocator. We can use it since we link libc with -lc for raylib anyway. const alloc8r = std.heap.c_allocator; var models = [num_models]c.Model // Can't be const, since we update their textures below { c.LoadModelFromMesh(c.GenMeshPlane(2, 2, 5, 5)), c.LoadModelFromMesh(c.GenMeshCube(2.0, 1.0, 2.0)), c.LoadModelFromMesh(c.GenMeshSphere(2, 32, 32)), c.LoadModelFromMesh(c.GenMeshHemiSphere(2, 16, 16)), c.LoadModelFromMesh(c.GenMeshCylinder(1, 2, 16)), c.LoadModelFromMesh(c.GenMeshTorus(0.25, 4.0, 16, 32)), c.LoadModelFromMesh(c.GenMeshKnot(1.0, 2.0, 16, 128)), c.LoadModelFromMesh(c.GenMeshPoly(5, 2.0)), c.LoadModelFromMesh(GenMeshCustom(alloc8r)) }; // Unload model data (from GPU VRAM) // Since we've allocated RAM for the last model's mesh using Zig allocators, // we must free it ourselves, so we skip it. // The only exception would be std.heap.c_allocator which works fine with raylib's RL_FREE macro, // since it uses C memory allocation. This means we could use UnloadModel if we used this allocator. defer for (0..num_models - 1) |i| c.UnloadModel(models[i]); // For the last, custom model / mesh, do what c.UnloadModel() does. // https://github.com/raysan5/raylib/blob/7d68aa686974347cefe0ef481c835e3d60bdc4b9/src/rmodels.c#L1123 defer { // Unload meshes for(0..@intCast(models[num_models - 1].meshCount)) |i| // @intCast -> usize { // For each mesh, do what c.UnloadMesh() does. // https://github.com/raysan5/raylib/blob/7d68aa686974347cefe0ef481c835e3d60bdc4b9/src/rmodels.c#L1755 c.rlUnloadVertexArray(models[num_models - 1].meshes[i].vaoId); // In src/config.h , but this file does not come with the raylib package: // #define MAX_MESH_VERTEX_BUFFERS 7 // Maximum vertex buffers (VBO) per mesh const max_mesh_vertex_buffers = 7; // So let's hardcode it here if (models[num_models - 1].meshes[i].vboId != null) for (0..max_mesh_vertex_buffers) |j| c.rlUnloadVertexBuffer(models[num_models - 1].meshes[i].vboId[j]); // Calls glBindVertexArray(), glDeleteVertexArrays() // vboId contains a pointer allocated in raylib's UploadMesh(), which is called at the end of // fn GenMeshCustom(), so we must use raylib's MemFree() on it. c.MemFree(models[num_models - 1].meshes[i].vboId); // MemFree() just wraps RL_FREE, which is #defined as free() // We only allocate vertices, texcoords and normals in fn GenMeshCustom() const vertex_count = 3; // Must provide slices to free(). alloc8r.free(models[num_models - 1].meshes[i].vertices[0..vertex_count * 3]); // x: f32, y: f32, z: f32 alloc8r.free(models[num_models - 1].meshes[i].texcoords[0..vertex_count * 2]); // u: f32, v: f32 alloc8r.free(models[num_models - 1].meshes[i].normals[0..vertex_count * 3]); // x: f32, y: f32, z: f32 // We never allocate these, so why free them? // Anyway, c.UnloadMesh() does, so let's do it just in case they are allocated somewehere in raylib functions. c.MemFree(models[num_models - 1].meshes[i].colors); c.MemFree(models[num_models - 1].meshes[i].tangents); c.MemFree(models[num_models - 1].meshes[i].texcoords2); c.MemFree(models[num_models - 1].meshes[i].indices); c.MemFree(models[num_models - 1].meshes[i].animVertices); c.MemFree(models[num_models - 1].meshes[i].animNormals); c.MemFree(models[num_models - 1].meshes[i].boneWeights); c.MemFree(models[num_models - 1].meshes[i].boneIds); } // Unload materials maps for (0..@intCast(models[num_models - 1].materialCount)) |i| // @intCast -> usize c.MemFree(models[num_models - 1].materials[i].maps); // Unload arrays c.MemFree(models[num_models - 1].meshes); c.MemFree(models[num_models - 1].materials); c.MemFree(models[num_models - 1].meshMaterial); // Unload animation data c.MemFree(models[num_models - 1].bones); c.MemFree(models[num_models - 1].bindPose); } // Generated meshes could be exported as .obj files //c.ExportMesh(models[0].meshes[0], "plane.obj"); //c.ExportMesh(models[1].meshes[0], "cube.obj"); //c.ExportMesh(models[2].meshes[0], "sphere.obj"); //c.ExportMesh(models[3].meshes[0], "hemisphere.obj"); //c.ExportMesh(models[4].meshes[0], "cylinder.obj"); //c.ExportMesh(models[5].meshes[0], "torus.obj"); //c.ExportMesh(models[6].meshes[0], "knot.obj"); //c.ExportMesh(models[7].meshes[0], "poly.obj"); //c.ExportMesh(models[8].meshes[0], "custom.obj"); // Set checked texture as default diffuse component for all models material for (0..num_models) |i| models[i].materials[0].maps[c.MATERIAL_MAP_DIFFUSE].texture = texture; // Define the camera to look into our 3d world var camera = c.Camera3D { .position = .{ .x = 5.0, .y = 5.0, .z = 5.0 }, // Camera position .target = .{ .x = 0.0, .y = 0.0, .z = 0.0 }, // Camera looking at point .up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera up vector (rotation towards target) .fovy = 45.0, // Camera field-of-view Y .projection = c.CAMERA_PERSPECTIVE // Camera mode type }; // Model drawing position const position = c.Vector3{ .x = 0.0, .y = 0.0, .z = 0.0 }; var current_model: usize = 0; c.SetTargetFPS(60); while (!c.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- c.UpdateCamera(&camera, c.CAMERA_ORBITAL); if (c.IsMouseButtonPressed(c.MOUSE_BUTTON_LEFT)) current_model = (current_model + 1) % num_models; // Cycle between the models if (c.IsKeyPressed(c.KEY_RIGHT)) { current_model += 1; if (current_model >= num_models) current_model = 0; } else if (c.IsKeyPressed(c.KEY_LEFT)) { if (current_model <= 1) { current_model = num_models - 1; } else current_model -= 1; } //---------------------------------------------------------------------------------- // Draw //--------------------------------------------------------------------------------- c.BeginDrawing(); defer c.EndDrawing(); c.ClearBackground(c.RAYWHITE); { c.BeginMode3D(camera); defer c.EndMode3D(); c.DrawModel(models[current_model], position, 1.0, c.WHITE); c.DrawGrid(10, 1.0); } c.DrawRectangle(30, 400, 310, 30, c.Fade(c.SKYBLUE, 0.5)); c.DrawRectangleLines(30, 400, 310, 30, c.Fade(c.DARKBLUE, 0.5)); c.DrawText("MOUSE LEFT BUTTON to CYCLE PROCEDURAL MODELS", 40, 410, 10, c.BLUE); switch (current_model) { 0 => c.DrawText("PLANE", 680, 10, 20, c.DARKBLUE), 1 => c.DrawText("CUBE", 680, 10, 20, c.DARKBLUE), 2 => c.DrawText("SPHERE", 680, 10, 20, c.DARKBLUE), 3 => c.DrawText("HEMISPHERE", 640, 10, 20, c.DARKBLUE), 4 => c.DrawText("CYLINDER", 680, 10, 20, c.DARKBLUE), 5 => c.DrawText("TORUS", 680, 10, 20, c.DARKBLUE), 6 => c.DrawText("KNOT", 680, 10, 20, c.DARKBLUE), 7 => c.DrawText("POLY", 680, 10, 20, c.DARKBLUE), 8 => c.DrawText("Custom (triangle)", 580, 10, 20, c.DARKBLUE), else => {} } //--------------------------------------------------------------------------------- } } // Generate a simple triangle mesh from code // using a Zig Allocator provided by the caller. // This function panics if there's an allocation error, // e.g. not enough memory. This is OK in this small demo program, // but most probably a bad idea in your production code. // // All the allocated RAM is freed in deferred calls to raylib's UnloadModel() in the main // function ( https://github.com/raysan5/raylib/blob/7d68aa686974347cefe0ef481c835e3d60bdc4b9/src/rmodels.c#L1123 ) // UnloadModel() calls UnloadMesh() in a loop for all the meshes of the model, then uses raylib's RL_FREE macro // to free the materials in a similar fashion. Then it uses RL_FREE to free the array of mesh pointers, the array // of material pointers, etc. // // This means that you we only use std.heap.c_allocator if we use UnloadModel(). // Alternatively, we could use allocator.free() to free .vertices, .texcoords and .normals // in the custom mesh generated by GenMeshCustom() fn GenMeshCustom(alloc8r: std.mem.Allocator) c.Mesh { const vertex_count = 3; var mesh = c.Mesh { .vertexCount = vertex_count, .triangleCount = 1, // 3 vertices, 3 coordinates each (x, y, z) .vertices = @ptrCast(alloc8r.alloc(f32, vertex_count * 3) catch |err| // @ptrCast -> [*c]f32 { std.debug.print("Memory allocation error: {}\n", .{err}); @panic("Memory allocation error"); }), // 3 vertices, 2 coordinates each (x, y) .texcoords = @ptrCast(alloc8r.alloc(f32, vertex_count * 2) catch |err| // @ptrCast -> [*c]f32 { std.debug.print("Memory allocation error: {}\n", .{err}); @panic("Memory allocation error"); }), .texcoords2 = null, // 3 vertices, 3 coordinates each (x, y, z) .normals = @ptrCast(alloc8r.alloc(f32, vertex_count * 3) catch |err| // @ptrCast -> [*c]f32 { std.debug.print("Memory allocation error: {}\n", .{err}); @panic("Memory allocation error"); }), .tangents = null, .colors = null, .indices = null, .animVertices = null, .animNormals = null, .boneIds = null, .boneWeights = null, .vaoId = 0, // c.UploadMesh() below uses RL_CALLOC() macro to allocate MAX_MESH_VERTEX_BUFFERS (7) of unsigned ints, // and saves the pointer to them in .vboId .vboId = null }; // The allocated memory is freed in the defer block in the main function. // Vertex at (0, 0, 0) mesh.vertices[0] = 0.0; mesh.vertices[1] = 0.0; mesh.vertices[2] = 0.0; mesh.normals[0] = 0.0; mesh.normals[1] = 1.0; mesh.normals[2] = 0.0; mesh.texcoords[0] = 0.0; mesh.texcoords[1] = 0.0; // Vertex at (1, 0, 2) mesh.vertices[3] = 1.0; mesh.vertices[4] = 0.0; mesh.vertices[5] = 2.0; mesh.normals[3] = 0.0; mesh.normals[4] = 1.0; mesh.normals[5] = 0.0; mesh.texcoords[2] = 0.5; mesh.texcoords[3] = 1.0; // Vertex at (2, 0, 0) mesh.vertices[6] = 2.0; mesh.vertices[7] = 0.0; mesh.vertices[8] = 0.0; mesh.normals[6] = 0.0; mesh.normals[7] = 1.0; mesh.normals[8] = 0.0; mesh.texcoords[4] = 1.0; mesh.texcoords[5] = 0.0; // Upload mesh data from CPU (RAM) to GPU (VRAM) memory c.UploadMesh(&mesh, false); return mesh; }
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-87b-models-mesh-generation-(Zig-allocator)/build.sh
#!/bin/sh tmp_raylib_include_path='' tmp_raylib_external_include_path='' tmp_raylib_lib_path='' tmp_raylib_zig_build_mode='' # No command line arguments => use local variables if [ $# -eq 0 ]; then echo echo 'Using locally defined build variables and paths' # Set the paths here if you invoke this build.sh manually tmp_raylib_path='~/ray' tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include" tmp_raylib_external_include_path="${tmp_raylib_path}/src/external" tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib" # One of: # -O Debug # -O ReleaseFast # -O ReleaseSafe # -O ReleaseSmall tmp_raylib_zig_build_mode='-O ReleaseSmall' else # Using variables set in ../build_example.sh tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH tmp_raylib_lib_path=$RAYLIB_LIB_PATH tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE fi tmp_raylib_include_arg='' if [ -n "$tmp_raylib_include_path" ]; then # Not empty tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}" fi if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}" fi #echo 'tmp_raylib_include_arg = ' #echo "$tmp_raylib_include_arg" tmp_raylib_lib_arg='' if [ -n "$tmp_raylib_lib_path" ]; then # Not empty tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib" else tmp_raylib_lib_arg='-lc -lraylib' fi #echo 'tmp_raylib_lib_arg = ' #echo "$tmp_raylib_lib_arg" echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}" zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-87b-models-mesh-generation-(Zig-allocator)/build.bat
@echo off REM First parameter not set = build.bat launched manually if "%~1"=="" ( echo. echo Using locally defined build variables and paths setlocal enableDelayedExpansion REM These values are used if you invoke this build.bat file manualy. REM If you use build_example.bat in the root folder, values set in that file are used. SET RAYLIB_PATH=D:\libs\raylib-4.5.0 SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib REM One of: REM -O Debug REM -O ReleaseFast REM -O ReleaseSafe REM -O ReleaseSmall SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall ) REM echo RAYLIB_PATH: %RAYLIB_PATH% REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH% REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH% REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH% REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE% @echo on zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc @echo off REM End local variables scope if not called from the main script if "%~1"=="" ( endlocal & ( SET RAYLIB_PATH=%RAYLIB_PATH% SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH% SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH% SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH% SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE% ) )
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-87b-models-mesh-generation-(Zig-allocator)/clean.bat
del main.exe del main.exe.obj del main.pdb
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-13-core-3d-camera-first-person/clean.sh
rm ./main rm ./main.o
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-13-core-3d-camera-first-person/main.zig
// build with `zig build-exe main.zig -lc -lraylib` // This is a Zig version of a raylib example from // https://github.com/raysan5/raylib/ // It is distributed under the same license as the original - unmodified zlib/libpng license // Header from the original source code follows below: ///******************************************************************************************* //* //* raylib [core] example - 3d camera first person //* //* Example originally created with raylib 1.3, last time updated with raylib 1.3 //* //* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, //* BSD-like license that allows static linking with closed source software //* //* Copyright (c) 2015-2023 Ramon Santamaria (@raysan5) //* //********************************************************************************************/ const c = @cImport( { @cInclude("raylib.h"); @cInclude("rcamera.h"); }); const std = @import("std"); pub fn main() void { const screenWidth = 800; const screenHeight = 450; const max_columns = 20; c.InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person"); defer c.CloseWindow(); // Close window and OpenGL context // Define the camera to look into our 3d world var camera = c.Camera3D { .position = .{ .x = 0.0, .y = 2.0, .z = 4.0 }, // Camera position .target = .{ .x = 0.0, .y = 2.0, .z = 0.0 }, // Camera looking at point .up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }, // Camera up vector (rotation towards target) .fovy = 60.0, // Camera field-of-view Y .projection = c.CAMERA_PERSPECTIVE // Camera mode type }; var camera_mode = c.CAMERA_FIRST_PERSON; // Generates some random columns var heights = [_]f32{ 0.0 } ** max_columns; var positions = [_]c.Vector3{ .{.x = 0.0, .y = 0.0, .z = 0.0} } ** max_columns; var colors = [_]c.Color{ .{.r = 0, .g = 0, .b = 0, .a = 0} } ** max_columns; //var i: usize = 0; //while (i < max_columns) : (i += 1) for (0..max_columns) |i| { heights[i] = @floatFromInt(c.GetRandomValue(1, 12)); positions[i] = .{ .x = @floatFromInt(c.GetRandomValue(-15, 15)), .y = heights[i]/2.0, .z = @floatFromInt(c.GetRandomValue(-15, 15)) }; colors[i] = .{ .r = @intCast(c.GetRandomValue(20, 255)), .g = @intCast(c.GetRandomValue(10, 55)), .b = 30, .a = 255 }; // u8 } c.DisableCursor(); // Limit cursor to relative movement inside the window c.SetTargetFPS(60); // Set our game to run at 60 frames-per-second while (!c.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- // Switch camera mode if (c.IsKeyPressed(c.KEY_ONE)) { camera_mode = c.CAMERA_FREE; camera.up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }; // Reset roll } if (c.IsKeyPressed(c.KEY_TWO)) { camera_mode = c.CAMERA_FIRST_PERSON; camera.up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }; // Reset roll } if (c.IsKeyPressed(c.KEY_THREE)) { camera_mode = c.CAMERA_THIRD_PERSON; camera.up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }; // Reset roll } if (c.IsKeyPressed(c.KEY_FOUR)) { camera_mode = c.CAMERA_ORBITAL; camera.up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }; // Reset roll } // Switch camera projection if (c.IsKeyPressed(c.KEY_P)) { if (camera.projection == c.CAMERA_PERSPECTIVE) { // Create isometric view camera_mode = c.CAMERA_THIRD_PERSON; // Note: The target distance is related to the render distance in the orthographic projection camera.position = .{ .x = 0.0, .y = 2.0, .z = -100.0 }; camera.target = .{ .x = 0.0, .y = 2.0, .z = 0.0 }; camera.up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }; camera.projection = c.CAMERA_ORTHOGRAPHIC; camera.fovy = 20.0; // near plane width in CAMERA_ORTHOGRAPHIC c.CameraYaw(&camera, -135.0 * c.DEG2RAD, true); c.CameraPitch(&camera, -45.0 * c.DEG2RAD, true, true, false); } else if (camera.projection == c.CAMERA_ORTHOGRAPHIC) { // Reset to default view camera_mode = c.CAMERA_THIRD_PERSON; camera.position = .{ .x = 0.0, .y = 2.0, .z = 10.0 }; camera.target = .{ .x = 0.0, .y = 2.0, .z = 0.0 }; camera.up = .{ .x = 0.0, .y = 1.0, .z = 0.0 }; camera.projection = c.CAMERA_PERSPECTIVE; camera.fovy = 60.0; } } // Update camera computes movement internally depending on the camera mode // Some default standard keyboard/mouse inputs are hardcoded to simplify use // For advance camera controls, it's reecommended to compute camera movement manually c.UpdateCamera(&camera, camera_mode); // Update camera // -- I have not ported this section to Zig, the code commented out below is in original C -- // Camera PRO usage example (EXPERIMENTAL) // This new camera function allows custom movement/rotation values to be directly provided // as input parameters, with this approach, rcamera module is internally independent of raylib inputs //UpdateCameraPro(&camera, // (Vector3){ // (IsKeyDown(KEY_W) || IsKeyDown(KEY_UP))*0.1f - // Move forward-backward // (IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN))*0.1f, // (IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT))*0.1f - // Move right-left // (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT))*0.1f, // 0.0f // Move up-down // }, // (Vector3){ // GetMouseDelta().x*0.05f, // Rotation: yaw // GetMouseDelta().y*0.05f, // Rotation: pitch // 0.0f // Rotation: roll // }, // GetMouseWheelMove()*2.0f); // Move to target (zoom) //---------------------------------------------------------------------------------- // Draw //--------------------------------------------------------------------------------- c.BeginDrawing(); defer c.EndDrawing(); c.ClearBackground(c.RAYWHITE); { c.BeginMode3D(camera); defer c.EndMode3D(); c.DrawPlane(.{ .x = 0.0, .y = 0.0, .z = 0.0 }, .{ .x = 32.0, .y = 32.0 }, c.LIGHTGRAY); // Draw ground c.DrawCube(.{ .x = -16.0, .y = 2.5, .z = 0.0 }, 1.0, 5.0, 32.0, c.BLUE); // Draw a blue wall c.DrawCube(.{ .x = 16.0, .y = 2.5, .z = 0.0 }, 1.0, 5.0, 32.0, c.LIME); // Draw a green wall c.DrawCube(.{ .x = 0.0, .y = 2.5, .z = 16.0 }, 32.0, 5.0, 1.0, c.GOLD); // Draw a yellow wall // Draw some cubes around for (0..max_columns) |i| { c.DrawCube(positions[i], 2.0, heights[i], 2.0, colors[i]); c.DrawCubeWires(positions[i], 2.0, heights[i], 2.0, c.MAROON); } // Draw player cube if (camera_mode == c.CAMERA_THIRD_PERSON) { c.DrawCube(camera.target, 0.5, 0.5, 0.5, c.PURPLE); c.DrawCubeWires(camera.target, 0.5, 0.5, 0.5, c.DARKPURPLE); } } // Draw info boxes c.DrawRectangle(5, 5, 330, 100, c.Fade(c.SKYBLUE, 0.5)); c.DrawRectangleLines(5, 5, 330, 100, c.BLUE); c.DrawText("Camera controls:", 15, 15, 10, c.BLACK); c.DrawText("- Move keys: W, A, S, D, Space, Left-Ctrl", 15, 30, 10, c.BLACK); c.DrawText("- Look around: arrow keys or mouse", 15, 45, 10, c.BLACK); c.DrawText("- Camera mode keys: 1, 2, 3, 4", 15, 60, 10, c.BLACK); c.DrawText("- Zoom keys: num-plus, num-minus or mouse scroll", 15, 75, 10, c.BLACK); c.DrawText("- Camera projection key: P", 15, 90, 10, c.BLACK); c.DrawRectangle(600, 5, 195, 100, c.Fade(c.SKYBLUE, 0.5)); c.DrawRectangleLines(600, 5, 195, 100, c.BLUE); c.DrawText("Camera status:", 610, 15, 10, c.BLACK); // @ptrCast -> [*c]const u8: https://github.com/ziglang/zig/issues/16234 // -- This code causes Zig compiler (0.11.0-dev.3859+88284c124) to segfault, see // -- https://github.com/ziglang/zig/issues/16197 //c.DrawText(c.TextFormat("- Mode: %s", @ptrCast(if (camera_mode == c.CAMERA_FREE) "FREE" else // if (camera_mode == c.CAMERA_FIRST_PERSON) "FIRST_PERSON" else // if (camera_mode == c.CAMERA_THIRD_PERSON) "THIRD_PERSON" else // if (camera_mode == c.CAMERA_ORBITAL) "ORBITAL" else "CUSTOM")), // 610, 30, 10, c.BLACK); const text_cam_mode = if (camera_mode == c.CAMERA_FREE) "- Mode: FREE" else if (camera_mode == c.CAMERA_FIRST_PERSON) "- Mode: FIRST_PERSON" else if (camera_mode == c.CAMERA_THIRD_PERSON) "- Mode: THIRD_PERSON" else if (camera_mode == c.CAMERA_ORBITAL) "- Mode: ORBITAL" else "- Mode: CUSTOM"; c.DrawText(text_cam_mode, 610, 30, 10, c.BLACK); // @ptrCast -> [*c]const u8: https://github.com/ziglang/zig/issues/16234 // -- This code causes Zig compiler (0.11.0-dev.3859+88284c124) to segfault, see // -- https://github.com/ziglang/zig/issues/16197 //c.DrawText(c.TextFormat("- Projection: %s", if (camera.projection == c.CAMERA_PERSPECTIVE) "PERSPECTIVE" else // if (camera.projection == c.CAMERA_ORTHOGRAPHIC) "ORTHOGRAPHIC" else "CUSTOM"), // 610, 45, 10, c.BLACK); const text_proj = if (camera.projection == c.CAMERA_PERSPECTIVE) "- Projection: PERSPECTIVE" else if (camera.projection == c.CAMERA_ORTHOGRAPHIC) "- Projection: ORTHOGRAPHIC" else "- Projection: CUSTOM"; c.DrawText(text_proj, 610, 45, 10, c.BLACK); c.DrawText(c.TextFormat("- Position: (%06.3f, %06.3f, %06.3f)", camera.position.x, camera.position.y, camera.position.z), 610, 60, 10, c.BLACK); c.DrawText(c.TextFormat("- Target: (%06.3f, %06.3f, %06.3f)", camera.target.x, camera.target.y, camera.target.z), 610, 75, 10, c.BLACK); c.DrawText(c.TextFormat("- Up: (%06.3f, %06.3f, %06.3f)", camera.up.x, camera.up.y, camera.up.z), 610, 90, 10, c.BLACK); //--------------------------------------------------------------------------------- } }
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-13-core-3d-camera-first-person/build.sh
#!/bin/sh tmp_raylib_include_path='' tmp_raylib_external_include_path='' tmp_raylib_lib_path='' tmp_raylib_zig_build_mode='' # No command line arguments => use local variables if [ $# -eq 0 ]; then echo echo 'Using locally defined build variables and paths' # Set the paths here if you invoke this build.sh manually tmp_raylib_path='~/ray' tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include" tmp_raylib_external_include_path="${tmp_raylib_path}/src/external" tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib" # One of: # -O Debug # -O ReleaseFast # -O ReleaseSafe # -O ReleaseSmall tmp_raylib_zig_build_mode='-O ReleaseSmall' else # Using variables set in ../build_example.sh tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH tmp_raylib_lib_path=$RAYLIB_LIB_PATH tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE fi tmp_raylib_include_arg='' if [ -n "$tmp_raylib_include_path" ]; then # Not empty tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}" fi if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}" fi #echo 'tmp_raylib_include_arg = ' #echo "$tmp_raylib_include_arg" tmp_raylib_lib_arg='' if [ -n "$tmp_raylib_lib_path" ]; then # Not empty tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib" else tmp_raylib_lib_arg='-lc -lraylib' fi #echo 'tmp_raylib_lib_arg = ' #echo "$tmp_raylib_lib_arg" echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}" zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-13-core-3d-camera-first-person/build.bat
@echo off REM First parameter not set = build.bat launched manually if "%~1"=="" ( echo. echo Using locally defined build variables and paths setlocal enableDelayedExpansion REM These values are used if you invoke this build.bat file manualy. REM If you use build_example.bat in the root folder, values set in that file are used. SET RAYLIB_PATH=D:\libs\raylib-4.5.0 SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib REM One of: REM -O Debug REM -O ReleaseFast REM -O ReleaseSafe REM -O ReleaseSmall SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall ) REM echo RAYLIB_PATH: %RAYLIB_PATH% REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH% REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH% REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH% REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE% @echo on zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc @echo off REM End local variables scope if not called from the main script if "%~1"=="" ( endlocal & ( SET RAYLIB_PATH=%RAYLIB_PATH% SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH% SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH% SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH% SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE% ) )
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-13-core-3d-camera-first-person/clean.bat
del main.exe del main.exe.obj del main.pdb
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-74-text-format-text/clean.sh
rm ./main rm ./main.o
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-74-text-format-text/main.zig
// build with `zig build-exe main.zig -lc -lraylib` // This is a Zig version of a raylib example from // https://github.com/raysan5/raylib/ // It is distributed under the same license as the original - unmodified zlib/libpng license // Header from the original source code follows below: ///******************************************************************************************* //* //* raylib [text] example - Text formatting //* //* Example originally created with raylib 1.1, last time updated with raylib 3.0 //* //* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, //* BSD-like license that allows static linking with closed source software //* //* Copyright (c) 2014-2023 Ramon Santamaria (@raysan5) //* //********************************************************************************************/ const c = @cImport( { @cInclude("raylib.h"); }); pub fn main() void { const screen_width = 800; const screen_height = 450; c.InitWindow(screen_width, screen_height, "raylib [text] example - text formatting"); defer c.CloseWindow(); // Close window and OpenGL context const score = 100020; const hiscore = 200450; const lives = 5; c.SetTargetFPS(60); while (!c.WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- //---------------------------------------------------------------------------------- // Draw //--------------------------------------------------------------------------------- c.BeginDrawing(); defer c.EndDrawing(); c.ClearBackground(c.RAYWHITE); // error: integer and float literals passed variadic function must be casted to a fixed-size number type c.DrawText(c.TextFormat("Score: %08i", @as(c_int, score)), 200, 80, 20, c.RED); c.DrawText(c.TextFormat("HiScore: %08i", @as(c_int, hiscore)), 200, 120, 20, c.GREEN); c.DrawText(c.TextFormat("Lives: %02i", @as(c_int, lives)), 200, 160, 40, c.BLUE); c.DrawText(c.TextFormat("Elapsed Time: %02.02f ms", c.GetFrameTime()*1000), 200, 220, 20, c.BLACK); //--------------------------------------------------------------------------------- } }
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-74-text-format-text/build.sh
#!/bin/sh tmp_raylib_include_path='' tmp_raylib_external_include_path='' tmp_raylib_lib_path='' tmp_raylib_zig_build_mode='' # No command line arguments => use local variables if [ $# -eq 0 ]; then echo echo 'Using locally defined build variables and paths' # Set the paths here if you invoke this build.sh manually tmp_raylib_path='~/ray' tmp_raylib_include_path="${tmp_raylib_path}/zig-out/include" tmp_raylib_external_include_path="${tmp_raylib_path}/src/external" tmp_raylib_lib_path="${tmp_raylib_path}/zig-out/lib" # One of: # -O Debug # -O ReleaseFast # -O ReleaseSafe # -O ReleaseSmall tmp_raylib_zig_build_mode='-O ReleaseSmall' else # Using variables set in ../build_example.sh tmp_raylib_include_path=$RAYLIB_INCLUDE_PATH tmp_raylib_external_include_path=$RAYLIB_EXTERNAL_INCLUDE_PATH tmp_raylib_lib_path=$RAYLIB_LIB_PATH tmp_raylib_zig_build_mode=$RAYLIB_ZIG_BUILD_MODE fi tmp_raylib_include_arg='' if [ -n "$tmp_raylib_include_path" ]; then # Not empty tmp_raylib_include_arg="-idirafter ${tmp_raylib_include_path}" fi if [ -n "$tmp_raylib_external_include_path" ]; then # Not empty tmp_raylib_include_arg="${tmp_raylib_include_arg} -idirafter ${tmp_raylib_external_include_path}" fi #echo 'tmp_raylib_include_arg = ' #echo "$tmp_raylib_include_arg" tmp_raylib_lib_arg='' if [ -n "$tmp_raylib_lib_path" ]; then # Not empty tmp_raylib_lib_arg="-L${tmp_raylib_lib_path} -lc -lraylib" else tmp_raylib_lib_arg='-lc -lraylib' fi #echo 'tmp_raylib_lib_arg = ' #echo "$tmp_raylib_lib_arg" echo "zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}" zig build-exe main.zig ${tmp_raylib_zig_build_mode} ${tmp_raylib_include_arg} -idirafter ./ ${tmp_raylib_lib_arg}
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-74-text-format-text/build.bat
@echo off REM First parameter not set = build.bat launched manually if "%~1"=="" ( echo. echo Using locally defined build variables and paths setlocal enableDelayedExpansion REM These values are used if you invoke this build.bat file manualy. REM If you use build_example.bat in the root folder, values set in that file are used. SET RAYLIB_PATH=D:\libs\raylib-4.5.0 SET RAYLIB_INCLUDE_PATH=!RAYLIB_PATH!\zig-out\include SET RAYLIB_EXTERNAL_INCLUDE_PATH=!RAYLIB_PATH!\src\external SET RAYLIB_LIB_PATH=!RAYLIB_PATH!\zig-out\lib REM One of: REM -O Debug REM -O ReleaseFast REM -O ReleaseSafe REM -O ReleaseSmall SET RAYLIB_ZIG_BUILD_MODE=-O ReleaseSmall ) REM echo RAYLIB_PATH: %RAYLIB_PATH% REM echo RAYLIB_INCLUDE_PATH: %RAYLIB_INCLUDE_PATH% REM echo RAYLIB_EXTERNAL_INCLUDE_PATH: %RAYLIB_EXTERNAL_INCLUDE_PATH% REM echo RAYLIB_LIB_PATH: %RAYLIB_LIB_PATH% REM echo RAYLIB_ZIG_BUILD_MODE: %RAYLIB_ZIG_BUILD_MODE% @echo on zig build-exe main.zig %RAYLIB_ZIG_BUILD_MODE% -idirafter .\ -idirafter %RAYLIB_INCLUDE_PATH% -idirafter %RAYLIB_EXTERNAL_INCLUDE_PATH% -L%RAYLIB_LIB_PATH% -lraylib -lopengl32 -lgdi32 -lwinmm -lc @echo off REM End local variables scope if not called from the main script if "%~1"=="" ( endlocal & ( SET RAYLIB_PATH=%RAYLIB_PATH% SET RAYLIB_INCLUDE_PATH=%RAYLIB_INCLUDE_PATH% SET RAYLIB_EXTERNAL_INCLUDE_PATH=%RAYLIB_EXTERNAL_INCLUDE_PATH% SET RAYLIB_LIB_PATH=%RAYLIB_LIB_PATH% SET RAYLIB_ZIG_BUILD_MODE=%RAYLIB_ZIG_BUILD_MODE% ) )
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-74-text-format-text/clean.bat
del main.exe del main.exe.obj del main.pdb
0
repos/raylib-zig-examples
repos/raylib-zig-examples/zig-raylib-38-shapes-following-eyes/clean.sh
rm ./main rm ./main.o