Closed monkoose closed 2 years ago
Ok found my mistake.
If I rename print-synnames
into something that doesn't have -
like printsynnames
, then i can require it with :lua require("myfunctions").printsynnames()
or i can require it with :lua require("myfunctions")["print-synnames"]()
.
For some reason i thought that fennel transforms dashes into underscore for exposed functions. But it isn't and this line
_2amodule_2a["print-synnames"] = print_synnames
confirms that.
So i guess it is fixed.
Anyway have you any suggestions about this in particular? Should i name all public functions without the dashes (name conventions in lisp) and just use underscores or simple one word names?
I will close it after some time.
Yep you have to be careful with Fnl->Lua naming since Fennel is farrr more permissive (which is great!). My general approach if I'm calling a Fennel compiled Lua function is to just guess what it mangled the name to (:lua require("myfunctions").print_synnames()
) or check the .lua
to see what it did. For instance, _2a
is *
, which I know from seeing it mangle that character so much.
I think you could export Lua friendly names if you know your module will be called from Lua a lot (so ensure you stick to a-zA-Z0-9_
or whatever it supports) but I think it's still okay to just use Fennel naming then document / think about how that'll be accessed from vanilla Lua.
Just a quirk of Fennel really! One that you can work around fairly easily but you need to be aware of whenever you're crossing the language boundary.
Thank you again.
You're welcome, just glad you worked it out!
Hello, Oli!
--Fixed-- so to save your time you can skip to my next comment, i have some question there.
I'm trying to convert simple functions to aniseed/fennel, and got into a problem.
I have
let g:aniseed#env = v:true
in my config.I have this file in my
~/.config/nvim/fnl/myfunctions.fnl
It converted to this file in
~/.config/nvim/lua/myfunctions.lua
But when I'm trying to call
print_synnames()
function with:lua require("myfunctions").print_synnames()
the error apperasIf i add
(print-synnames)
intomyfunctions.fnl
and eval file with conjure - it works and i can see the output in the echo area.If i add
(global Synnames print-synnames)
intomyfunctions.fnl
and then require it ininit.fnl
then i can call that function without a problem with:lua Synnames()
Inside
fnl
dir i have another module and i can call some function from it with the:lua require...
without a problem. Do i miss something?