Merge branch 'fennel-module-name' into 'master'
Make fennel.repl accept moduleName argument. Closes #2 See merge request alexjgriffith/min-love2d-fennel!5
This commit is contained in:
commit
f583452b77
2916
fennel.lua
2916
fennel.lua
File diff suppressed because it is too large
Load diff
|
@ -37,7 +37,7 @@
|
|||
:onValues out
|
||||
:onError (fn [kind ...] (out [kind "Error:" ...]))
|
||||
:pp view
|
||||
}]
|
||||
:moduleName "lib.fennel"}]
|
||||
;; this thread will send "eval" events for us to consume:
|
||||
(coroutine.resume coro options)
|
||||
(: thread :start "eval" io-channel)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
@ -23,19 +23,19 @@
|
|||
|
||||
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
|
||||
luac = love.filesystem.newFileData(fennel.compileString(code), "io") else
|
||||
|
||||
luac = love.filesystem.read("lib/stdio.lua") end
|
||||
local thread = love.thread.newThread(luac)
|
||||
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)
|
||||
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}
|
||||
|
||||
|
||||
|
||||
|
|
56
readme.org
56
readme.org
|
@ -20,57 +20,5 @@ If you design your game as a series of states in a very simple state machine, fo
|
|||
|
||||
|
||||
* Emacs Setup
|
||||
|
||||
#+BEGIN_SRC emacs-lisp
|
||||
(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
|
||||
Once you install the latest version of [[https://gitlab.com/technomancy/fennel-mode][fennel-mode]], you can run
|
||||
=C-u M-x fennel-repl= followed by =love .= to launch a repl.
|
||||
|
|
Loading…
Reference in a new issue