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 The entire library is currently contained in a single object. We can bring this
`moon` object into scope by requiring `"moon"`. `moon` object into scope by requiring `"moon"`.
```moon ```moon
require "moon" require "moon"
-- `moon.p` is the debug printer -- `moon.p` is the debug printer
moon.p { hello: "world" } moon.p { hello: "world" }
``` ```
If you prefer to just inject all of the functions into the current scope, you 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: can require `"moon.all"` instead. The following has the same effect as above:
```moon ```moon
require "moon.all" require "moon.all"
p { hello: "world" } p { hello: "world" }
``` ```
All of the functions are compatible with Lua in addition to MoonScript, but All of the functions are compatible with Lua in addition to MoonScript, but
some of them only make sense in the context of MoonScript. 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 `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. entry for a value, it will fall back on the original environment.
```moon ```moon
my_env = { my_env = {
secret_function: -> print "shhh this is secret" secret_function: -> print "shhh this is secret"
say_hi: -> print "hi there!" say_hi: -> print "hi there!"
} }
say_hi = -> print "I am a closure" say_hi = -> print "I am a closure"
fn = -> fn = ->
secret_function! secret_function!
say_hi! 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 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. Returns the first argument.
```moon ```moon
a = { hello: "world" } a = { hello: "world" }
b = { okay: "sure" } b = { okay: "sure" }
extend a, b extend a, b
print a.okay print a.okay
``` ```
### `copy(tbl)` ### `copy(tbl)`
Creates a shallow copy of a table, equivalent to: Creates a shallow copy of a table, equivalent to:
```moon ```moon
copy = (arg) -> {k,v for k,v in pairs self} copy = (arg) -> {k,v for k,v in pairs self}
``` ```
## Class/Object Functions ## 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. 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. Otherwise, return the result of calling Lua's type method.
```moon ```moon
class MyClass class MyClass
nil nil
x = MyClass! x = MyClass!
assert type(x) == MyClass assert type(x) == MyClass
``` ```
### `bind_methods(obj)` ### `bind_methods(obj)`
Takes an instance of an object, returns a proxy to the object whose methods can Takes an instance of an object, returns a proxy to the object whose methods can
be called without providing self as the first argument. be called without providing self as the first argument.
```moon ```moon
obj = SomeClass! obj = SomeClass!
bound_obj = bind_methods obj bound_obj = bind_methods obj
-- following have the same effect -- following have the same effect
obj\hello! obj\hello!
bound_obj.hello! bound_obj.hello!
``` ```
It lazily creates and stores in the proxy table the bound methods when they It lazily creates and stores in the proxy table the bound methods when they
are first called. 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` In this example we add the functionality of `First` to an instance of `Second`
without ever instancing `First`. without ever instancing `First`.
```moon ```moon
class First class First
new: (@var) => new: (@var) =>
show_var: => print "var is:", @var show_var: => print "var is:", @var
class Second class Second
new: => new: =>
mixin self, First, "hi" mixin self, First, "hi"
a = Second! a = Second!
a\show_var! a\show_var!
``` ```
Be weary of name collisions when mixing in other classes, names will be Be weary of name collisions when mixing in other classes, names will be
overwritten. 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 `method_names`. The inserted methods are bound methods that will run with
`other_obj` as the receiver. `other_obj` as the receiver.
```moon ```moon
class List class List
add: (item) => print "adding to", self add: (item) => print "adding to", self
remove: (item) => print "removing from", self remove: (item) => print "removing from", self
class Encapsulation class Encapsulation
new: => new: =>
@list = List! @list = List!
mixin_object self, @list, {"add", "remove"} mixin_object self, @list, {"add", "remove"}
e = Encapsulation! e = Encapsulation!
e.add "something" e.add "something"
``` ```
### `mixin_table(a, b, [names])` ### `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: For example, to sum all numbers in a list:
```moon ```moon
numbers = {4,3,5,6,7,2,3} numbers = {4,3,5,6,7,2,3}
sum = fold numbers, (a,b) -> a + b sum = fold numbers, (a,b) -> a + b
``` ```
## Debug Functions ## Debug Functions
### `debug.upvalue(fn, key[, value])` ### `debug.upvalue(fn, key[, value])`
Gets or sets the value of an upvalue for a function by name. Gets or sets the value of an upvalue for a function by name.