2015-01-01 21:04:14 -08:00
<!DOCTYPE html>
< html >
< head >
< meta http-equiv = "Content-type" content = "text/html;charset=UTF-8" / >
2015-11-09 08:01:19 -08:00
< title > Getting Started – Wren< / title >
2015-01-01 21:04:14 -08:00
< link rel = "stylesheet" type = "text/css" href = "style.css" / >
2015-01-15 21:18:18 -08:00
< 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' >
2015-01-01 21:04:14 -08:00
<!-- 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" >
2015-01-18 15:37:50 -08:00
< h1 > < a href = "./" > wren< / a > < / h1 >
2015-01-01 21:04:14 -08:00
< h2 > a classy little scripting language< / h2 >
< / div >
< / div >
< / header >
< div class = "page" >
2015-11-09 08:01:19 -08:00
< nav class = "big" >
2015-01-01 21:04:14 -08:00
< ul >
< li > < a href = "getting-started.html" > Getting Started< / a > < / li >
2015-11-09 08:01:19 -08:00
< li > < a href = "contributing.html" > Contributing< / a > < / li >
2015-01-01 21:04:14 -08:00
< / ul >
< section >
2015-11-09 08:01:19 -08:00
< h2 > language guide< / h2 >
2015-01-01 21:04:14 -08:00
< 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 >
2015-11-09 08:01:19 -08:00
< 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 >
2015-01-01 21:04:14 -08:00
< / ul >
< / section >
< section >
< h2 > reference< / h2 >
< ul >
2015-11-09 08:01:19 -08:00
< li > < a href = "modules" > Modules< / a > < / li >
2017-10-19 07:05:45 -07:00
< li > < a href = "embedding" > Embedding< / a > < / li >
2015-01-01 21:04:14 -08:00
< li > < a href = "performance.html" > Performance< / a > < / li >
< li > < a href = "qa.html" > Q & A< / a > < / li >
< / ul >
< / section >
< / nav >
2015-11-09 08:01:19 -08:00
< 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 >
2017-10-19 07:05:45 -07:00
< li > < a href = "embedding" > Embedding< / a > < / li >
2015-11-09 08:01:19 -08:00
< li > < a href = "performance.html" > Performance< / a > < / li >
< li > < a href = "qa.html" > Q & A< / a > < / li >
< / ul >
< / td >
< / tr >
< / table >
< / nav >
2015-01-01 21:04:14 -08:00
< main >
< h1 > Getting Started< / h1 >
2015-11-09 08:01:19 -08:00
< 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 >
2015-09-11 21:39:04 -07:00
< ul >
< li >
2015-11-09 08:01:19 -08:00
< 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-api.html" > embedded< / a > in a larger host application. It has no
2016-12-05 08:17:54 +09:00
dependencies beyond the C standard library. You can use it as a static
2015-11-09 08:01:19 -08:00
library, shared library, or simply compile the source into your app. < / p >
2015-09-11 21:39:04 -07:00
< / li >
< li >
2015-11-09 08:01:19 -08:00
< 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 >
2015-09-11 21:39:04 -07:00
< / li >
< / ul >
2015-11-09 08:01:19 -08:00
< p > If you’ re on a Unix or Mac and you can rock a command line, it’ s just: < / p >
2017-10-19 07:05:45 -07:00
< div class = "codehilite" > < pre > < span > < / span > $ git clone https://github.com/munificent/wren.git
$ < span class = "nb" > cd< / span > wren
$ make
$ ./wren
2015-01-01 21:04:14 -08:00
< / pre > < / div >
2015-11-09 08:01:19 -08:00
< p > This builds both the VM and the CLI. It downloads libuv automatically for you.
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 >
2017-10-19 07:05:45 -07:00
< div class = "codehilite" > < pre > < span > < / span > $ make vm
2015-09-11 21:39:04 -07:00
< / pre > < / div >
2015-11-09 08:01:19 -08:00
< p > This compiles the VM to static and shared libraries. It does not even download
libuv since it isn’ t needed. < / p >
2015-01-01 21:04:14 -08:00
< h2 > Interactive mode < a href = "#interactive-mode" name = "interactive-mode" class = "header-anchor" > #< / a > < / h2 >
2015-11-09 08:01:19 -08:00
< 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 >
2017-10-19 07:05:45 -07:00
< div class = "codehilite" > < pre > < span > < / span > < span class = "vg" > System< / span > < span class = "o" > .< / span > < span class = "n" > print< / span > < span class = "p" > (< / span > < span class = "s" > " Hello, world!" < / span > < span class = "p" > )< / span >
2015-01-01 21:04:14 -08:00
< / pre > < / div >
2015-11-09 08:01:19 -08:00
< p > Or a little more exciting: < / p >
2017-10-19 07:05:45 -07:00
< div class = "codehilite" > < pre > < span > < / span > < span class = "k" > for< / span > < span class = "p" > (< / span > < span class = "err" > i< / span > < span class = "k" > in< / span > < span class = "mi" > 1< / span > < span class = "o" > ..< / span > < span class = "mi" > 10< / span > < span class = "p" > )< / span > < span class = "vg" > System< / span > < span class = "o" > .< / span > < span class = "n" > print< / span > < span class = "p" > (< / span > < span class = "s" > " Counting up < / span > < span class = "si" > %(< / span > < span class = "err" > i< / span > < span class = "si" > )< / span > < span class = "s" > " < / span > < span class = "p" > )< / span >
2015-01-01 21:04:14 -08:00
< / pre > < / div >
2015-11-09 08:01:19 -08:00
< 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 >
2015-01-01 21:04:14 -08:00
< h2 > Running scripts < a href = "#running-scripts" name = "running-scripts" class = "header-anchor" > #< / a > < / h2 >
2015-11-09 08:01:19 -08:00
< 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 >
2017-10-19 07:05:45 -07:00
< div class = "codehilite" > < pre > < span > < / span > < span class = "k" > for< / span > < span class = "p" > (< / span > < span class = "n" > yPixel< / span > < span class = "k" > in< / span > < span class = "mi" > 0< / span > < span class = "o" > ...< / span > < span class = "mi" > 24< / span > < span class = "p" > )< / span > < span class = "p" > {< / span >
2015-11-09 08:01:19 -08:00
< span class = "k" > var< / span > < span class = "err" > y< / span > < span class = "o" > =< / span > < span class = "n" > yPixel< / span > < span class = "o" > /< / span > < span class = "mi" > 12< / span > < span class = "o" > -< / span > < span class = "mi" > 1< / span >
< span class = "k" > for< / span > < span class = "p" > (< / span > < span class = "n" > xPixel< / span > < span class = "k" > in< / span > < span class = "mi" > 0< / span > < span class = "o" > ...< / span > < span class = "mi" > 80< / span > < span class = "p" > )< / span > < span class = "p" > {< / span >
< span class = "k" > var< / span > < span class = "err" > x< / span > < span class = "o" > =< / span > < span class = "n" > xPixel< / span > < span class = "o" > /< / span > < span class = "mi" > 30< / span > < span class = "o" > -< / span > < span class = "mi" > 2< / span >
< span class = "k" > var< / span > < span class = "n" > x0< / span > < span class = "o" > =< / span > < span class = "err" > x< / span >
< span class = "k" > var< / span > < span class = "n" > y0< / span > < span class = "o" > =< / span > < span class = "err" > y< / span >
< span class = "k" > var< / span > < span class = "n" > iter< / span > < span class = "o" > =< / span > < span class = "mi" > 0< / span >
< span class = "k" > while< / span > < span class = "p" > (< / span > < span class = "n" > iter< / span > < span class = "o" > < < / span > < span class = "mi" > 11< / span > < span class = "o" > & & < / span > < span class = "n" > x0< / span > < span class = "o" > *< / span > < span class = "n" > x0< / span > < span class = "o" > +< / span > < span class = "n" > y0< / span > < span class = "o" > *< / span > < span class = "n" > y0< / span > < span class = "o" > < =< / span > < span class = "mi" > 4< / span > < span class = "p" > )< / span > < span class = "p" > {< / span >
< span class = "k" > var< / span > < span class = "n" > x1< / span > < span class = "o" > =< / span > < span class = "p" > (< / span > < span class = "n" > x0< / span > < span class = "o" > *< / span > < span class = "n" > x0< / span > < span class = "p" > )< / span > < span class = "o" > -< / span > < span class = "p" > (< / span > < span class = "n" > y0< / span > < span class = "o" > *< / span > < span class = "n" > y0< / span > < span class = "p" > )< / span > < span class = "o" > +< / span > < span class = "err" > x< / span >
< span class = "k" > var< / span > < span class = "n" > y1< / span > < span class = "o" > =< / span > < span class = "mi" > 2< / span > < span class = "o" > *< / span > < span class = "n" > x0< / span > < span class = "o" > *< / span > < span class = "n" > y0< / span > < span class = "o" > +< / span > < span class = "err" > y< / span >
< span class = "n" > x0< / span > < span class = "o" > =< / span > < span class = "n" > x1< / span >
< span class = "n" > y0< / span > < span class = "o" > =< / span > < span class = "n" > y1< / span >
< span class = "n" > iter< / span > < span class = "o" > =< / span > < span class = "n" > iter< / span > < span class = "o" > +< / span > < span class = "mi" > 1< / span >
< span class = "p" > }< / span >
< span class = "vg" > System< / span > < span class = "o" > .< / span > < span class = "n" > write< / span > < span class = "p" > (< / span > < span class = "s" > " .-:;+=xX$& " < / span > < span class = "p" > [< / span > < span class = "n" > iter< / span > < span class = "p" > ])< / span >
2015-01-01 21:04:14 -08:00
< span class = "p" > }< / span >
2015-11-09 08:01:19 -08:00
< span class = "vg" > System< / span > < span class = "o" > .< / span > < span class = "n" > print< / span > < span class = "p" > (< / span > < span class = "s" > " " < / span > < span class = "p" > )< / span >
2015-01-01 21:04:14 -08:00
< span class = "p" > }< / span >
< / pre > < / div >
2015-11-09 08:01:19 -08:00
< p > Now run: < / p >
2017-10-19 07:05:45 -07:00
< div class = "codehilite" > < pre > < span > < / span > $ ./wren my_script.wren
2015-01-01 21:04:14 -08:00
< / pre > < / div >
2015-11-09 08:01:19 -08:00
< 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 >
2015-01-01 21:04:14 -08:00
< ul >
2015-11-09 08:01:19 -08:00
< 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 >
2015-01-01 21:04:14 -08:00
< / ul >
< / main >
< / div >
< footer >
< div class = "page" >
< div class = "main-column" >
2015-11-09 08:01:19 -08:00
< 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 >
2015-01-01 21:04:14 -08:00
< div class = "main-column" >
< / div >
< / footer >
< / body >
2015-04-25 08:50:08 -07:00
< / html >