-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fennel lua escape hatch #2
Comments
Right on! Thanks for tracking me down to show me this. What I ultimately want is a macro that turns that into a one liner. Unfortunately it seems a bit tricky 'cause I both want to run a few expressions (e.g. in a |
Ah, gotcha. I'm not sure you'll be able to achieve that, sadly. Fennel macros can only return one form so you can't really do multiple things without using (require-hardcore-version [telescope :telescope]
[idk telescope.thing]
(print idk)))
; -->
(let [(ok_1_ telescope) (pcall require :telescope)]
(when ok_1_
(let [idk telescope.thing]
(print idk))))
(macro require-hardcore-version [mod-binding body-bindings body]
(let [[mod-sym mod-name] mod-binding
ok (gensym :ok)]
`(let [,(list ok mod-sym) (pcall require ,mod-name)]
(when ,ok
(let ,body-bindings ,body))))) Also, I think a good pattern for this would be to do the dependency checking for all modules in one place so you could just write a normal aniseed module that is only ever required if its dependencies are available. i.e. (fn check-dep [d] (let [ok? (pcall require d)] (when ok? 1)))
(fn load-if-dep-available! [mod ds]
(let [deps (if (table? ds) ds [ds])
results (map check-dep deps)]
(when (= (count deps) (count results))
(require mod))))
; map, count, and table? are from aniseed.core
(load-if-dep-available! :dotfiles.module.telescope :telescope)
(load-if-dep-available! :dotfiles.module.something [:fennel :io]) No macros necessary. Sorry if I'm getting a little over-involved in your dotfiles lol, I just found the problem interesting and have been tinkering with macros/aniseed's compiler so this was somewhat related. |
I already have a
|
Hi, I replied to your aniseed issue about
(lua ...)
, since that issue is closed I thought I'd post this here. While you can't use(lua "return ...")
at the top level of a fennel file, you can use it inside of a(when ...)
and achieve your goal.Although, now that I'm writing this out, this technique will probably break aniseed modules... So perhaps this isn't that helpful...On the latest
aniseed/develop
this works fineCompiled
🙂
The text was updated successfully, but these errors were encountered: