Update docs for structs and objects

This commit is contained in:
2026-01-27 14:27:09 +11:00
parent f2a1b5a3ac
commit 9648744e17
2 changed files with 25 additions and 2 deletions

View File

@@ -18,6 +18,8 @@
<li><strong><a href="#type_system">Type System</a></strong></li>
<li><a href="#value_types">Value Types</a></li>
<li><a href="#type_checker">Type Checker</a></li>
<li><a href="#object_types">Types of Functions, Templates, and Objects</a></li>
<li><strong><a href="#structs">Structs, Templates and Objects</a></strong></li>
<li><strong><a href="#inline_ground">Inline Ground</a></strong></li>
<li><strong><a href="#builtins">Built In Functions</a></strong></li>
<li><a href="#input_string_msg__string">input(string msg) string</a></li>
@@ -125,6 +127,15 @@ while number &lt; 10 {
<li><code>bool</code>: Either true or false</li>
</ul>
</div>
<div id="object_types">
<h3>Types of Functions, Templates, and Objects</h3>
<p>The type signature of a function looks like this:</p>
<pre class="code"><code>fun(argType, argType, argType) returnType</code></pre>
<p>The type signature of a template looks like this:</p>
<pre class="code"><code>template(fieldType fieldName, fieldType fieldName, fieldType fieldName)</code></pre>
<p>The type signature of an object looks like this:</p>
<pre class="code"><code>object(fieldType fieldName, fieldType fieldName, fieldType fieldName)</code></pre>
</div>
<div id="type_checker">
<h3>Type Checker</h3>
<p>Solstice statically checks types at compile time to ensure your data is used as intended. These are the details of the type checker.</p>
@@ -137,6 +148,18 @@ while number &lt; 10 {
</ul>
</div>
</div>
<div id="structs">
<h2>Structs, templates and objects</h2>
<p><strong>Note:</strong> Structs, templates, and objects in Solstice are currently in beta. A lot of work in the type checker has been done, but accessing fields is still an issue.</p>
<p>In Solstice, you can create a struct to group various bits of data together. You can specify default values for each field with <code>:</code> or <code>=</code>.</p>
<pre class="code"><code>struct Person {
name: "John"
age: 32
}</code></pre>
<p>This struct generates a template named "Person" which can be used later to generate new objects.</p>
<p>You can use the <code>new</code> operator to create new instances of templates.</p>
<pre class="code"><code>max = new Person</code></pre>
</div>
<div id="inline_ground">
<h2>Inline Ground</h2>
<p>Since Solstice is built atop Ground, you can write Ground code inside Solstice code, usually to wrap a Ground function for the Solstice standard library.</p>