Skip to content

Commit 913ea45

Browse files
committed
deploy: 4e26580
1 parent 9a7633a commit 913ea45

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

docs/object/modules/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
</span></span><span style=display:flex><span>
3030
</span></span><span style=display:flex><span>timer<span style=color:#f92672>:</span> mach.time.Timer,
3131
</span></span><span style=display:flex><span>counter<span style=color:#f92672>:</span> <span style=color:#66d9ef>u32</span>,
32-
</span></span></code></pre></div><p>There is only ever one <em>instance</em> of a module in a program, so these are <em>effectively</em> global variables. Writing these as <em>struct fields</em> rather than literally as global <code>var</code>s means that <strong><em>Mach moduloe&rsquo;s global state fields are globally addressible</em></strong> (its possible to walk <em>all modules used in the program</em>, then walk over <em>all their state fields</em>, inspecting their data types, and reading/writing their values at runtime - which is super useful for debug tooling and more!)</p><h2 id=modules-can-have-_systems_>Modules can have <em>systems</em></h2><p>Similar to how we declared <code>pub const mach_module = .foo_name;</code>, a module can declare that it has <em>systems</em> with specific names:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-zig data-lang=zig><span style=display:flex><span><span style=color:#66d9ef>pub</span> <span style=color:#66d9ef>const</span> mach_systems <span style=color:#f92672>=</span> .{ .init, .tick, .deinit };
33-
</span></span></code></pre></div><p>In this case, our module declared that it has systems called <code>.init</code>, <code>.tick</code>, and <code>.deinit</code> - these are just made up names (we&rsquo;re <em>declaring them</em>) - we can name them whatever we like.</p><p>Systems are ultimately just functions (or lists of functions) that <em>could</em> be run if someone wants them to. They don&rsquo;t do anything by default.</p><p>The only requirement is that if a system is named in <code>mach_systems</code>, there must be a corresponding public function or schedule of the same name (else you&rsquo;ll get a compiler error) - for example:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-zig data-lang=zig><span style=display:flex><span><span style=color:#66d9ef>pub</span> <span style=color:#66d9ef>fn</span> init() <span style=color:#66d9ef>void</span> {
32+
</span></span></code></pre></div><p>There is only ever one <em>instance</em> of a module in a program, so these are <em>effectively</em> global variables. Writing these as <em>struct fields</em> rather than literally as global <code>var</code>s means that <strong><em>Mach moduloe&rsquo;s global state fields are globally addressible</em></strong> (its possible to walk <em>all modules used in the program</em>, then walk over <em>all their state fields</em>, inspecting their data types, and reading/writing their values at runtime - which is super useful for debug tooling and more!)</p><h2 id=modules-can-have-_systems_>Modules can have <em>systems</em></h2><p>Similar to how we declared <code>pub const mach_module = .foo_name;</code>, a module can declare that it has <em>systems</em> with specific names:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-zig data-lang=zig><span style=display:flex><span><span style=color:#66d9ef>pub</span> <span style=color:#66d9ef>const</span> mach_systems <span style=color:#f92672>=</span> .{ .main, .init, .tick, .deinit };
33+
</span></span></code></pre></div><p>In this case, our module declared that it has systems called <code>.main</code>, <code>.init</code>, <code>.tick</code>, and <code>.deinit</code> - these are just made up names (we&rsquo;re <em>declaring them</em>) - we can name them whatever we like.</p><p>Systems are ultimately just functions (or lists of functions) that <em>could</em> be run if someone wants them to. They don&rsquo;t do anything by default.</p><p>The only requirement is that if a system is named in <code>mach_systems</code>, there must be a corresponding public function or schedule of the same name (else you&rsquo;ll get a compiler error) - for example:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-zig data-lang=zig><span style=display:flex><span><span style=color:#66d9ef>pub</span> <span style=color:#66d9ef>fn</span> init() <span style=color:#66d9ef>void</span> {
3434
</span></span><span style=display:flex><span> <span style=color:#75715e>// ...
3535
</span></span></span><span style=display:flex><span><span style=color:#75715e></span>}
3636
</span></span></code></pre></div><p>Systems are covered in more depth in <a href=../systems>the systems section</a>.</p><h2 id=modules-can-have-_objects_>Modules can have <em>objects</em></h2><p>Just like how we added the <code>timer</code> and <code>counter</code> fields above, it is possible to declare <em>lists of objects</em> inside a module. For example, here&rsquo;s a list of <code>monsters</code> where each monster object can have a <code>health</code> and <code>damage</code> value:</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-zig data-lang=zig><span style=display:flex><span>monsters<span style=color:#f92672>:</span> mach.Objects(<span style=color:#66d9ef>struct</span> {
Binary file not shown.

0 commit comments

Comments
 (0)