Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hello world to samples page #397

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
9 changes: 9 additions & 0 deletions assets/zig-code/samples/hello-world.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const std = @import("std");
const stdout = std.io.getStdOut().writer();

pub fn main() !void {
try stdout.print("hello world!\n", .{});
}

// exe=succeed

17 changes: 11 additions & 6 deletions content/en-US/learn/samples.smd
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,40 @@
},
---

# [Hello world]($heading.id('ext'))
A minimal example printing hello world.

[]($code.language('=html').buildAsset("samples/hello-world.zig"))

# [Calling external library functions]($heading.id('ext'))
All system API functions can be invoked this way, you do not need library bindings to interface them.

[]($code.language('=html').buildAsset("samples/0-windows-msgbox.zig"))
[]($code.language('=html').buildAsset("samples/windows-msgbox.zig"))

# [Memory leak detection]($heading.id('leak'))
Using `std.heap.GeneralPurposeAllocator` you can track double frees and memory leaks.

[]($code.language('=html').buildAsset("samples/1-memory-leak.zig"))
[]($code.language('=html').buildAsset("samples/memory-leak.zig"))


# [C interoperability]($heading.id('c-interop'))
Example of importing a C header file and linking to both libc and raylib.

[]($code.language('=html').buildAsset("samples/2-c-interop.zig"))
[]($code.language('=html').buildAsset("samples/c-interop.zig"))


# [Zigg Zagg]($heading.id('zigg-zagg'))
Zig is *optimized* for coding interviews (not really).

[]($code.language('=html').buildAsset("samples/3-ziggzagg.zig"))
[]($code.language('=html').buildAsset("samples/ziggzagg.zig"))


# [Generic Types]($heading.id('generic'))
In Zig types are comptime values and we use functions that return a type to implement generic algorithms and data structures. In this example we implement a simple generic queue and test its behaviour.

[]($code.language('=html').buildAsset("samples/4-generic-type.zig"))
[]($code.language('=html').buildAsset("samples/generic-type.zig"))


# [Using cURL from Zig]($heading.id('curl'))

[]($code.language('=html').buildAsset("samples/5-curl.zig"))
[]($code.language('=html').buildAsset("samples/curl.zig"))