Notes tagged with: zig

December 13, 2022

zig

Easily install Zig with zigup

I used to manage my Zig installation by installing the binary and copying to my path. Not too hard, but now there is even an easier way by using zigup.

To install zig, it enables you to simply type zigup master

I would recommend to get the latest binary from the Github releases page. Or if you already have Zig, install it from source:

# Install the binary
git clone [email protected]:marler8997/zigup.git
cd zigup
zig build -Dfetch
cp zig-out/bin/zigup ~/.local/bin/

November 24, 2022

zig

Zig types explained in Ziglings

I have been tinkering with Zig lately and to get a grasp on the language I have been using the excellent Ziglings quizes.

In Quiz #58 there is a great comment which lists the different types for Zig:

//
// We've absorbed a lot of information about the variations of types
// we can use in Zig. Roughly, in order we have:
//
//                          u8  single item
//                         *u8  single-item pointer
//                        []u8  slice (size known at runtime)
//                       [5]u8  array of 5 u8s
//                       [*]u8  many-item pointer (zero or more)
//                 enum {a, b}  set of unique values a and b
//                error {e, f}  set of unique error values e and f
//      struct {y: u8, z: i32}  group of values y and z
// union(enum) {a: u8, b: i32}  single value either u8 or i32
//
// Values of any of the above types can be assigned as "var" or "const"
// to allow or disallow changes (mutability) via the assigned name:
//
//     const a: u8 = 5; // immutable
//       var b: u8 = 5; //   mutable
//
// We can also make error unions or optional types from any of
// the above:
//
//     var a: E!u8 = 5; // can be u8 or error from set E
//     var b: ?u8 = 5;  // can be u8 or null