Skip to content

Commit

Permalink
Merge pull request #132 from pedropark99/edition-2
Browse files Browse the repository at this point in the history
Add links for Leanpub publishing
  • Loading branch information
pedropark99 authored Feb 16, 2025
2 parents eb10089 + c91b691 commit 7b056a6
Show file tree
Hide file tree
Showing 24 changed files with 101 additions and 76 deletions.
21 changes: 21 additions & 0 deletions Assets/leanpub-button.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<style>
.btn {
border-radius: 5px;
background-color: #4f73e8;
border: #4f73e8;
opacity: 1;
transition: 0.3s;
}

.btn:hover {
background-color: #2144b6;
border: #2144b6;
}
</style>


<a href="https://leanpub.com/introductiontozigaproject-basedbook">
<button class="btn btn-primary" type="button">
Buy the book on Leanpub!
</button>
</a>
25 changes: 12 additions & 13 deletions Cover/cover-art.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Cover/cover-artv4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Cover/cover-artv4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ the Zig compiler to compile and run the Zig code examples.

## Support the project!

If you like this project, and you want to support it, you can buy an eBook or a physical copy
of the book on Amazon:
If you like this project, and you want to support it, you can buy a PDF, eBook or a physical copy
of the book, either at Amazon, or at Leanpub:

<https://www.amazon.com/dp/B0DJYMDRLP>
- Amazon: <https://www.amazon.com/dp/B0DJYMDRLP>
- Leanpub: <https://leanpub.com/introductiontozigaproject-basedbook>

### Sending donations directly

Expand Down
4 changes: 1 addition & 3 deletions _freeze/Chapters/01-base64/execute-results/html.json

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions _freeze/Chapters/01-zig-weird/execute-results/html.json

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions _freeze/Chapters/03-structs/execute-results/html.json

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions _freeze/Chapters/03-unittests/execute-results/html.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion _freeze/Chapters/05-pointers/execute-results/html.json

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions _freeze/Chapters/07-build-system/execute-results/html.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions _freeze/Chapters/10-stack-project/execute-results/html.json

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions _freeze/Chapters/12-file-op/execute-results/html.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions _freeze/index/execute-results/html.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ book:
title: "Introduction to Zig"
subtitle: "a project-based book"
author: "Pedro Duarte Faria"
edition: 1
date: "today"
google-analytics: "G-6CHJXK4CEV"
cover-image: "Cover/cover-artv3.png"
Expand Down
7 changes: 4 additions & 3 deletions docs/Chapters/03-structs.html
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,8 @@ <h2 data-number="2.5" class="anchored" data-anchor-id="sec-type-cast"><span clas
<span id="cb49-6"><a href="#cb49-6" aria-hidden="true" tabindex="-1"></a> <span class="kw">try</span> expect(<span class="bu">@TypeOf</span>(y) == <span class="dt">u32</span>);</span>
<span id="cb49-7"><a href="#cb49-7" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>1/1 file2ed34a8fc96.test_0...OKAll 1 tests passed.</code></pre>
<pre><code>1/1 file9f8940318094.test_0...OKAll 1 tests passed
d.</code></pre>
</div>
</div>
<p>This is the general way to perform type casting in Zig. But remember, <code>@as()</code> works only when casting is unambiguous and safe, and there are situations where these assumptions do not hold. For example, when casting an integer value into a float value, or vice-versa, it is not clear to the compiler how to perform this conversion safely.</p>
Expand All @@ -942,7 +943,7 @@ <h2 data-number="2.5" class="anchored" data-anchor-id="sec-type-cast"><span clas
<span id="cb51-6"><a href="#cb51-6" aria-hidden="true" tabindex="-1"></a> <span class="kw">try</span> expect(<span class="bu">@TypeOf</span>(y) == <span class="dt">f32</span>);</span>
<span id="cb51-7"><a href="#cb51-7" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>1/1 file2ed34bfb9fa5.test_0...OKAll 1 tests passed
<pre><code>1/1 file9f8954828844.test_0...OKAll 1 tests passed
d.</code></pre>
</div>
</div>
Expand All @@ -959,7 +960,7 @@ <h2 data-number="2.5" class="anchored" data-anchor-id="sec-type-cast"><span clas
<span id="cb53-8"><a href="#cb53-8" aria-hidden="true" tabindex="-1"></a> <span class="kw">try</span> expect(<span class="bu">@TypeOf</span>(u32_ptr) == *<span class="kw">const</span> <span class="dt">u32</span>);</span>
<span id="cb53-9"><a href="#cb53-9" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>1/1 file2ed324328e1f.test_0...OKAll 1 tests passed
<pre><code>1/1 file9f8944ca02e1.test_0...OKAll 1 tests passed
d.</code></pre>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions docs/Chapters/03-unittests.html
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ <h2 data-number="8.1" class="anchored" data-anchor-id="introducing-the-test-bloc
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> <span class="kw">try</span> expect((a + b) == <span class="dv">4</span>);</span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>1/1 file153713a3190e.test.testing simple sum...OKA
<pre><code>1/1 filea5b06c1ec326.test.testing simple sum...OKA
All 1 tests passed.</code></pre>
</div>
</div>
Expand Down Expand Up @@ -396,8 +396,8 @@ <h2 data-number="8.4" class="anchored" data-anchor-id="testing-errors"><span cla
<span id="cb7-14"><a href="#cb7-14" aria-hidden="true" tabindex="-1"></a> <span class="kw">try</span> expectError(<span class="kw">error</span>.OutOfMemory, alloc_error(allocator));</span>
<span id="cb7-15"><a href="#cb7-15" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>1/1 file1537546f248.test.testing error...OKAll 1 t
tests passed.</code></pre>
<pre><code>1/1 filea5b059c00874.test.testing error...OKAll 1
tests passed.</code></pre>
</div>
</div>
</section>
Expand Down Expand Up @@ -433,7 +433,7 @@ <h2 data-number="8.5" class="anchored" data-anchor-id="testing-simple-equalities
<span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a> );</span>
<span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>1/1 file15377bbafb73.test.arrays are equal?...OKAl
<pre><code>1/1 filea5b054e42b80.test.arrays are equal?...OKAl
ll 1 tests passed.</code></pre>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/Chapters/09-error-handling.html
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ <h3 data-number="10.1.3" class="anchored" data-anchor-id="casting-error-values">
<span id="cb8-20"><a href="#cb8-20" aria-hidden="true" tabindex="-1"></a> );</span>
<span id="cb8-21"><a href="#cb8-21" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>1/1 file10459ffd0e21.test.coerce error value...OKA
<pre><code>1/1 filea64e1da1167c.test.coerce error value...OKA
All 1 tests passed.</code></pre>
</div>
</div>
Expand Down
12 changes: 6 additions & 6 deletions docs/Chapters/10-stack-project.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ <h3 data-number="12.1.1" class="anchored" data-anchor-id="applying-over-a-functi
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> _ = twice(<span class="dv">5678</span>);</span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>1/1 file1105a40478a9d.test.test comptime...OKAll 1
1 tests passed.</code></pre>
<pre><code>1/1 filea72d248f97f8.test.test comptime...OKAll 1
tests passed.</code></pre>
</div>
</div>
<p>But what if we provide a number that is not compile-time known to this function? For example, we might provide a different input value to this function depending on the target OS of our compilation process. The code example below demonstrates such case.</p>
Expand Down Expand Up @@ -426,8 +426,8 @@ <h3 data-number="12.1.2" class="anchored" data-anchor-id="applying-over-an-expre
<span id="cb6-11"><a href="#cb6-11" aria-hidden="true" tabindex="-1"></a> <span class="kw">try</span> <span class="kw">comptime</span> expect(fibonacci(<span class="dv">7</span>) == <span class="dv">13</span>);</span>
<span id="cb6-12"><a href="#cb6-12" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>1/1 file1105a31c0f24f.test.fibonacci...OKAll 1 tes
sts passed.</code></pre>
<pre><code>1/1 filea72d3cf7abe2.test.fibonacci...OKAll 1 test
ts passed.</code></pre>
</div>
</div>
<p>A lot of your Zig source code might be potentially executed at compile-time, because the <code>zig</code> compiler can figure it out the output of some expressions. Especially if these expressions depends only at compile-time known values. We have talked about this at <a href="01-memory.html#sec-compile-time" class="quarto-xref"><span>Section 3.1.1</span></a>.</p>
Expand Down Expand Up @@ -455,8 +455,8 @@ <h3 data-number="12.1.3" class="anchored" data-anchor-id="applying-over-a-block"
<span id="cb8-15"><a href="#cb8-15" aria-hidden="true" tabindex="-1"></a> _ = x;</span>
<span id="cb8-16"><a href="#cb8-16" aria-hidden="true" tabindex="-1"></a><span class="op">}</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
<pre><code>1/1 file1105a37ca2b0d.test.fibonacci in a block...
.OKAll 1 tests passed.</code></pre>
<pre><code>1/1 filea72d6353d586.test.fibonacci in a block...O
OKAll 1 tests passed.</code></pre>
</div>
</div>
</section>
Expand Down
23 changes: 19 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">

<meta name="author" content="Pedro Duarte Faria">
<meta name="dcterms.date" content="2025-02-15">
<meta name="dcterms.date" content="2025-02-16">

<title>Introduction to Zig</title>
<style>
Expand Down Expand Up @@ -287,7 +287,7 @@ <h1 class="title">Introduction to Zig</h1>
<div>
<div class="quarto-title-meta-heading">Published</div>
<div class="quarto-title-meta-contents">
<p class="date">February 15, 2025</p>
<p class="date">February 16, 2025</p>
</div>
</div>

Expand All @@ -305,7 +305,7 @@ <h1 class="unnumbered">Welcome</h1><p><img src="Cover/cover-artv3.png" title="In
<p>Welcome! This is the initial page for the “Open Access” HTML version of the book “Introduction to Zig: a project-based book”, written by <a href="https://pedro-faria.netlify.app/">Pedro Duarte Faria</a>. This is an open book that provides an introduction to the <a href="https://ziglang.org/">Zig programming language</a>, which is a new general-purpose, and low-level language for building robust and optimal software.</p>
<section id="support-the-project" class="level2 unnumbered">
<h2 class="unnumbered anchored" data-anchor-id="support-the-project">Support the project!</h2>
<p>If you like this project, and you want to support it, you can buy an eBook or a physical copy of the book on Amazon:</p>
<p>If you like this project, and you want to support it, you can buy a PDF, eBook or a physical copy of the book, either at Amazon, or at Leanpub:</p>
<style>
.btn {
border-radius: 5px;
Expand All @@ -321,6 +321,21 @@ <h2 class="unnumbered anchored" data-anchor-id="support-the-project">Support the
}
</style>
<p><a href="https://www.amazon.com/dp/B0DJYMDRLP"> <button class="btn btn-primary" type="button"> Buy the book on Amazon! </button> </a></p>
<style>
.btn {
border-radius: 5px;
background-color: #4f73e8;
border: #4f73e8;
opacity: 1;
transition: 0.3s;
}

.btn:hover {
background-color: #2144b6;
border: #2144b6;
}
</style>
<p><a href="https://leanpub.com/introductiontozigaproject-basedbook"> <button class="btn btn-primary" type="button"> Buy the book on Leanpub! </button> </a></p>
<section id="sending-donations-directly" class="level3">
<h3 class="anchored" data-anchor-id="sending-donations-directly">Sending donations directly</h3>
<p>You can also donate some amount directly to the author of the project via:</p>
Expand Down Expand Up @@ -404,7 +419,7 @@ <h2 class="unnumbered anchored" data-anchor-id="about-the-author">About the auth
</section>
<section id="license" class="level2 unnumbered">
<h2 class="unnumbered anchored" data-anchor-id="license">License</h2>
<p>Copyright © 2024 Pedro Duarte Faria. This book is licensed by the <a href="https://creativecommons.org/licenses/by/4.0/">CC-BY 4.0 Creative Commons Attribution 4.0 International Public License</a><a href="#fn4" class="footnote-ref" id="fnref4" role="doc-noteref"><sup>4</sup></a>.</p>
<p>Copyright © 2025 Pedro Duarte Faria. This book is licensed by the <a href="https://creativecommons.org/licenses/by/4.0/">CC-BY 4.0 Creative Commons Attribution 4.0 International Public License</a><a href="#fn4" class="footnote-ref" id="fnref4" role="doc-noteref"><sup>4</sup></a>.</p>
<p><img src="Figures/creative-commoms-88x31.png" class="img-fluid" width="88"></p>
</section>
<section id="book-compilation-metadata" class="level2 unnumbered">
Expand Down
Loading

0 comments on commit 7b056a6

Please sign in to comment.