Merge branch 'master' into smarter-imports

# Conflicts:
#	src/module/io.c
#	src/vm/wren_vm.c
This commit is contained in:
Bob Nystrom
2018-07-15 21:01:14 -07:00
43 changed files with 502 additions and 217 deletions

View File

@ -158,9 +158,10 @@ are available on an object. When you write:
unicorn.isFancy
You're saying "look up the method `isFancy` in the scope of the object
`unicorn`". In this case, the fact that you want to look up a *method* `isFancy`
and not a *variable* `isFancy` is explicit. That's what `.` does and the
object to the left of the period is the object you want to look up the method on.
`unicorn`”. In this case, the fact that you want to look up a *method*
`isFancy` and not a *variable* `isFancy` is explicit. That's what `.` does and
the object to the left of the period is the object you want to look up the
method on.
### `this`
@ -430,7 +431,7 @@ They can be used from static methods:
:::wren
Foo.setFromStatic("first")
Foo.bar.printFromStatic() //> first
Foo.printFromStatic() //> first
And also instance methods. When you do so, there is still only one static field
shared among all instances of the class:

View File

@ -148,14 +148,14 @@ method calls — the entire callstack — gets suspended. For example:
:::wren
var fiber = Fiber.new {
(1..10).map {|i|
(1..10).each {|i|
Fiber.yield(i)
}
}
Here, we're calling `yield()` from within a [function](functions.html) being
passed to the `map()` method. This works fine in Wren because that inner
`yield()` call will suspend the call to `map()` and the function passed to it
passed to the `each()` method. This works fine in Wren because that inner
`yield()` call will suspend the call to `each()` and the function passed to it
as a callback.
## Transferring control

View File

@ -66,7 +66,7 @@ for Wren. To install that, run:
:::sh
$ cd util/pygments-lexer
$ sudo python setup.py develop
$ sudo python3 setup.py develop
$ cd ../.. # Back to the root Wren directory.
Now you can build the docs:
@ -79,7 +79,7 @@ server from there. Python includes one:
:::sh
$ cd build/docs
$ python -m SimpleHTTPServer
$ python3 -m http.server
Running `make docs` is a drag every time you change a line of Markdown or SASS,
so there is also a file watching version that will automatically regenerate the

View File

@ -76,7 +76,7 @@ Something like:
{
if (strcmp(className, "Math") == 0)
{
if (!isStatic && strcmp(signature, "add(_,_)") == 0)
if (isStatic && strcmp(signature, "add(_,_)") == 0)
{
return mathAdd; // C function for Math.add(_,_).
}

View File

@ -102,6 +102,7 @@ is:
:::c
void error(
WrenVM* vm,
WrenErrorType type,
const char* module,
int line,

View File

@ -270,7 +270,7 @@ and closes the file:
:::c
void fileFinalize(void* data)
{
closeFile((FILE**)file);
closeFile((FILE**) data);
}
It uses this little utility function:

View File

@ -129,28 +129,12 @@ negative to count backwards from the end of the string.
It is a runtime error if `search` is not a string or `start` is not an integer
index within the string's byte length.
### **split**(separator)
Returns a list of one or more strings separated by `separator`.
:::wren
var string = "abc abc abc"
System.print(string.split(" ")) //> [abc, abc, abc]
It is a runtime error if `separator` is not a string or is an empty string.
### **replace**(old, swap)
Returns a new string with all occurences of `old` replaced with `swap`.
:::wren
var string = "abc abc abc"
System.print(string.replace(" ", "")) //> abcabcabc
### **iterate**(iterator), **iteratorValue**(iterator)
Implements the [iterator protocol](../../control-flow.html#the-iterator-protocol)
for iterating over the *code points* in the string:
Implements the [iterator protocol][] for iterating over the *code points* in the
string:
[iterator protocol]: ../../control-flow.html#the-iterator-protocol
:::wren
var codePoints = []
@ -163,12 +147,74 @@ for iterating over the *code points* in the string:
If the string contains any bytes that are not valid UTF-8, this iterates over
those too, one byte at a time.
### **replace**(old, swap)
Returns a new string with all occurrences of `old` replaced with `swap`.
:::wren
var string = "abc abc abc"
System.print(string.replace(" ", "")) //> abcabcabc
### **split**(separator)
Returns a list of one or more strings separated by `separator`.
:::wren
var string = "abc abc abc"
System.print(string.split(" ")) //> [abc, abc, abc]
It is a runtime error if `separator` is not a string or is an empty string.
### **startsWith**(prefix)
Checks if the string starts with `prefix`.
It is a runtime error if `prefix` is not a string.
### **trim**()
Returns a new string with whitespace removed from the beginning and end of this
string. "Whitespace" is space, tab, carriage return, and line feed characters.
:::wren
System.print(" \nstuff\r\t".trim()) //> stuff
### **trim**(chars)
Returns a new string with all code points in `chars` removed from the beginning
and end of this string.
:::wren
System.print("ᵔᴥᵔᴥᵔbearᵔᴥᴥᵔᵔ".trim("ᵔᴥ")) //> bear
### **trimEnd**()
Like `trim()` but only removes from the end of the string.
:::wren
System.print(" \nstuff\r\t".trimEnd()) //> " \nstuff"
### **trimEnd**(chars)
Like `trim()` but only removes from the end of the string.
:::wren
System.print("ᵔᴥᵔᴥᵔbearᵔᴥᴥᵔᵔ".trimEnd("ᵔᴥ")) //> ᵔᴥᵔᴥᵔbear
### **trimStart**()
Like `trim()` but only removes from the beginning of the string.
:::wren
System.print(" \nstuff\r\t".trimStart()) //> "stuff\r\t"
### **trimStart**(chars)
Like `trim()` but only removes from the beginning of the string.
:::wren
System.print("ᵔᴥᵔᴥᵔbearᵔᴥᴥᵔᵔ".trimStart("ᵔᴥ")) //> bearᵔᴥᴥᵔᵔ
### **+**(other) operator
Returns a new string that concatenates this string and `other`.

View File

@ -97,7 +97,7 @@ The size of the contents of the file in bytes.
### **close**()
Closes the file. After calling this, you can read or write from it.
Closes the file. After calling this, you can't read or write from it.
### **readBytes**(count)