Make fennel.repl accept moduleName argument.

This commit is contained in:
Phil Hagelberg 2020-04-01 21:42:57 -07:00
parent a89f224708
commit 9df2def227
4 changed files with 8 additions and 2976 deletions

2916
fennel.lua

File diff suppressed because it is too large Load diff

View file

@ -37,7 +37,7 @@
:onValues out :onValues out
:onError (fn [kind ...] (out [kind "Error:" ...])) :onError (fn [kind ...] (out [kind "Error:" ...]))
:pp view :pp view
}] :moduleName "lib.fennel"}]
;; this thread will send "eval" events for us to consume: ;; this thread will send "eval" events for us to consume:
(coroutine.resume coro options) (coroutine.resume coro options)
(: thread :start "eval" io-channel) (: thread :start "eval" io-channel)

View file

@ -7,7 +7,7 @@
local prompt = prompt local function _0_() io.write("> ") io.flush() return io.read("*l") end prompt = _0_ local prompt = nil local function _0_() io.write("> ") io.flush() return io.read("*l") end prompt = _0_
local function looper(input) if input then local function looper(input) if input then
@ -23,19 +23,19 @@
local function start_repl() local function start_repl()
local code = love.filesystem.read("stdio.fnl") local luac = luac local code = love.filesystem.read("stdio.fnl") local luac = nil
if code then if code then
luac = love.filesystem.newFileData(fennel.compileString(code), "io") else luac = love.filesystem.newFileData(fennel.compileString(code), "io") else
luac = love.filesystem.read("lib/stdio.lua") end luac = love.filesystem.read("lib/stdio.lua") end
local thread = love.thread.newThread(luac) local thread = love.thread.newThread(luac)
local io_channel = love.thread.newChannel() local io_channel = love.thread.newChannel()
local coro = coroutine.create(fennel.repl) local out = out local coro = coroutine.create(fennel.repl) local out = nil
local function _2_(val) local function _2_(val)
return io_channel:push(val) end out = _2_ local options = options return io_channel:push(val) end out = _2_ local options = nil
local function _3_(kind, ...) return out({kind, "Error:", ...}) end options = {onError = _3_, onValues = out, pp = view, readChunk = coroutine.yield} local function _3_(kind, ...) return out({kind, "Error:", ...}) end options = {moduleName = "lib.fennel", onError = _3_, onValues = out, pp = view, readChunk = coroutine.yield}

View file

@ -20,57 +20,5 @@ If you design your game as a series of states in a very simple state machine, fo
* Emacs Setup * Emacs Setup
Once you install the latest version of [[https://gitlab.com/technomancy/fennel-mode][fennel-mode]], you can run
#+BEGIN_SRC emacs-lisp =C-u M-x fennel-repl= followed by =love .= to launch a repl.
(autoload 'fennel-mode "/path/to/fennel-mode" nil t)
(require 'fennel-mode)
;; By default fennel-mode moves focus to the \*inferior-lisp\* buffer
;; setting `fennel-mode-switch-to-repl-after-reload' to nil prevents this
(customize-save-variable 'fennel-mode-switch-to-repl-after-reload nil)
(add-to-list 'auto-mode-alist '("\\.fnl\\'" . fennel-mode))
;; you can bind this to whatever you like
(defun run-love ()
(interactive)
(run-lisp "love ."))
;; for some reason when I load a fnl file it starts the slime minor mode
;; I have included the hook below to prevent this
(defun fennel-mode-hook-fun ()
(interactive)
(slime-mode nil))
(add-hook 'fennel-mode-hook 'fennel-mode-hook-fun)
#+END_SRC
* Known Issues
Presently fennel.lua has to be in the main directory for =fennel-reload= from fennel-mode.el to work. The issue is
#+BEGIN_SRC elisp
(let [old (require :module-name)
_ (tset package.loaded :module-name nil)
(ok new) (pcall require :module-name) ;; fails if fennel not in base directory
new (if (not ok) (do (print new) old) new)]
(when (= (type new) :table)
(each [k v (pairs new)] (tset old k v))
(each [k (pairs old)] (when (not (. new k)) (tset old k nil)))
(tset package.loaded :module-name old)))
#+END_SRC
The error that gets thrown is.
#+BEGIN_SRC
./module-name.fnl:#Some Number#: module 'fennel' not found:
no field package.preload['fennel']
no 'fennel' in LOVE game directories.
no file 'fennel' in LOVE paths.
no file './fennel.lua'
no file '/usr/local/share/luajit-2.0.5/fennel.lua'
no file '/usr/local/share/lua/5.1/fennel.lua'
no file '/usr/local/share/lua/5.1/fennel/init.lua'
no file './fennel.so'
no file '/usr/local/lib/lua/5.1/fennel.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
#+END_SRC