Questions tagged [zig]

Zig is an open-source programming language designed for robustness, optimality, and clarity.

Zig is a general-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.

Website:

Documentation:

Zig has many features for low-level programming, notably: packed structs (structs without padding between fields), arbitrary width integers and multiple pointer types. Zig has no hidden control flow, no hidden memory alocation, no macros (but therefor compile time code execution)

212 questions
0
votes
0 answers

How do you set a breakpoint in build.zig?

More specifically, how do you successfully hit a breakpoint set in the build.zig file in order to debug the build process. I'm working in vscode, and it would be awesome if I could create a special configuration in launch.json that achieved this.
ragnar
  • 480
  • 3
  • 18
0
votes
1 answer

Got error during orelse 2 "var optinal integer"

I'm a fresh new in Zig who test a few codes with "orelse". I tried to create 2 optional unsigned integer variables as following code and use orelse with them. const std = @import("std"); pub fn main() !void { var value1: ?u32 = 123; var…
Le Dong Thuc
  • 195
  • 1
  • 6
0
votes
1 answer

Why does my tree creation fail without the use of inline?

I'm trying to create a Trie structure in Zig using Zigs StringHashMap. I am able to get it to work a bit, but only by using a "inline" for loop which is not really usable as this requires the paths to be known at compile time :-( Any…
seriousme
  • 11
  • 2
0
votes
2 answers

Cross compile cython with zig cc

Is there a way to cross compile cython project with zig cc. According to this blog zig can cross compile. An example which cross compiles cython hello world would be great.
Levon
  • 10,408
  • 4
  • 47
  • 42
0
votes
1 answer

How to include readline into a Zig project

I am trying to use readline in my Zig project. I managed to make the linker find it by adding this to the build file: exe.linkLibC(); exe.addIncludeDir("/usr/local/opt/readline/include"); …
Renato
  • 12,940
  • 3
  • 54
  • 85
0
votes
1 answer

How can I make a typed index in Zig

I have an algorithm that has two arrays with their respective indices. Only, it would be very easy to mix both indices and access one of the arrays with the wrong index. For example: var array1 = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var index1 =…
aganm
  • 1,245
  • 1
  • 11
  • 30
0
votes
1 answer

Can I pass commandline arguments when invoking "zig build run"?

I'm just starting with the new programming language Zig and finding documentation pretty sparse. I can build and run the current project by invoking zig build run. I can also do zig run src/main.zig assuming standard project layout. But in neither…
hippietrail
  • 15,848
  • 18
  • 99
  • 158
0
votes
2 answers

Further slicing of an existing slice always results in the same data, regardless of slice position

I'm new to Zig (using 0.9.1 stable) and have had some trouble effectively slicing an array at compile time. const some_file = @embedFile("filepath.bin"); const data_section = some_file[0x1000..0x2000]; // This has the correct data const data1 =…
0
votes
1 answer

Does Zig support the union of anonymous structs and arrays?

Is this possible in zig? And if so how would something like the following C++ code look in Zig? template class vec3 { union { struct{ T x,y,z; }; T vec_array[3]; }; };
ragnar
  • 480
  • 3
  • 18
0
votes
1 answer

Zig error: Array access of non-array type

I need some help on creating an array as a struct field in Zig. const VarStr = struct { buffer: [1000]u8, len: u8, pub fn init(str: []const u8) VarStr { var filled: u8 = 0; for (str) |char, ind| { .buffer[ind]…
0
votes
1 answer

Creating a json write stream doesn't compile

I am trying to use JSON in zig and I don't understand why this doesn't compile: const file = std.fs.cwd().createFile("Hello", .{.read = true}) catch unreachable; const stream = std.json.writeStream(std.fs.File.Writer, 5000000); _ = stream; The…
taste01
  • 35
  • 1
  • 6
0
votes
1 answer

Can you retry a Zig function call when it returns an error?

Zig's documentation shows different methods of error handling including bubbling the error value up the call stack, catching the error and using a default value, panicking, etc. I'm trying to figure out how to retry functions which provide error…
0
votes
1 answer

error: expected type 'type' -- while trying to return error from an error set

I'm new to Zig and am trying to learn how error-handling and error sets work. If I run const erro = error{Oops}; fn failingFunction() erro.Oops!void { return erro.Oops; } test "returning an error" { failingFunction() catch |err| { …
0
votes
1 answer

Idiomatic way to wite/pass type to generic function in ziglang

This is a much simplified version of my real issue but hopefully demonstrates my question in a concise manner. My question is about the interface to printKeys. I have to pass in the type of the data to be printed as a comptime parameter, and the…
jcoder
  • 29,554
  • 19
  • 87
  • 130
0
votes
1 answer

Why does this zig program fail to compile due to "expected error union type, found 'error:124:18'"?

test "error union if" { var ent_num: error{UnknownEntity}!u32 = error.UnknownEntity; if (ent_num) |entity| { try expect(@TypeOf(entity) == u32); try expect(entity == 5); } else |err| { _ = err catch |err1| { //…
Helin Wang
  • 4,002
  • 1
  • 30
  • 34