1
0
forked from Mirror/wren

Merge pull request #751 from wren-lang/0.3.0-refactor

0.3.0 refactor
This commit is contained in:
ruby
2020-06-05 14:57:20 -07:00
committed by GitHub
parent 6ab4abe9e3
commit d585a080e8
476 changed files with 13159 additions and 93444 deletions

View File

@ -0,0 +1,30 @@
^title Wren CLI
---
## What is it?
**The Wren Command-Line Interface** is a tool you can run which gives you a way to run Wren code, and
also includes modules for talking to the operating system—file IO,
networking, stuff like that. It depends on [libuv][] for that
functionality.
Wren as a language is intentionally designed to be minimal.
That includes the built in language features, the standard library and the VM itself.
In order to access files, networks and other IO, you'd need to make a tool _using_ the language VM.
That's what the CLI project is! It is not bundled as part of the wren project,
instead it is it's own project as a standalone tool you can run.
It exposes it's own standard library and modules that may be of interest
if looking for a general purpose single binary scriptable tool.
Wren CLI is a work in progress, and contributions are welcome to make it more useful over time.
## Why does it exist?
- It's fun to make things.
- It's always a good idea to test the language you're making!
- Interest was expressed in a scriptable tool using the Wren language.
- It's helpful for others to learn from, since it is a real world usage example showing several concepts.
[libuv]: http://libuv.org/

View File

@ -0,0 +1,16 @@
^title CLI Modules
The Wren CLI executable extends the built in language modules with it's own,
which offer access to IO and other facilities for scripting.
The CLI modules are deeply tied to [libuv][], each other, and other internals
of the command-line app, so can't easily be separated out and pulled into host
applications that want to embed Wren. Scripts written for the CLI then,
are specific to the CLI unless another host implements the same API.
[libuv]: http://libuv.org
* [io](io)
* [os](os)
* [scheduler](scheduler)
* [timer](timer)

View File

@ -0,0 +1,15 @@
^title Directory Class
A directory on the file system.
## Static Methods
### Directory.**exists**(path)
Whether a directory exists at `path`. This returns `false` for files or other
special file system entities.
### Directory.**list**(path)
Lists the contents of the directory at `path`. Returns a sorted list of path
strings for all of the contents of the directory.

View File

@ -0,0 +1,48 @@
^title FileFlags Class
Contains constants for the various file flags used to open or create a file.
These correspond directly to the flags that can be passed to the POSIX
[`open()`][open] syscall.
[open]: http://linux.die.net/man/2/open
They are integers and can be bitwise or'ed together to produce a composite
flag.
## Static Methods
### FileFlags.**readOnly**
The file can be read from but not written. Equivalent to `O_RDONLY`.
### FileFlags.**writeOnly**
The file can be written but not read from. Equivalent to `O_WRONLY`.
### FileFlags.**readWrite**
The file can be both read from and written to. Equivalent to `O_RDWR`.
### FileFlags.**sync**
Writes will block until the data has been physically written to the underling
hardware. This does *not* affect whether or the file API is synchronous. File
operations are always asynchronous in Wren and may allow other scheduled fibers
to run.
This is a lower-level flag that ensures that when a write completes, it has
been flushed all the way to disc.
### FileFlags.**create**
Creates a new file if a file at the given path does not already exist.
### FileFlags.**truncate**
If the file already exists and can be written to, its previous contents are
discarded.
### FileFlags.**exclusive**
Ensures that a new file must be created. If a file already exists at the given
path, this flag will cause the operation to fail.

View File

@ -0,0 +1,138 @@
^title File Class
Lets you work with files on the file system. An instance of this class
represents an open file with a file descriptor.
When you are done with a file object, it's a good idea to explicitly close it.
If you don't, the GC will close it when the file is no longer used and gets
finalized, but that may take a while. In the meantime, leaving it open wastes
a file descriptor.
## Static Methods
### File.**create**(path, fn)
Opens the file at `path` for writing and passes it to `fn`. If there is already
a file at that path, it is truncated. After the function returns, the file is
automatically closed.
<pre class="snippet">
File.create("numbers.txt") {|file|
file.writeBytes("one two three")
}
</pre>
### File.**delete**(path)
Deletes the file at `path`.
### File.**exists**(path)
Whether a regular file exists at `path`. This returns `false` for directories
or other special file system entities.
### File.**open**(path, fn)
Opens the file at `path` for reading and passes it to `fn`. After the function
returns, the file is automatically closed.
<pre class="snippet">
File.open("words.txt") {|file|
file.readBytes(5)
}
</pre>
### File.**read**(path)
Reads the entire contents of the file at `path` and returns it as a string.
<pre class="snippet">
File.read("words.txt")
</pre>
No encoding or decoding is done. If the file is UTF-8, then the resulting
string will be a UTF-8 string. Otherwise, it will be a string of bytes in
whatever encoding the file uses.
### File.**realPath**(path)
Resolves `path`, traversing symlinks and removining any unneeded `./` and `../`
components. Returns the canonical absolute path to the file.
<pre class="snippet">
var path = "/some/./symlink/a/../b/file.txt"
System.print(File.realPath(path)) //> /real/path/a/file.txt
</pre>
### File.**size**(path)
Returns the size in bytes of the contents of the file at `path`.
## Constructors
### File.**create**(path)
Opens the file at `path` for writing. If there is already a file at that path,
it is truncated.
<pre class="snippet">
var file = File.create("colors.txt")
file.writeBytes("chartreuse lime teal")
file.close()
</pre>
### File.**open**(path)
Opens the file at `path` for reading. You are responsible for closing it when
done with it.
## Methods
### **descriptor**
The numeric file descriptor used to access the file.
### **isOpen**
Whether the file is still open or has been closed.
### **size**
The size of the contents of the file in bytes.
### **close**()
Closes the file. After calling this, you can't read or write from it.
### **readBytes**(count)
Reads up to `count` bytes starting from the beginning of the file.
<pre class="snippet">
// Assume this file contains "I am a file!".
File.open("example.txt") {|file|
System.print(file.readBytes(6)) //> I am a
}
</pre>
### **readBytes**(count, offset)
Reads up to `count` bytes starting at `offset` bytes from the beginning of
the file.
<pre class="snippet">
// Assume this file contains "I am a file!".
File.open("example.txt") {|file|
System.print(file.readBytes(6, 2)) //> am a f
}
</pre>
### **writeBytes**(bytes)
Writes the raw bytes of the string `bytes` to the end of the file.
### **writeBytes**(bytes, offset)
Writes the raw bytes of the string `bytes` to the to the file, starting at
`offset`. Any overlapping bytes already in the file at the offset are
overwritten.

View File

@ -0,0 +1,9 @@
^title Module "io"
Provides access to operating system streams and the file system.
* [Directory](directory.html)
* [File](file.html)
* [Stat](stat.html)
* [Stdin](stdin.html)
* [Stdout](stdout.html)

View File

@ -0,0 +1,63 @@
^title Stat Class
A data structure describing the low-level details of a file system entry.
## Static Methods
### Stat.**path**(path)
"Stats" the file or directory at `path`.
## Methods
### **blockCount**
The number of system blocks allocated on disk for the file.
### **blockSize**
The preferred block size in bytes for interacting with the file. It may vary
from file to file.
### **device**
The ID of the device containing the entry.
### **group**
Numeric group ID of the file's owner.
### **inode**
The [inode][] number of the entry.
[inode]: https://en.wikipedia.org/wiki/Inode
### **isDirectory**
Whether the file system entity is a directory.
### **isFile**
Whether the file system entity is a regular file, as opposed to a directory or
other special entity.
### **linkCount**
The number of hard links to the entry.
### **mode**
A bit field describing the entry's type and protection flags.
### **size**
The size of the entry in bytes.
### **specialDevice**
The device ID for the entry, if it's a special file.
### **user**
Numeric user ID of the file's owner.

View File

@ -0,0 +1,45 @@
^title Stdin Class
The standard input stream.
## Static Methods
### **isRaw**
Returns `true` if stdin is in raw mode. When in raw mode, input is not echoed
or buffered, and all characters, even non-printing and control characters go
into stdin.
Defaults to `false`.
### **isRaw**=(value)
Sets raw mode on or off.
### **isTerminal**
Returns `true` if Stdin is connected to a "TTY". This is true when the user is
running Wren in an interactive terminal, and false if it its input is coming
from a pipe.
### **readByte**()
Reads one byte of input from stdin. Blocks the current fiber until a byte has
been received.
Returns the byte value as a number or `null` if stdin is closed.
Note that output is not automatically flushed when calling this. If you want to
display a prompt before reading input, you'll want to call `Stdout.flush()`
after printing the prompt.
### **readLine**()
Reads one line of input from stdin. Blocks the current fiber until a full line
of input has been received.
Returns the string of input or `null` if stdin is closed.
Note that output is not automatically flushed when calling this. If you want to
display a prompt before reading input, you'll want to call `Stdout.flush()`
after printing the prompt.

View File

@ -0,0 +1,11 @@
^title Stdout Class
The standard output stream.
## Static Methods
### **flush()**
Flushes all buffered data to the stream. Ensures any data written to stdout
that is in the buffer gets written to the file or terminal that stdout is
connected to.

View File

@ -0,0 +1,89 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>{title} &ndash; Wren</title>
<script type="application/javascript" src="../../../prism.js" data-manual></script>
<script type="application/javascript" src="../../../wren.js"></script>
<link rel="stylesheet" type="text/css" href="../../../prism.css" />
<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" class="module">
<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">
<a href="../../../"><img src="../../../wren.svg" class="logo"></a>
<ul>
<li><a href="../../">Back to Wren CLI</a></li>
<li><a href="../">Back to CLI Modules</a></li>
<li><a href="./">io module</a></li>
</ul>
<section>
<h2>io classes</h2>
<ul>
<li><a href="directory.html">Directory</a></li>
<li><a href="file.html">File</a></li>
<li><a href="file-flags.html">FileFlags</a></li>
<li><a href="stat.html">Stat</a></li>
<li><a href="stdin.html">Stdin</a></li>
<li><a href="stdout.html">Stdout</a></li>
</ul>
</section>
</nav>
<nav class="small">
<table>
<tr>
<td><a href="../">Back to CLI Modules</a></td>
<td><a href="./">io module</a></td>
</tr>
<tr>
<td colspan="2"><h2>io classes</h2></td>
</tr>
<tr>
<td>
<ul>
<li><a href="directory.html">Directory</a></li>
<li><a href="file.html">File</a></li>
<li><a href="file-flags.html">FileFlags</a></li>
</ul>
</td>
<td>
<ul>
<li><a href="stat.html">Stat</a></li>
<li><a href="stdin.html">Stdin</a></li>
<li><a href="stdout.html">Stdout</a></li>
</ul>
</td>
</tr>
</table>
</nav>
<main>
<h1>{title}</h1>
{html}
</main>
</div>
<footer>
<div class="page">
<div class="main-column">
<p>Wren lives
<a href="https://github.com/wren-lang/wren">on GitHub</a>
&mdash; Made with &#x2764; by
<a href="http://journal.stuffwithstuff.com/">Bob Nystrom</a> and
<a href="https://github.com/wren-lang/wren/blob/master/AUTHORS">friends</a>.
</p>
<div class="main-column">
</div>
</footer>
</body>
</html>

View File

@ -0,0 +1,7 @@
^title Module "os"
The os module exposes classes for accessing capabilities provided by the
underlying operating system.
* [Platform](platform.html)
* [Process](process.html)

View File

@ -0,0 +1,30 @@
^title Platform Class
The Platform class exposes basic information about the operating system Wren is
running on top of.
## Static Methods
### **name**
The name of the platform. This roughly describes the operating system, and is
usually one of:
* "iOS"
* "Linux"
* "OS X"
* "POSIX"
* "Unix"
* "Windows"
If Wren was compiled for an unknown operating system, returns "Unknown".
### **isPosix**
Returns `true` if the host operating system is known to support the POSIX
standard. This is true for Linux and other Unices, as well as the various Apple
operating systems.
### **isWindows**
Returns `true` if the host operating system is some flavor of Windows.

View File

@ -0,0 +1,38 @@
^title Process Class
The Process class lets you work with operating system processes, including the
currently running one.
## Static Methods
### **allArguments**
The list of command-line arguments that were passed when the Wren process was
spawned. This includes the Wren executable itself, the path to the file being
run (if any), and any other options passed to Wren itself.
If you run:
$ wren file.wren arg
This returns:
<pre class="snippet">
System.print(Process.allArguments) //> ["wren", "file.wren", "arg"]
</pre>
### **arguments**
The list of command-line arguments that were passed to your program when the
Wren process was spawned. This does not include arguments handled by Wren
itself.
If you run:
$ wren file.wren arg
This returns:
<pre class="snippet">
System.print(Process.arguments) //> ["arg"]
</pre>

View File

@ -0,0 +1,81 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>{title} &ndash; Wren</title>
<script type="application/javascript" src="../../../prism.js" data-manual></script>
<script type="application/javascript" src="../../../wren.js"></script>
<link rel="stylesheet" type="text/css" href="../../../prism.css" />
<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" class="module">
<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">
<a href="../../../"><img src="../../../wren.svg" class="logo"></a>
<ul>
<li><a href="../../">Back to Wren CLI</a></li>
<li><a href="../">Back to CLI Modules</a></li>
<li><a href="./">os module</a></li>
</ul>
<section>
<h2>os classes</h2>
<ul>
<li><a href="platform.html">Platform</a></li>
<li><a href="process.html">Process</a></li>
</ul>
</section>
</nav>
<nav class="small">
<table>
<tr>
<td><a href="../">Back to CLI Modules</a></td>
<td><a href="./">os module</a></td>
</tr>
<tr>
<td colspan="2"><h2>os classes</h2></td>
</tr>
<tr>
<td>
<ul>
<li><a href="platform.html">Platform</a></li>
<li><a href="process.html">Process</a></li>
</ul>
</td>
<td>
<ul>
</ul>
</td>
</tr>
</table>
</nav>
<main>
<h1>{title}</h1>
{html}
</main>
</div>
<footer>
<div class="page">
<div class="main-column">
<p>Wren lives
<a href="https://github.com/wren-lang/wren">on GitHub</a>
&mdash; Made with &#x2764; by
<a href="http://journal.stuffwithstuff.com/">Bob Nystrom</a> and
<a href="https://github.com/wren-lang/wren/blob/master/AUTHORS">friends</a>.
</p>
<div class="main-column">
</div>
</footer>
</body>
</html>

View File

@ -0,0 +1,5 @@
^title Module "scheduler"
**TODO**
* [Scheduler](scheduler.html)

View File

@ -0,0 +1,7 @@
^title Scheduler Class
**TODO**
## Methods
**TODO**

View File

@ -0,0 +1,79 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>{title} &ndash; Wren</title>
<script type="application/javascript" src="../../../prism.js" data-manual></script>
<script type="application/javascript" src="../../../wren.js"></script>
<link rel="stylesheet" type="text/css" href="../../../prism.css" />
<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" class="module">
<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">
<a href="../../../"><img src="../../../wren.svg" class="logo"></a>
<ul>
<li><a href="../../">Back to Wren CLI</a></li>
<li><a href="../">Back to CLI Modules</a></li>
<li><a href="./">scheduler module</a></li>
</ul>
<section>
<h2>scheduler classes</h2>
<ul>
<li><a href="scheduler.html">Scheduler</a></li>
</ul>
</section>
</nav>
<nav class="small">
<table>
<tr>
<td><a href="../">Back to CLI Modules</a></td>
<td><a href="./">scheduler module</a></td>
</tr>
<tr>
<td colspan="2"><h2>scheduler classes</h2></td>
</tr>
<tr>
<td>
<ul>
<li><a href="scheduler.html">Scheduler</a></li>
</ul>
</td>
<td>
<ul>
</ul>
</td>
</tr>
</table>
</nav>
<main>
<h1>{title}</h1>
{html}
</main>
</div>
<footer>
<div class="page">
<div class="main-column">
<p>Wren lives
<a href="https://github.com/wren-lang/wren">on GitHub</a>
&mdash; Made with &#x2764; by
<a href="http://journal.stuffwithstuff.com/">Bob Nystrom</a> and
<a href="https://github.com/wren-lang/wren/blob/master/AUTHORS">friends</a>.
</p>
<div class="main-column">
</div>
</footer>
</body>
</html>

View File

@ -0,0 +1,94 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>{title} &ndash; Wren</title>
<script type="application/javascript" src="../../prism.js" data-manual></script>
<script type="application/javascript" src="../../wren.js"></script>
<link rel="stylesheet" type="text/css" href="../../prism.css" />
<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" class="module">
<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">
<a href="../../"><img src="../../wren.svg" class="logo"></a>
<ul>
<li><a href="../">Back to Wren CLI</a></li>
</ul>
<section>
<h2>Built In</h2>
<ul>
<li><a href="../../modules">Wren modules</a></li>
</ul>
</section>
<section>
<h2>CLI modules</h2>
<ul>
<li><a href="io">io</a></li>
<li><a href="os">os</a></li>
<li><a href="scheduler">scheduler</a></li>
<li><a href="timer">timer</a></li>
</ul>
</section>
</nav>
<nav class="small">
<table>
<tr>
<td><h2>core</h2></td>
<td><h2>optional</h2></td>
<td><h2>cli</h2></td>
</tr>
<tr>
<td>
<ul>
<li><a href="core">core</a></li>
</ul>
</td>
<td>
<ul>
<li><a href="meta">meta</a></li>
<li><a href="random">random</a></li>
</ul>
</td>
<td>
<ul>
<li><a href="io">io</a></li>
<li><a href="os">os</a></li>
<li><a href="scheduler">scheduler</a></li>
<li><a href="timer">timer</a></li>
</ul>
</td>
</tr>
</table>
</nav>
<main>
<h1>{title}</h1>
{html}
</main>
</div>
<footer>
<div class="page">
<div class="main-column">
<p>Wren lives
<a href="https://github.com/wren-lang/wren">on GitHub</a>
&mdash; Made with &#x2764; by
<a href="http://journal.stuffwithstuff.com/">Bob Nystrom</a> and
<a href="https://github.com/wren-lang/wren/blob/master/AUTHORS">friends</a>.
</p>
<div class="main-column">
</div>
</footer>
</body>
</html>

View File

@ -0,0 +1,5 @@
^title Module "timer"
**TODO**
* [Timer](timer.html)

View File

@ -0,0 +1,79 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>{title} &ndash; Wren</title>
<script type="application/javascript" src="../../../prism.js" data-manual></script>
<script type="application/javascript" src="../../../wren.js"></script>
<link rel="stylesheet" type="text/css" href="../../../prism.css" />
<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" class="module">
<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">
<a href="../../../"><img src="../../../wren.svg" class="logo"></a>
<ul>
<li><a href="../../">Back to Wren CLI</a></li>
<li><a href="../">Back to CLI Modules</a></li>
<li><a href="./">timer module</a></li>
</ul>
<section>
<h2>timer classes</h2>
<ul>
<li><a href="timer.html">Timer</a></li>
</ul>
</section>
</nav>
<nav class="small">
<table>
<tr>
<td><a href="../">Back to CLI Modules</a></td>
<td><a href="./">timer module</a></td>
</tr>
<tr>
<td colspan="2"><h2>timer classes</h2></td>
</tr>
<tr>
<td>
<ul>
<li><a href="timer.html">Timer</a></li>
</ul>
</td>
<td>
<ul>
</ul>
</td>
</tr>
</table>
</nav>
<main>
<h1>{title}</h1>
{html}
</main>
</div>
<footer>
<div class="page">
<div class="main-column">
<p>Wren lives
<a href="https://github.com/wren-lang/wren">on GitHub</a>
&mdash; Made with &#x2764; by
<a href="http://journal.stuffwithstuff.com/">Bob Nystrom</a> and
<a href="https://github.com/wren-lang/wren/blob/master/AUTHORS">friends</a>.
</p>
<div class="main-column">
</div>
</footer>
</body>
</html>

View File

@ -0,0 +1,7 @@
^title Timer Class
**TODO**
## Methods
**TODO**

View File

@ -0,0 +1,88 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>{title} &ndash; Wren</title>
<script type="application/javascript" src="../prism.js" data-manual></script>
<script type="application/javascript" src="../wren.js"></script>
<link rel="stylesheet" type="text/css" href="../prism.css" />
<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">
<a href="../"><img src="../wren.svg" class="logo"></a>
<ul>
<li><a href="../">Back to Wren</a></li>
</ul>
<section>
<h2>Wren CLI</h2>
<ul>
<li><a href="./">About</a></li>
<li><a target="_blank" href="https://github.com/wren-lang/wren-cli/releases">Downloads</a></li>
<li><a href="usage.html">Usage</a></li>
</ul>
</section>
<section>
<h2>API docs</h2>
<ul>
<li><a href="modules">CLI Modules</a></li>
</ul>
</section>
</nav>
<nav class="small">
<table>
<tr>
<div><a href="../">Back to Wren</a></div>
</tr>
<tr>
<td><h2>CLI</h2></td>
<td><h2>API</h2></td>
</tr>
<tr>
<td>
<ul>
<li><a href="./">About</a></li>
<li><a target="_blank" href="https://github.com/wren-lang/wren-cli/releases">Downloads</a></li>
<li><a href="usage.html">Usage</a></li>
</ul>
</td>
<td>
<ul>
<li><a href="modules">CLI Modules</a></li>
</ul>
</td>
</tr>
</table>
</nav>
<main>
<h2>{title}</h2>
{html}
</main>
</div>
<footer>
<div class="page">
<div class="main-column">
<p>Wren lives
<a href="https://github.com/wren-lang/wren">on GitHub</a>
&mdash; Made with &#x2764; by
<a href="http://journal.stuffwithstuff.com/">Bob Nystrom</a> and
<a href="https://github.com/wren-lang/wren/blob/master/AUTHORS">friends</a>.
</p>
<div class="main-column">
</div>
</footer>
</body>
</html>

View File

@ -0,0 +1,55 @@
^title Wren CLI Usage
---
You can [download a build for your OS from the releases page](https://github.com/wren-lang/wren-cli/releases).
### Interactive mode
If you just run `wren` without any arguments, it starts the interpreter in
interactive mode, where you can type in a line of code, and it immediately executes
it. You can exit the interpreter using good old Ctrl-C or Ctrl-D.
Here's something to try:
<pre class="snippet">
System.print("Hello, world!")
</pre>
Or a little more exciting:
<pre class="snippet">
for (i in 1..10) System.print("Counting up %(i)")
</pre>
### Running scripts
The standalone interpreter can also load scripts from files and run them. Just
pass the name of the script to `wren`. Create a file named "my_script.wren" in
your favorite text editor and paste this into it:
<pre class="snippet">
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>
Now run:
$ ./wren my_script.wren