2014-04-09 07:53:30 -07:00
|
|
|
^title Getting Started
|
|
|
|
|
|
2015-09-22 21:19:38 -07:00
|
|
|
Getting Wren running on your machine is straightforward. Tiny C programs with
|
|
|
|
|
few dependencies are nice that way. "Wren" encompasses two separate artifacts:
|
2015-08-30 22:38:40 -07:00
|
|
|
|
|
|
|
|
* **The virtual machine.** This is the core chunk of C that executes Wren
|
|
|
|
|
source code. It is just a library, not a standalone application. It's
|
2015-09-22 21:19:38 -07:00
|
|
|
designed to be [embedded][] in a larger host application. It has no
|
2016-05-02 02:39:11 +04:30
|
|
|
dependencies beyond the C standard library. You can use it as a static
|
2015-09-22 21:19:38 -07:00
|
|
|
library, shared library, or simply compile the source into your app.
|
2015-08-30 22:38:40 -07:00
|
|
|
|
|
|
|
|
* **The command line executable.** Wren also ships with a CLI wrapper around
|
|
|
|
|
the VM. This gives you a way to run Wren code from the command-line, and
|
2015-09-22 21:19:38 -07:00
|
|
|
also includes modules for talking to the operating system—file IO,
|
|
|
|
|
networking, stuff like that. It depends on [libuv][] for that
|
|
|
|
|
functionality.
|
2015-08-30 22:38:40 -07:00
|
|
|
|
2017-10-31 21:47:51 +01:00
|
|
|
[embedded]: embedding
|
2015-08-30 22:38:40 -07:00
|
|
|
[libuv]: http://libuv.org/
|
|
|
|
|
|
|
|
|
|
If you're on a Unix or Mac and you can rock a command line, it's just:
|
2014-04-09 07:53:30 -07:00
|
|
|
|
2015-09-22 21:19:38 -07:00
|
|
|
:::sh
|
2019-02-05 18:41:31 -08:00
|
|
|
$ git clone https://github.com/wren-lang/wren.git
|
2014-04-09 07:53:30 -07:00
|
|
|
$ cd wren
|
|
|
|
|
$ make
|
|
|
|
|
$ ./wren
|
|
|
|
|
|
2017-04-09 09:31:44 -07:00
|
|
|
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 `bin/`. Static and shared libraries for embedding Wren get built in `lib/`.
|
2015-02-22 10:19:23 -08:00
|
|
|
|
2015-09-22 21:19:38 -07:00
|
|
|
For Mac users, there is also an XCode project under `util/xcode`. For
|
2019-03-24 21:32:04 +01:00
|
|
|
Windows brethren, `util/vs2017` contains a Visual Studio solution. Note
|
2015-01-23 10:41:11 -08:00
|
|
|
that these may not have the exact same build settings as the makefile. The
|
|
|
|
|
makefile is the "official" way to compile Wren.
|
2014-04-09 07:53:30 -07:00
|
|
|
|
2015-08-30 22:38:40 -07:00
|
|
|
If you only want to build the VM, you can do:
|
|
|
|
|
|
2015-09-22 21:19:38 -07:00
|
|
|
:::sh
|
2015-08-30 22:38:40 -07:00
|
|
|
$ make vm
|
|
|
|
|
|
2017-04-09 09:31:44 -07:00
|
|
|
This compiles the VM to static and shared libraries.
|
2015-08-30 22:38:40 -07:00
|
|
|
|
2014-04-09 07:53:30 -07:00
|
|
|
## Interactive mode
|
|
|
|
|
|
2015-09-22 21:19:38 -07:00
|
|
|
If you just run `wren` 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:
|
2014-04-09 07:53:30 -07:00
|
|
|
|
2015-09-22 07:59:54 -07:00
|
|
|
:::wren
|
2015-09-15 07:46:09 -07:00
|
|
|
System.print("Hello, world!")
|
2014-04-09 07:53:30 -07:00
|
|
|
|
|
|
|
|
Or a little more exciting:
|
|
|
|
|
|
2015-09-22 07:59:54 -07:00
|
|
|
:::wren
|
2015-11-21 09:20:50 -08:00
|
|
|
for (i in 1..10) System.print("Counting up %(i)")
|
2014-04-09 07:53:30 -07:00
|
|
|
|
2015-01-03 23:27:02 -08:00
|
|
|
You can exit the interpreter using good old Ctrl-C or Ctrl-D, or just throw
|
|
|
|
|
your computer to the ground and storm off.
|
2014-04-09 07:53:30 -07:00
|
|
|
|
|
|
|
|
## Running scripts
|
|
|
|
|
|
2015-01-03 23:27:02 -08:00
|
|
|
The standalone interpreter can also load scripts from files and run them. Just
|
2015-09-22 21:19:38 -07:00
|
|
|
pass the name of the script to `wren`. Create a file named "my_script.wren" in
|
2015-01-03 23:27:02 -08:00
|
|
|
your favorite text editor and paste this into it:
|
2014-04-09 07:53:30 -07:00
|
|
|
|
2015-09-22 07:59:54 -07:00
|
|
|
:::wren
|
2014-04-09 07:53:30 -07:00
|
|
|
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
|
|
|
|
|
}
|
2015-09-15 07:46:09 -07:00
|
|
|
System.write(" .-:;+=xX$& "[iter])
|
2014-04-09 07:53:30 -07:00
|
|
|
}
|
|
|
|
|
|
2015-09-15 07:46:09 -07:00
|
|
|
System.print("")
|
2014-04-09 07:53:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Now run:
|
|
|
|
|
|
2015-09-22 21:19:38 -07:00
|
|
|
:::sh
|
2014-08-19 07:35:20 -07:00
|
|
|
$ ./wren my_script.wren
|
2014-04-09 07:53:30 -07:00
|
|
|
|
2015-11-07 11:09:04 -08:00
|
|
|
Neat, right? You're a Wren programmer now! The next step is to [learn the
|
|
|
|
|
language](syntax.html). If you run into bugs, or have ideas or questions, any of
|
|
|
|
|
the following work:
|
2014-04-09 07:53:30 -07:00
|
|
|
|
2015-01-20 17:46:52 -08:00
|
|
|
* **Ask on the [Wren mailing list][list].**
|
|
|
|
|
* Tell me on twitter at [@munificentbob][twitter].
|
|
|
|
|
* [File a ticket][issue] at [the GitHub repo][repo].
|
2014-04-11 10:45:20 -07:00
|
|
|
* Send a pull request.
|
2015-01-03 23:27:02 -08:00
|
|
|
* Email me at [`robert@stuffwithstuff.com`](mailto:robert@stuffwithstuff.com).
|
2015-01-20 17:46:52 -08:00
|
|
|
|
|
|
|
|
[list]: https://groups.google.com/forum/#!forum/wren-lang
|
|
|
|
|
[twitter]: https://twitter.com/intent/user?screen_name=munificentbob
|
2019-02-05 18:41:31 -08:00
|
|
|
[issue]: https://github.com/wren-lang/wren/issues
|
|
|
|
|
[repo]: https://github.com/wren-lang/wren
|