Update docs for structs and objects
This commit is contained in:
@@ -64,7 +64,7 @@ function highlightSolstice(code) {
|
||||
const word = code.substring(i, end);
|
||||
|
||||
// Check what type of word it is
|
||||
if (['def', 'if', 'while', 'return', 'ground', 'puts'].includes(word)) {
|
||||
if (['def', 'if', 'while', 'return', 'ground', 'puts', 'def', 'struct', 'new'].includes(word)) {
|
||||
result += `<span class="keyword">${word}</span>`;
|
||||
} else if (['input', 'print', 'println'].includes(word)) {
|
||||
result += `<span class="builtin">${word}</span>`;
|
||||
@@ -87,7 +87,7 @@ function highlightSolstice(code) {
|
||||
}
|
||||
|
||||
// Check for operators
|
||||
else if ('+-*/=!<>'.includes(code[i])) {
|
||||
else if ('+-*/=!<>:'.includes(code[i])) {
|
||||
let op = code[i];
|
||||
if (i + 1 < code.length && '='.includes(code[i + 1])) {
|
||||
op += code[i + 1];
|
||||
|
||||
@@ -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 < 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 < 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>
|
||||
|
||||
Reference in New Issue
Block a user