Skip to content

Commit

Permalink
Add the dofile API function #23
Browse files Browse the repository at this point in the history
  • Loading branch information
Olical committed Nov 30, 2023
1 parent b8b1d2e commit 013a13e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
10 changes: 10 additions & 0 deletions docs/api/nfnl/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
**Table of contents**

- [`compile-all-files`](#compile-all-files)
- [`dofile`](#dofile)

## `compile-all-files`
Function signature:
Expand All @@ -15,6 +16,15 @@ Compiles all files in the given dir (optional), defaulting to the current workin

Will do nothing if you execute it on a directory that doesn't contain an nfnl configuration file.

## `dofile`
Function signature:

```
(dofile file)
```

Just like :luafile, takes a Fennel file path (optional, defaults to current open file) and executes it from disk. However! This doesn't compile the Fennel! It maps the Fennel path to the matching Lua file already in your file system and executes that with Lua's built in dofile. So you need to have already written your .fnl and had nfnl compile that to a .lua for this to work, it's just a convinience function for you to call directly or through the :nfnlfile command.


<!-- Generated with Fenneldoc v1.0.1
https://gitlab.com/andreyorst/fenneldoc -->
11 changes: 9 additions & 2 deletions fnl/nfnl/api.fnl
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
(local {: autoload} (require :nfnl.module))
(local compile (autoload :nfnl.compile))
(local config (autoload :nfnl.config))
(local fs (autoload :nfnl.fs))

(fn compile-all-files [dir]
(local mod {})

(fn mod.compile-all-files [dir]
"Compiles all files in the given dir (optional), defaulting to the current working directory. Returns a sequential table with each of the files compilation result.
Will do nothing if you execute it on a directory that doesn't contain an nfnl configuration file."
Expand All @@ -11,4 +14,8 @@
(when config
(compile.all-files {: root-dir : cfg}))))

{: compile-all-files}
(fn mod.dofile [file]
"Just like :luafile, takes a Fennel file path (optional, defaults to current open file) and executes it from disk. However! This doesn't compile the Fennel! It maps the Fennel path to the matching Lua file already in your file system and executes that with Lua's built in dofile. So you need to have already written your .fnl and had nfnl compile that to a .lua for this to work, it's just a convinience function for you to call directly or through the :nfnlfile command."
(dofile (fs.fnl-path->lua-path (vim.fn.expand (or file "%")))))

mod
9 changes: 7 additions & 2 deletions lua/nfnl/api.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 013a13e

Please sign in to comment.