-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrata.html
More file actions
239 lines (215 loc) · 11.2 KB
/
Copy pathstrata.html
File metadata and controls
239 lines (215 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Strata Scripting Language. Gameplay Scripting for Hyperion Engine</title>
<meta name="description" content="Strata is Hyperion Engine's gameplay scripting language: statically typed, LLVM-compiled to native code with live hot-reload on save. Syntax guide.">
<link rel="canonical" href="https://hyperionengine.dev/strata.html">
<meta name="robots" content="index, follow, max-image-preview:large">
<meta name="author" content="The Hyperion Contributors">
<meta name="theme-color" content="#0b0d10">
<meta name="color-scheme" content="dark">
<link rel="icon" type="image/png" sizes="96x96" href="/favicon-light.png" media="(prefers-color-scheme: light)">
<link rel="icon" type="image/png" sizes="96x96" href="/favicon-dark.png" media="(prefers-color-scheme: dark)">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="manifest" href="/site.webmanifest">
<meta property="og:type" content="article">
<meta property="og:site_name" content="Hyperion Engine">
<meta property="og:locale" content="en_US">
<meta property="og:title" content="Strata Scripting Language. Gameplay Scripting for Hyperion Engine">
<meta property="og:description" content="Statically typed, LLVM-compiled gameplay scripting for Hyperion Engine with live hot-reload on save. Functions, control flow, boxes, optionals and engine bindings.">
<meta property="og:url" content="https://hyperionengine.dev/strata.html">
<meta property="og:image" content="https://hyperionengine.dev/assets/lightmap-editor.png">
<meta property="og:image:width" content="1891">
<meta property="og:image:height" content="1103">
<meta property="og:image:alt" content="Hyperion editor showing the Sponza scene with scene hierarchy, properties, content browser and console panels">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Strata Scripting Language. Gameplay Scripting for Hyperion Engine">
<meta name="twitter:description" content="Statically typed, LLVM-compiled gameplay scripting for Hyperion Engine with live hot-reload on save.">
<meta name="twitter:image" content="https://hyperionengine.dev/assets/lightmap-editor.png">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap">
<link rel="stylesheet" href="styles.css">
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@graph": [
{
"@type": "TechArticle",
"@id": "https://hyperionengine.dev/strata.html#article",
"headline": "Strata Scripting Language. Gameplay Scripting for Hyperion Engine",
"description": "Strata is the statically typed, LLVM-compiled scripting language for gameplay in Hyperion Engine, with live recompilation on save.",
"inLanguage": "en",
"author": {
"@type": "Organization",
"name": "HyperionGameTech",
"url": "https://hyperionengine.dev/"
},
"about": {
"@type": "ComputerLanguage",
"name": "Strata",
"url": "https://hyperionengine.dev/strata.html"
},
"mainEntityOfPage": "https://hyperionengine.dev/strata.html",
"image": "https://hyperionengine.dev/assets/lightmap-editor.png"
},
{
"@type": "BreadcrumbList",
"@id": "https://hyperionengine.dev/strata.html#breadcrumb",
"itemListElement": [
{ "@type": "ListItem", "position": 1, "name": "Home", "item": "https://hyperionengine.dev/" },
{ "@type": "ListItem", "position": 2, "name": "Strata", "item": "https://hyperionengine.dev/strata.html" }
]
}
]
}
</script>
</head>
<body>
<a class="skip-link" href="#main">Skip to content</a>
<header class="site-header">
<div class="wrap header-inner">
<a class="brand" href="/" aria-label="Hyperion Engine — home"><img src="assets/hyperion-logo.png" alt="" width="382" height="105"></a>
<nav class="nav" aria-label="Primary">
<a href="/">Home</a>
<a href="/#features">Features</a>
<a href="/strata.html" aria-current="page">Strata</a>
<a href="/docs/">Docs</a>
<a class="nav-github" href="https://github.com/HyperionGameTech/HyperionEngine" rel="noopener" aria-label="Hyperion Engine on GitHub" title="GitHub"><svg viewBox="0 0 16 16" aria-hidden="true" focusable="false"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg></a>
</nav>
</div>
</header>
<main id="main">
<section class="wrap section section-intro" aria-labelledby="strata-heading">
<h1 id="strata-heading">Strata scripting language</h1>
<p>Strata is the primary scripting language for gameplay in Hyperion Engine.<br><br>It is statically typed, has <em>no GC, ref-counting, or manual memory management.</em>. Compiled via JIT in-editor with live reload, or AOT compiled + linked for shipping builds.<br><br>None of that <em>restarting the game or editor to see your changes</em> hogwash.</p>
<p>Note that Strata itself is a separate project from Hyperion; freely usable in other projects. GitHub: <a href="https://github.com/StrataLanguage/stratac" rel="noopener">github.com/StrataLanguage/stratac</a>.</p>
</section>
<section class="wrap section" aria-labelledby="functions-heading">
<h2 id="functions-heading">The Basics Volume I: Functions</h2>
<p>Functions are C-like, with static types</p>
<pre><code>int add(int a, int b)
{
return a + b;
}</code></pre>
</section>
<section class="wrap section" aria-labelledby="control-flow-heading">
<h2 id="control-flow-heading">The Basics Volume II: Control flow</h2>
<p><code>if</code>, <code>while</code>, <code>for</code>, <code>break</code>, and <code>continue</code> all work as expected in Strata, if you're used to any C-based language</p>
<pre><code>int factorial(int n)
{
int result = 1;
int i = 1;
while (i <= n)
{
result = result * i;
i = i + 1;
}
return result;
}</code></pre>
</section>
<section class="wrap section" aria-labelledby="arrays-heading">
<h2 id="arrays-heading">The Basics Volume III: Arrays and strings</h2>
<p>Dynamic arrays in Strata grow with <code>array_push</code> and report their size with <code>.length</code>.</p>
<p>Fixed size arrays are supposed as well for struct field members.</p>
<pre><code>extern int printf(string fmt, ...);
struct Inventory
{
int[8] item_ids; // Fixed size.
};
int main()
{
string[] backpack = { "torch", "rope" };
array_push(backpack, "rations");
printf("carrying %u items\n", backpack.length);
return (int)backpack.length; // 3
}</code></pre>
</section>
<section class="wrap section" aria-labelledby="enums-heading">
<h2 id="enums-heading">The Basics Volume IV: Enums</h2>
<p>Enums are scoped. If you've used them in C#, or used <code>enum class</code> in C++, it's that.</p>
<pre><code>enum Color : int { Red, Green, Blue };
enum Scale : byte { Small = 1, Medium, Large, Huge };
Color c = Color.Blue;
int v = (int)c;
Color back = (Color)2;</code></pre>
</section>
<section class="wrap section" aria-labelledby="engine-heading">
<h2 id="engine-heading">Now you're cooking: working with engine objects</h2>
<p>Handles are opaque types, mirroring Hyperion Engine objects. Extern functions are implemented by the engine in C++. These exact declarations ship with the engine.</p>
<p>An <code>impl</code> block attaches functions to a <code>handle</code>, <code>struct</code> or <code>enum</code> type to be used as methods.
</p>
<pre><code>handle Camera;
impl Camera
{
extern float GetFOV(Camera self);
extern void SetFOV(Camera self, float v);
}
void reset_view(Camera cam)
{
cam.SetFOV(60.0);
}</code></pre>
<p>Engine side: (C++)</p>
<pre><code>HYP_CLASS()
class Camera : public ObjectBase
{
HYP_OBJECT_BODY(Camera);
public:
HYP_METHOD(Property = "FOV")
float GetFOV() const;
HYP_METHOD(Property = "FOV")
void SetFOV(float v);
};
/// Hyperion's build tool will automatically set up the mapping from Strata to Hyperion's native runtime.</code></pre>
</section>
<section class="wrap section" aria-labelledby="boxes-heading">
<h2 id="boxes-heading">Advanced Reading: Boxes and optionals</h2>
<p>For a given type you defined, say, <code>Foo</code> - <code>^Foo</code> (note the caret) allocates a value on the heap (a "box"). Boxes are move-only, and are freed when they go out of scope. This lets us forego the need for garbage collection, runtime reference counting and manual memory management.
<br><br><code>Foo?</code> is an optional: it may be empty, and testing it with <code>while (cur?)</code> blesses it, proving to the compiler that it holds a value.
<br><br>
Strata <strong>does not have a "null" or "nil"</strong> keyword or a "null pointer" concept. Instead, optionals are used to represent the absence of a value.
<br><br>
The compiler prevents you from using an optional that may be empty, so you can't crash the game by forgetting to check.
</p>
<pre><code>struct Crate
{
int weight;
Crate? next;
};
int main()
{
^Crate head = Crate { .weight = 12 };
Crate? cur = head;
int total = 0;
while (cur?)
{
total = total + cur.weight;
cur = cur.next;
// You can't use cur again here.
// You'll need another `if (cur?) { ... }` and use it in that block.
}
return total; // 12
}</code></pre>
</section>
<section class="wrap section" aria-labelledby="running-heading">
<h2 id="running-heading">Running Strata scripts</h2>
<p>Scripts are plain <code>.strata</code> files. The Hyperion editor recompiles them on save, so there is no restart or reload step. See the <a href="https://github.com/StrataLanguage/stratac" rel="noopener">Strata compiler on GitHub</a> or <a href="/">back to the Hyperion Engine overview</a>.</p>
</section>
</main>
<footer class="site-footer">
<div class="wrap footer-inner">
<span>Hyperion Engine</span>
<nav aria-label="Footer">
<a href="/">Home</a>
<a href="/#features">Features</a>
<a href="/strata.html" aria-current="page">Strata</a>
<a href="/docs/">Docs</a>
<a href="https://github.com/HyperionGameTech/HyperionEngine" rel="noopener">GitHub</a>
<a href="https://ajmd.dev" rel="me noopener">ajmd.dev</a>
</nav>
</div>
</footer>
</body>
</html>