mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-12 14:48:40 +01:00
209 lines
8.1 KiB
HTML
209 lines
8.1 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
|
|
<title>Getting Started – Wren</title>
|
|
<link rel="stylesheet" type="text/css" href="style.css" />
|
|
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:400,700,400italic,700italic|Source+Code+Pro:400|Lato:400|Sanchez:400italic,400' rel='stylesheet' type='text/css'>
|
|
<!-- Tell mobile browsers we're optimized for them and they don't need to crop
|
|
the viewport. -->
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
|
|
</head>
|
|
<body id="top">
|
|
<header>
|
|
<div class="page">
|
|
<div class="main-column">
|
|
<h1><a href="./">wren</a></h1>
|
|
<h2>a classy little scripting language</h2>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
<div class="page">
|
|
<nav class="big">
|
|
<ul>
|
|
<li><a href="getting-started.html">Getting Started</a></li>
|
|
<li><a href="contributing.html">Contributing</a></li>
|
|
</ul>
|
|
<section>
|
|
<h2>language guide</h2>
|
|
<ul>
|
|
<li><a href="syntax.html">Syntax</a></li>
|
|
<li><a href="values.html">Values</a></li>
|
|
<li><a href="lists.html">Lists</a></li>
|
|
<li><a href="maps.html">Maps</a></li>
|
|
<li><a href="method-calls.html">Method Calls</a></li>
|
|
<li><a href="control-flow.html">Control Flow</a></li>
|
|
<li><a href="variables.html">Variables</a></li>
|
|
<li><a href="functions.html">Functions</a></li>
|
|
<li><a href="classes.html">Classes</a></li>
|
|
<li><a href="concurrency.html">Concurrency</a></li>
|
|
<li><a href="error-handling.html">Error Handling</a></li>
|
|
<li><a href="modularity.html">Modularity</a></li>
|
|
</ul>
|
|
</section>
|
|
<section>
|
|
<h2>reference</h2>
|
|
<ul>
|
|
<li><a href="modules">Modules</a></li>
|
|
<li><a href="embedding">Embedding</a></li>
|
|
<li><a href="performance.html">Performance</a></li>
|
|
<li><a href="qa.html">Q & A</a></li>
|
|
</ul>
|
|
</section>
|
|
</nav>
|
|
<nav class="small">
|
|
<table>
|
|
<tr>
|
|
<td><a href="getting-started.html">Getting Started</a></td>
|
|
<td><a href="contributing.html">Contributing</a></td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="2"><h2>language guide</h2></td>
|
|
<td><h2>reference</h2></td>
|
|
</tr>
|
|
<tr>
|
|
<td>
|
|
<ul>
|
|
<li><a href="syntax.html">Syntax</a></li>
|
|
<li><a href="values.html">Values</a></li>
|
|
<li><a href="lists.html">Lists</a></li>
|
|
<li><a href="maps.html">Maps</a></li>
|
|
<li><a href="method-calls.html">Method Calls</a></li>
|
|
<li><a href="control-flow.html">Control Flow</a></li>
|
|
</ul>
|
|
</td>
|
|
<td>
|
|
<ul>
|
|
<li><a href="variables.html">Variables</a></li>
|
|
<li><a href="functions.html">Functions</a></li>
|
|
<li><a href="classes.html">Classes</a></li>
|
|
<li><a href="concurrency.html">Concurrency</a></li>
|
|
<li><a href="error-handling.html">Error Handling</a></li>
|
|
<li><a href="modularity.html">Modularity</a></li>
|
|
</ul>
|
|
</td>
|
|
<td>
|
|
<ul>
|
|
<li><a href="modules">Modules</a></li>
|
|
<li><a href="embedding">Embedding</a></li>
|
|
<li><a href="performance.html">Performance</a></li>
|
|
<li><a href="qa.html">Q & A</a></li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</nav>
|
|
<main>
|
|
<h1>Getting Started</h1>
|
|
<p>Getting Wren running on your machine is straightforward. Tiny C programs with
|
|
few dependencies are nice that way. “Wren” encompasses two separate artifacts: </p>
|
|
<ul>
|
|
<li>
|
|
<p><strong>The virtual machine.</strong> This is the core chunk of C that executes Wren
|
|
source code. It is just a library, not a standalone application. It’s
|
|
designed to be <a href="embedding">embedded</a> in a larger host application. It has no
|
|
dependencies beyond the C standard library. You can use it as a static
|
|
library, shared library, or simply compile the source into your app. </p>
|
|
</li>
|
|
<li>
|
|
<p><strong>The command line executable.</strong> Wren also ships with a CLI wrapper around
|
|
the VM. This gives you a way to run Wren code from the command-line, and
|
|
also includes modules for talking to the operating system—file IO,
|
|
networking, stuff like that. It depends on <a href="http://libuv.org/">libuv</a> for that
|
|
functionality. </p>
|
|
</li>
|
|
</ul>
|
|
<p>If you’re on a Unix or Mac and you can rock a command line, it’s just: </p>
|
|
<div class="codehilite"><pre><span></span>$ git clone https://github.com/munificent/wren.git
|
|
$ <span class="nb">cd</span> wren
|
|
$ make
|
|
$ ./wren
|
|
</pre></div>
|
|
|
|
|
|
<p>This builds both the VM and the CLI. The release build of the CLI goes right
|
|
into the repo’s top level directory. Binaries for other configurations are built
|
|
to <code>bin/</code>. Static and shared libraries for embedding Wren get built in <code>lib/</code>. </p>
|
|
<p>For Mac users, there is also an XCode project under <code>util/xcode</code>. For
|
|
Windows brethren, <code>util/msvc2013</code> contains a Visual Studio solution. Note
|
|
that these may not have the exact same build settings as the makefile. The
|
|
makefile is the “official” way to compile Wren. </p>
|
|
<p>If you only want to build the VM, you can do: </p>
|
|
<div class="codehilite"><pre><span></span>$ make vm
|
|
</pre></div>
|
|
|
|
|
|
<p>This compiles the VM to static and shared libraries. </p>
|
|
<h2>Interactive mode <a href="#interactive-mode" name="interactive-mode" class="header-anchor">#</a></h2>
|
|
<p>If you just run <code>wren</code> without any arguments, it starts the interpreter in
|
|
interactive mode. You can type in a line of code, and it immediately executes
|
|
it. Here’s something to try: </p>
|
|
<div class="codehilite"><pre><span></span>System.print("Hello, world!")
|
|
</pre></div>
|
|
|
|
|
|
<p>Or a little more exciting: </p>
|
|
<div class="codehilite"><pre><span></span>for (i in 1..10) System.print("Counting up %(i)")
|
|
</pre></div>
|
|
|
|
|
|
<p>You can exit the interpreter using good old Ctrl-C or Ctrl-D, or just throw
|
|
your computer to the ground and storm off. </p>
|
|
<h2>Running scripts <a href="#running-scripts" name="running-scripts" class="header-anchor">#</a></h2>
|
|
<p>The standalone interpreter can also load scripts from files and run them. Just
|
|
pass the name of the script to <code>wren</code>. Create a file named “my_script.wren” in
|
|
your favorite text editor and paste this into it: </p>
|
|
<div class="codehilite"><pre><span></span>for (yPixel in 0...24) {
|
|
var y = yPixel / 12 - 1
|
|
for (xPixel in 0...80) {
|
|
var x = xPixel / 30 - 2
|
|
var x0 = x
|
|
var y0 = y
|
|
var iter = 0
|
|
while (iter < 11 && x0 * x0 + y0 * y0 <= 4) {
|
|
var x1 = (x0 * x0) - (y0 * y0) + x
|
|
var y1 = 2 * x0 * y0 + y
|
|
x0 = x1
|
|
y0 = y1
|
|
iter = iter + 1
|
|
}
|
|
System.write(" .-:;+=xX$& "[iter])
|
|
}
|
|
|
|
System.print("")
|
|
}
|
|
</pre></div>
|
|
|
|
|
|
<p>Now run: </p>
|
|
<div class="codehilite"><pre><span></span>$ ./wren my_script.wren
|
|
</pre></div>
|
|
|
|
|
|
<p>Neat, right? You’re a Wren programmer now! The next step is to <a href="syntax.html">learn the
|
|
language</a>. If you run into bugs, or have ideas or questions, any of
|
|
the following work: </p>
|
|
<ul>
|
|
<li><strong>Ask on the <a href="https://groups.google.com/forum/#!forum/wren-lang">Wren mailing list</a>.</strong> </li>
|
|
<li>Tell me on twitter at <a href="https://twitter.com/intent/user?screen_name=munificentbob">@munificentbob</a>. </li>
|
|
<li><a href="https://github.com/munificent/wren/issues">File a ticket</a> at <a href="https://github.com/munificent/wren">the GitHub repo</a>. </li>
|
|
<li>Send a pull request. </li>
|
|
<li>Email me at <a href="mailto:robert@stuffwithstuff.com"><code>robert@stuffwithstuff.com</code></a>. </li>
|
|
</ul>
|
|
</main>
|
|
</div>
|
|
<footer>
|
|
<div class="page">
|
|
<div class="main-column">
|
|
<p>Wren lives
|
|
<a href="https://github.com/munificent/wren">on GitHub</a>
|
|
— Made with ❤ by
|
|
<a href="http://journal.stuffwithstuff.com/">Bob Nystrom</a> and
|
|
<a href="https://github.com/munificent/wren/blob/master/AUTHORS">friends</a>.
|
|
</p>
|
|
<div class="main-column">
|
|
</div>
|
|
</footer>
|
|
</body>
|
|
</html>
|