-
Notifications
You must be signed in to change notification settings - Fork 0
/
embed.html
361 lines (340 loc) · 28.1 KB
/
embed.html
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Asciidoctor 2.0.12">
<meta name="author" content="v0.1">
<title>How to embed Agate in your application</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
<link rel="stylesheet" href="./asciidoctor.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="./rouge-old_github.css">
<meta name="keywords" content="Agate, programming language, scripting, gamedev" />
<meta name="description" content="Agate, a simple and embeddable programming language" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
</head>
<body class="article toc2 toc-right">
<div id="header">
<h1>How to embed Agate in your application</h1>
<div class="details">
<span id="author" class="author">v0.1</span><br>
</div>
<div id="toc" class="toc2">
<div id="toctitle">Table of Contents</div>
<ul class="sectlevel1">
<li><a href="#_virtual_machine">Virtual Machine</a>
<ul class="sectlevel2">
<li><a href="#_creation_and_deletion">Creation and Deletion</a></li>
<li><a href="#_basic_configuration">Basic Configuration</a></li>
<li><a href="#_executing_a_simple_script">Executing a simple script</a></li>
</ul>
</li>
<li><a href="#_slots">Slots</a>
<ul class="sectlevel2">
<li><a href="#_primitive_types">Primitive types</a></li>
<li><a href="#_array">Array</a></li>
<li><a href="#_map">Map</a></li>
<li><a href="#_variables">Variables</a></li>
</ul>
</li>
<li><a href="#_handles">Handles</a>
<ul class="sectlevel2">
<li><a href="#_handle_management">Handle management</a></li>
<li><a href="#_call_handles">Call handles</a></li>
</ul>
</li>
<li><a href="#_foreign_methods">Foreign methods</a></li>
<li><a href="#_foreign_classes">Foreign classes</a></li>
<li><a href="#_calling_agate_from_c">Calling Agate from C</a></li>
<li><a href="#_advanced_configuration">Advanced configuration</a>
<ul class="sectlevel2">
<li><a href="#_units">Units</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="content">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>Agate aims to be embedded in other applications like games. It has a C API to interact with the runtime environment of the Agate virtual machine.</p>
</div>
<div class="paragraph">
<p><a href="index.html">< Back to main page</a></p>
</div>
<div class="paragraph">
<p>The whole <a href="api.html">Agate API</a> is in the <code>agate.h</code> header. You need to include it to have access to the features of Agate.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="agate"><span class="c1">#include "agate.h"</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_virtual_machine"><a class="anchor" href="#_virtual_machine"></a>Virtual Machine</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_creation_and_deletion"><a class="anchor" href="#_creation_and_deletion"></a>Creation and Deletion</h3>
<div class="paragraph">
<p>In order to use Agate in your application, the first step is to create an Agate virtual machine which is represented by a pointer to an <code>AgateVM</code> structure in C. <code>AgateVM</code> is an <a href="https://en.wikipedia.org/wiki/Opaque_data_type">opaque type</a>. The <code>agateNewVM</code> function gives you a fresh new Agate virtual machine. The <code>agateDeleteVM</code> function deletes the virtual machines and all the associated ressources.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="agate"><span class="n">AgateVM</span><span class="w"> </span><span class="o">*</span><span class="n">vm</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">agateNewVM</span><span class="p">(</span><span class="n">NULL</span><span class="p">);</span><span class="err">
</span><span class="o">//</span><span class="w"> </span><span class="n">do</span><span class="w"> </span><span class="n">something</span><span class="w"> </span><span class="n">with</span><span class="w"> </span><span class="n">vm</span><span class="err">
</span><span class="n">agateDeleteVM</span><span class="p">(</span><span class="n">vm</span><span class="p">);</span></code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_basic_configuration"><a class="anchor" href="#_basic_configuration"></a>Basic Configuration</h3>
<div class="paragraph">
<p><code>NULL</code> indicates to use a default configuration for the virtual machine. In many cases, that is not what you want. The <code>AgateConfig</code> structure specifies the configuration of the virtual machine. In this section, we will see some basic configuration settings. Next sections will provide more advanced configuration options. The <code>agateConfigInitialize</code> initializes a configuration structure.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="agate"><span class="n">AgateConfig</span><span class="w"> </span><span class="n">config</span><span class="p">;</span><span class="err">
</span><span class="n">agateConfigInitialize</span><span class="p">(</span><span class="o">&</span><span class="n">config</span><span class="p">);</span><span class="err">
</span><span class="o">//</span><span class="w"> </span><span class="n">set</span><span class="w"> </span><span class="n">the</span><span class="w"> </span><span class="n">configuration</span><span class="err">
</span><span class="n">AgateVM</span><span class="w"> </span><span class="o">*</span><span class="n">vm</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">agateNewVM</span><span class="p">(</span><span class="o">&</span><span class="n">config</span><span class="p">);</span><span class="err">
</span><span class="o">//</span><span class="w"> </span><span class="n">do</span><span class="w"> </span><span class="n">something</span><span class="w"> </span><span class="n">with</span><span class="w"> </span><span class="n">vm</span><span class="err">
</span><span class="n">agateDeleteVM</span><span class="p">(</span><span class="n">vm</span><span class="p">);</span></code></pre>
</div>
</div>
<div class="sect3">
<h4 id="_assert_handling"><a class="anchor" href="#_assert_handling"></a>Assert handling</h4>
<div class="paragraph">
<p>Agate provides <a href="https://en.wikipedia.org/wiki/Assertion_(software_development)">assertions</a> in the language with the <code>assert</code> keyword. The behaviour of a failed assertion is determined by <code>assert_handling</code> in the configuration.</p>
</div>
<div class="paragraph">
<p>By default, the value of <code>assert_handling</code> is <code>AGATE_ASSERT_ABORT</code>. This means that the script aborts if the assertion fails. This is useful when developping the script. You can also choose that the assertion returns <code>nil</code> instead of stopping the script, with the <code>AGATE_ASSERT_NIL</code> value. In this case, the script may fail later. Or you can also choose that assertions are totally removed from the script with the <code>AGATE_ASSERT_NONE</code> value. This should be the configuration in production, when the script has been well tested.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="agate"><span class="n">AgateConfig</span><span class="w"> </span><span class="n">config</span><span class="p">;</span><span class="err">
</span><span class="n">agateConfigInitialize</span><span class="p">(</span><span class="o">&</span><span class="n">config</span><span class="p">);</span><span class="err">
</span><span class="n">config</span><span class="p">.</span><span class="n">assert_handling</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">AGATE_ASSERT_NONE</span><span class="p">;</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_inputoutput"><a class="anchor" href="#_inputoutput"></a>Input/Output</h4>
<div class="paragraph">
<p>By default, Agate does not print anything, you have to provide functions for this.</p>
</div>
<div class="paragraph">
<p>The <code>print</code> function is responsible to print a string to the standard output. The simplest implementation of a <code>print</code> function uses the <a href="https://en.cppreference.com/w/c/io/fputs"><code>fputs</code></a> standard function. This function is used by <a href="IO.html#_print"><code>IO.print</code></a> and related functions.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="agate"><span class="n">void</span><span class="w"> </span><span class="n">print_handler</span><span class="p">(</span><span class="n">AgateVM</span><span class="w"> </span><span class="o">*</span><span class="n">vm</span><span class="p">,</span><span class="w"> </span><span class="n">const</span><span class="w"> </span><span class="n">char</span><span class="o">*</span><span class="w"> </span><span class="n">text</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="err">
</span><span class="w"> </span><span class="n">fputs</span><span class="p">(</span><span class="n">text</span><span class="p">,</span><span class="w"> </span><span class="n">stdout</span><span class="p">);</span><span class="err">
</span><span class="p">}</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>write</code> function is responsible to write a single byte to the standard output. It can be used to output binary data to the standard output. The simplest implementation of a <code>write</code> function uses the <a href="https://en.cppreference.com/w/c/io/fputc"><code>fputc</code></a> standard function. This function is used by the <a href="IO.html#_write"><code>IO.write</code></a> function.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="agate"><span class="n">void</span><span class="w"> </span><span class="n">write_handler</span><span class="p">(</span><span class="n">AgateVM</span><span class="w"> </span><span class="o">*</span><span class="n">vm</span><span class="p">,</span><span class="w"> </span><span class="n">uint8_t</span><span class="w"> </span><span class="n">byte</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="err">
</span><span class="w"> </span><span class="n">fputc</span><span class="p">(</span><span class="n">byte</span><span class="p">,</span><span class="w"> </span><span class="n">stdout</span><span class="p">);</span><span class="err">
</span><span class="p">}</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>error</code> function is responsible to output errors. The function takes the following parameters: the kind of error, the unit name, the line of the error and the error message.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="agate"><span class="n">void</span><span class="w"> </span><span class="n">error_handler</span><span class="p">(</span><span class="n">AgateVM</span><span class="w"> </span><span class="o">*</span><span class="n">vm</span><span class="p">,</span><span class="w"> </span><span class="n">AgateErrorKind</span><span class="w"> </span><span class="n">kind</span><span class="p">,</span><span class="w"> </span><span class="n">const</span><span class="w"> </span><span class="n">char</span><span class="w"> </span><span class="o">*</span><span class="n">unit_name</span><span class="p">,</span><span class="w"> </span><span class="n">int</span><span class="w"> </span><span class="n">line</span><span class="p">,</span><span class="w"> </span><span class="n">const</span><span class="w"> </span><span class="n">char</span><span class="w"> </span><span class="o">*</span><span class="n">message</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="err">
</span><span class="w"> </span><span class="n">switch</span><span class="w"> </span><span class="p">(</span><span class="n">kind</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="err">
</span><span class="w"> </span><span class="n">case</span><span class="w"> </span><span class="n">AGATE_ERROR_COMPILE</span><span class="o">:</span><span class="err">
</span><span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"%s:%d: error: %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">unit_name</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="p">,</span><span class="w"> </span><span class="n">message</span><span class="p">);</span><span class="err">
</span><span class="w"> </span><span class="k">break</span><span class="p">;</span><span class="err">
</span><span class="w"> </span><span class="n">case</span><span class="w"> </span><span class="n">AGATE_ERROR_RUNTIME</span><span class="o">:</span><span class="err">
</span><span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"error: %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">message</span><span class="p">);</span><span class="err">
</span><span class="w"> </span><span class="k">break</span><span class="p">;</span><span class="err">
</span><span class="w"> </span><span class="n">case</span><span class="w"> </span><span class="n">AGATE_ERROR_STACKTRACE</span><span class="o">:</span><span class="err">
</span><span class="w"> </span><span class="n">printf</span><span class="p">(</span><span class="s">"%s:%d: in %s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span><span class="w"> </span><span class="n">unit_name</span><span class="p">,</span><span class="w"> </span><span class="n">line</span><span class="p">,</span><span class="w"> </span><span class="n">message</span><span class="p">);</span><span class="err">
</span><span class="w"> </span><span class="k">break</span><span class="p">;</span><span class="err">
</span><span class="w"> </span><span class="p">}</span><span class="err">
</span><span class="p">}</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>The <code>input</code> function is responsible for taking the input from the user. The simplest implementation of an <code>input</code> function uses the <a href="https://en.cppreference.com/w/c/io/fgets"><code>fgets</code></a> standard functions. This function is used by the <a href="IO.html#_input"><code>IO.input</code></a> function.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="agate"><span class="n">void</span><span class="w"> </span><span class="n">input_handler</span><span class="p">(</span><span class="n">AgateVM</span><span class="w"> </span><span class="o">*</span><span class="n">vm</span><span class="p">,</span><span class="w"> </span><span class="n">char</span><span class="w"> </span><span class="o">*</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="n">size_t</span><span class="w"> </span><span class="n">size</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="err">
</span><span class="w"> </span><span class="n">fgets</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="n">size</span><span class="p">,</span><span class="w"> </span><span class="n">stdin</span><span class="p">);</span><span class="err">
</span><span class="p">}</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Finally, you can use these functions in the configuration.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="agate"><span class="n">AgateConfig</span><span class="w"> </span><span class="n">config</span><span class="p">;</span><span class="err">
</span><span class="n">agateConfigInitialize</span><span class="p">(</span><span class="o">&</span><span class="n">config</span><span class="p">);</span><span class="err">
</span><span class="n">config</span><span class="p">.</span><span class="n">print</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">print_handler</span><span class="p">;</span><span class="err">
</span><span class="n">config</span><span class="p">.</span><span class="n">write</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">write_handler</span><span class="p">;</span><span class="err">
</span><span class="n">config</span><span class="p">.</span><span class="n">error</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">error_handler</span><span class="p">;</span><span class="err">
</span><span class="n">config</span><span class="p">.</span><span class="n">input</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">print_handler</span><span class="p">;</span></code></pre>
</div>
</div>
</div>
<div class="sect3">
<h4 id="_conversions_from_string"><a class="anchor" href="#_conversions_from_string"></a>Conversions from string</h4>
<div class="paragraph">
<p>Agate can be configured to use custom integer conversion from string in <code>parse_int</code> and float conversion from string in <code>parse_float</code>. These two functions are used during parsing and in the <a href="String.html#_to_i"><code>String.to_i</code></a> and <a href="String.html#_to_f"><code>String.to_f</code></a> functions.</p>
</div>
<div class="paragraph">
<p>If set to <code>NULL</code>, a default implementation is provided using <a href="https://en.cppreference.com/w/c/string/byte/strtol"><code>strtoll</code></a> for <code>parse_int</code> and <a href="https://en.cppreference.com/w/c/string/byte/strtof"><code>strtod</code></a> for <code>parse_float</code>, taking care of locale management. If you use Agate in C++17 (or later), you can use <a href="https://en.cppreference.com/w/cpp/utility/from_chars"><code>std::from_chars</code></a> which may be faster than the default implementation.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="cpp"><span class="c1">// C++17 implementation of parse_int</span>
<span class="kt">bool</span> <span class="nf">parse_int</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">text</span><span class="p">,</span> <span class="kt">ptrdiff_t</span> <span class="n">size</span><span class="p">,</span> <span class="kt">int</span> <span class="n">base</span><span class="p">,</span> <span class="kt">int64_t</span> <span class="o">*</span><span class="n">result</span><span class="p">)</span> <span class="p">{</span>
<span class="kt">int64_t</span> <span class="n">value</span><span class="p">;</span>
<span class="k">auto</span> <span class="p">[</span> <span class="n">ptr</span><span class="p">,</span> <span class="n">ec</span> <span class="p">]</span> <span class="o">=</span> <span class="n">std</span><span class="o">::</span><span class="n">from_chars</span><span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="n">text</span> <span class="o">+</span> <span class="n">size</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">base</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ec</span> <span class="o">==</span> <span class="n">std</span><span class="o">::</span><span class="n">errc</span><span class="p">())</span> <span class="p">{</span>
<span class="o">*</span><span class="n">result</span> <span class="o">=</span> <span class="n">value</span><span class="p">;</span>
<span class="k">return</span> <span class="n">ptr</span> <span class="o">==</span> <span class="n">text</span> <span class="o">+</span> <span class="n">size</span><span class="p">;</span>
<span class="p">}</span>
<span class="o">*</span><span class="n">result</span> <span class="o">=</span> <span class="n">std</span><span class="o">::</span><span class="n">numeric_limits</span><span class="o"><</span><span class="kt">int64_t</span><span class="o">>::</span><span class="n">max</span><span class="p">();</span>
<span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">// C++17 implementation of parse_float</span>
<span class="kt">bool</span> <span class="nf">parse_float</span><span class="p">(</span><span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">text</span><span class="p">,</span> <span class="kt">ptrdiff_t</span> <span class="n">size</span><span class="p">,</span> <span class="kt">double</span> <span class="o">*</span><span class="n">result</span><span class="p">)</span> <span class="p">{</span>
<span class="kt">double</span> <span class="n">value</span><span class="p">;</span>
<span class="k">auto</span> <span class="p">[</span> <span class="n">ptr</span><span class="p">,</span> <span class="n">ec</span> <span class="p">]</span> <span class="o">=</span> <span class="n">std</span><span class="o">::</span><span class="n">from_chars</span><span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="n">text</span> <span class="o">+</span> <span class="n">size</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">std</span><span class="o">::</span><span class="n">chars_format</span><span class="o">::</span><span class="n">general</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">ec</span> <span class="o">==</span> <span class="n">std</span><span class="o">::</span><span class="n">errc</span><span class="p">())</span> <span class="p">{</span>
<span class="o">*</span><span class="n">result</span> <span class="o">=</span> <span class="n">value</span><span class="p">;</span>
<span class="k">return</span> <span class="n">ptr</span> <span class="o">==</span> <span class="n">text</span> <span class="o">+</span> <span class="n">size</span><span class="p">;</span>
<span class="p">}</span>
<span class="o">*</span><span class="n">result</span> <span class="o">=</span> <span class="n">std</span><span class="o">::</span><span class="n">numeric_limits</span><span class="o"><</span><span class="kt">double</span><span class="o">>::</span><span class="n">quiet_NaN</span><span class="p">();</span>
<span class="k">return</span> <span class="nb">false</span><span class="p">;</span>
<span class="p">}</span></code></pre>
</div>
</div>
<div class="paragraph">
<p>Finally, if you really want to override the defaut implementation, you must change the configuration.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="agate"><span class="n">AgateConfig</span><span class="w"> </span><span class="n">config</span><span class="p">;</span><span class="err">
</span><span class="n">agateConfigInitialize</span><span class="p">(</span><span class="o">&</span><span class="n">config</span><span class="p">);</span><span class="err">
</span><span class="n">config</span><span class="p">.</span><span class="n">parse_int</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">parse_int</span><span class="p">;</span><span class="err">
</span><span class="n">config</span><span class="p">.</span><span class="n">parse_float</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">parse_float</span><span class="p">;</span></code></pre>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_executing_a_simple_script"><a class="anchor" href="#_executing_a_simple_script"></a>Executing a simple script</h3>
<div class="paragraph">
<p>After the virtual machine is configured, you can execute a simple script in a string with <code>agateCallString()</code>. The return value indicates if the script was executed without errors (<code>AGATE_STATUS_OK</code>) or if the compilation of the script failed (<code>AGATE_STATUS_COMPILE_ERROR</code>) or if a runtime error occured (<code>AGATE_STATUS_RUNTIME_ERROR</code>).</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="rouge highlight"><code data-lang="agate"><span class="n">AgateStatus</span><span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">agateCallString</span><span class="p">(</span><span class="n">vm</span><span class="p">,</span><span class="w"> </span><span class="s">"game"</span><span class="p">,</span><span class="w"> </span><span class="s">"IO.println(</span><span class="se">\"</span><span class="s">Start!</span><span class="se">\"</span><span class="s">)"</span><span class="p">);</span></code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_slots"><a class="anchor" href="#_slots"></a>Slots</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Slots are identifiers for communicating between the Agate part and the C part. They are indices in an array of values that you can read or write.</p>
</div>
<div class="sect2">
<h3 id="_primitive_types"><a class="anchor" href="#_primitive_types"></a>Primitive types</h3>
</div>
<div class="sect2">
<h3 id="_array"><a class="anchor" href="#_array"></a>Array</h3>
</div>
<div class="sect2">
<h3 id="_map"><a class="anchor" href="#_map"></a>Map</h3>
</div>
<div class="sect2">
<h3 id="_variables"><a class="anchor" href="#_variables"></a>Variables</h3>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_handles"><a class="anchor" href="#_handles"></a>Handles</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_handle_management"><a class="anchor" href="#_handle_management"></a>Handle management</h3>
</div>
<div class="sect2">
<h3 id="_call_handles"><a class="anchor" href="#_call_handles"></a>Call handles</h3>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_foreign_methods"><a class="anchor" href="#_foreign_methods"></a>Foreign methods</h2>
<div class="sectionbody">
</div>
</div>
<div class="sect1">
<h2 id="_foreign_classes"><a class="anchor" href="#_foreign_classes"></a>Foreign classes</h2>
<div class="sectionbody">
</div>
</div>
<div class="sect1">
<h2 id="_calling_agate_from_c"><a class="anchor" href="#_calling_agate_from_c"></a>Calling Agate from C</h2>
<div class="sectionbody">
</div>
</div>
<div class="sect1">
<h2 id="_advanced_configuration"><a class="anchor" href="#_advanced_configuration"></a>Advanced configuration</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_units"><a class="anchor" href="#_units"></a>Units</h3>
</div>
</div>
</div>
</div>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
messageStyle: "none",
tex2jax: {
inlineMath: [["\\(", "\\)"]],
displayMath: [["\\[", "\\]"]],
ignoreClass: "nostem|nolatexmath"
},
asciimath2jax: {
delimiters: [["\\$", "\\$"]],
ignoreClass: "nostem|noasciimath"
},
TeX: { equationNumbers: { autoNumber: "none" } }
})
MathJax.Hub.Register.StartupHook("AsciiMath Jax Ready", function () {
MathJax.InputJax.AsciiMath.postfilterHooks.Add(function (data, node) {
if ((node = data.script.parentNode) && (node = node.parentNode) && node.classList.contains("stemblock")) {
data.math.root.display = "block"
}
return data
})
})
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js?config=TeX-MML-AM_HTMLorMML"></script>
</body>
</html>