remove unneeded indentation from documentation

This commit is contained in:
leaf corcoran 2013-04-17 21:05:01 -07:00
parent 4b5d6f1cde
commit c61b826f3b
2 changed files with 753 additions and 751 deletions

File diff suppressed because it is too large Load Diff

View File

@ -10,19 +10,19 @@ used to perform various common things.
The entire library is currently contained in a single object. We can bring this
`moon` object into scope by requiring `"moon"`.
```moon
require "moon"
-- `moon.p` is the debug printer
moon.p { hello: "world" }
```
```moon
require "moon"
-- `moon.p` is the debug printer
moon.p { hello: "world" }
```
If you prefer to just inject all of the functions into the current scope, you
can require `"moon.all"` instead. The following has the same effect as above:
```moon
require "moon.all"
p { hello: "world" }
```
```moon
require "moon.all"
p { hello: "world" }
```
All of the functions are compatible with Lua in addition to MoonScript, but
some of them only make sense in the context of MoonScript.
@ -53,20 +53,20 @@ The environment of the function is set to a new table whose metatable will use
`scope` to look up values. `scope` must be a table. If `scope` does not have an
entry for a value, it will fall back on the original environment.
```moon
my_env = {
secret_function: -> print "shhh this is secret"
say_hi: -> print "hi there!"
}
```moon
my_env = {
secret_function: -> print "shhh this is secret"
say_hi: -> print "hi there!"
}
say_hi = -> print "I am a closure"
say_hi = -> print "I am a closure"
fn = ->
secret_function!
say_hi!
fn = ->
secret_function!
say_hi!
run_with_scope fn, my_env
```
run_with_scope fn, my_env
```
Note that any closure values will always take precedence against global name
@ -86,22 +86,22 @@ whose `__index` is set to the next table.
Returns the first argument.
```moon
a = { hello: "world" }
b = { okay: "sure" }
```moon
a = { hello: "world" }
b = { okay: "sure" }
extend a, b
extend a, b
print a.okay
```
print a.okay
```
### `copy(tbl)`
Creates a shallow copy of a table, equivalent to:
```moon
copy = (arg) -> {k,v for k,v in pairs self}
```
```moon
copy = (arg) -> {k,v for k,v in pairs self}
```
## Class/Object Functions
@ -114,28 +114,28 @@ Returns true if `value` is an instance of a MoonScript class, false otherwise.
If `value` is an instance of a MoonScript class, then return it's class object.
Otherwise, return the result of calling Lua's type method.
```moon
class MyClass
nil
```moon
class MyClass
nil
x = MyClass!
assert type(x) == MyClass
```
x = MyClass!
assert type(x) == MyClass
```
### `bind_methods(obj)`
Takes an instance of an object, returns a proxy to the object whose methods can
be called without providing self as the first argument.
```moon
obj = SomeClass!
```moon
obj = SomeClass!
bound_obj = bind_methods obj
bound_obj = bind_methods obj
-- following have the same effect
obj\hello!
bound_obj.hello!
```
-- following have the same effect
obj\hello!
bound_obj.hello!
```
It lazily creates and stores in the proxy table the bound methods when they
are first called.
@ -148,18 +148,18 @@ constructor of the class with the `obj` as the receiver.
In this example we add the functionality of `First` to an instance of `Second`
without ever instancing `First`.
```moon
class First
new: (@var) =>
show_var: => print "var is:", @var
```moon
class First
new: (@var) =>
show_var: => print "var is:", @var
class Second
new: =>
mixin self, First, "hi"
class Second
new: =>
mixin self, First, "hi"
a = Second!
a\show_var!
```
a = Second!
a\show_var!
```
Be weary of name collisions when mixing in other classes, names will be
overwritten.
@ -170,19 +170,19 @@ Inserts into `obj` methods from `other_obj` whose names are listen in
`method_names`. The inserted methods are bound methods that will run with
`other_obj` as the receiver.
```moon
class List
add: (item) => print "adding to", self
remove: (item) => print "removing from", self
```moon
class List
add: (item) => print "adding to", self
remove: (item) => print "removing from", self
class Encapsulation
new: =>
@list = List!
mixin_object self, @list, {"add", "remove"}
class Encapsulation
new: =>
@list = List!
mixin_object self, @list, {"add", "remove"}
e = Encapsulation!
e.add "something"
```
e = Encapsulation!
e.add "something"
```
### `mixin_table(a, b, [names])`
@ -202,13 +202,14 @@ being iterated over starting with the second item.
For example, to sum all numbers in a list:
```moon
numbers = {4,3,5,6,7,2,3}
sum = fold numbers, (a,b) -> a + b
```
```moon
numbers = {4,3,5,6,7,2,3}
sum = fold numbers, (a,b) -> a + b
```
## Debug Functions
### `debug.upvalue(fn, key[, value])`
Gets or sets the value of an upvalue for a function by name.