~technomancy/fennel

650f0ad39c6873152c118a360d98207b1a03f90e — Phil Hagelberg a month ago 958853f
Clarify how to get fennel.lua in setup guide.

Remove redundant "Embedding" section from tutorial. The setup guide
is a better place to cover that.
2 files changed, 8 insertions(+), 50 deletions(-)

M setup.md
M tutorial.md
M setup.md => setup.md +7 -3
@@ 112,8 112,11 @@ process and including the Lua output in the application may be easier.
The Fennel compiler can be added to your code repository, and then
loaded from Lua.

 1. Add `fennel.lua` to your code repository
 2. Add the following lines to your Lua code:
 1. Get the `fennel.lua` library. You can get this from a
    [release tarball](https://fennel-lang.org/downloads/Fennel-0.6.0.tgz)
    or by running `make` in a source checkout.
 2. Add `fennel.lua` to your code repository.
 3. Add the following lines to your Lua code:

```lua
local fennel = require("fennel")


@@ 121,11 124,12 @@ table.insert(package.loaders or package.searchers, fennel.searcher)
local mylib = require("mylib") -- will compile and load code in mylib.fnl
```

Be sure to use the library and not the file for the entire `fennel` compiler.

**Note**: Optionally, if you want the Fennel REPL to print tables
in a more readable format, you can add `fennelview.fnl` to
your code repository.


### Performing ahead-of-time compilation

If the target system of your application does not make it easy to add

M tutorial.md => tutorial.md +1 -47
@@ 612,53 612,6 @@ which is distinct from `package.path` used to find Lua modules). The
path usually includes an entry to let you load things relative to the
current directory by default.

## Embedding

Lua is most commonly used to embed inside other applications, and
Fennel is no different. The simplest thing to do is include Fennel the
output from `fennel --compile` as part of your overall application's
build process. However, the Fennel compiler is very small, and
including it into your codebase means that you can embed a Fennel repl
inside your application or support reloading from disk, allowing a
much more pleasant interactive development cycle.

Here is an example of embedding the Fennel compiler inside a
[LÖVE][13] game written in Lua to allow live reloads:

```lua
local fennel = require("fennel")
-- mycode.fnl ends in a line like this:
-- {:draw (fn [] ...) :update (fn [dt] ...)}
local mycode = fennel.dofile("mycode.fnl")

love.update = function(dt)
  mycode.update(dt)
  -- other updates
end

love.draw = function()
  mycode.draw()
  -- other drawing
end

love.keypressed = function(key)
  if(key == "f5") then -- support reloading
    for k,v in pairs(fennel.dofile("mycode.fnl")) do
      mycode[k] = v
    end
  else
    -- other key handling
  end
end

```

You can add `fennel.lua` as a single file to your project, but if you also
add `fennelview.fnl` then when you use a Fennel repl you'll get results
rendered much more nicely. Running `(local view (require :fennelview))`
will get you a `view` function which turns any table into a fennel-syntax
string rendering of that table for debugging.

[1]: http://www.defmacro.org/ramblings/lisp.html
[2]: http://danmidwood.com/content/2014/11/21/animated-paredit.html
[3]: https://www.lua.org/manual/5.1/


@@ 673,3 626,4 @@ string rendering of that table for debugging.
[12]: http://nova-fusion.com/2011/06/30/lua-metatables-tutorial/
[13]: https://love2d.org
[14]: https://fennel-lang.org/lua-primer