bakpakin / Fennel

Lua Lisp Language
https://fennel-lang.org
MIT License
2.42k stars 124 forks source link

readline support #471

Closed bsturk closed 7 months ago

bsturk commented 7 months ago

I'm trying to get readline support working and I've followed the steps outlined in the docs:

Anything other than alphabet letters shows up as garbage in my terminal (e.g. Ctrl-R or trying to use vi movement).

inputrc.txt readline_test_lua.txt

technomancy commented 7 months ago

What happens when you (require :readline) from within the Fennel REPL? Loading this thru Luarocks should require activating the Luarocks loader; it's unclear why this would work on the Lua side without it.

bsturk commented 7 months ago

I agree, it's odd that it is working there, I was just trying to make sure it got installed and would be picked up. Here's what I get when I put the require in my .fennelrc or run the command in the REPL, looks like it is not picking it up, is there some kind of module path I need to set?

hostname[~]% fennel runtime error: module 'readline' not found: no field package.preload['readline'] no file '/usr/local/share/lua/5.4/readline.lua' no file '/usr/local/share/lua/5.4/readline/init.lua' no file '/usr/local/lib/lua/5.4/readline.lua' no file '/usr/local/lib/lua/5.4/readline/init.lua' no file './readline.lua' no file './readline/init.lua' no file '/usr/local/lib/lua/5.4/readline.so' no file '/usr/local/lib/lua/5.4/loadall.so' no file './readline.so' no file './readline.fnl' no file './readline/init.fnl' stack traceback: [C]: in function 'require' /home/user/.fennelrc:1: in main chunk [C]: in function 'xpcall' [string "src.launcher"]:6365: in function ? [string "src.launcher"]:6181: in function ?

technomancy commented 7 months ago

I don't use Luarocks myself, so I'm not sure what's going on here, but where did Luarocks put readline.lua when you installed it? I assume it's not on any of the paths you just pasted, but the question is why not?

Does it work if you put (require :luarocks.loader) right before requiring readline?

bsturk commented 7 months ago

this seems to be the issue:

hostname[~]% locate readline.lua /usr/local/share/lua/5.1/readline.lua

I seem to have lua 5.1 installed and fennel is using lua 5.4. Ubuntu seems to be pretty conservative w/ the lua release it ships with.

bsturk commented 7 months ago

fixed that, and 5.4 doesn't support dynamic libraries? :(

error loading module 'C-readline' from file '/usr/local/lib/lua/5.4/C-readline.so': dynamic libraries not enabled; check your Lua installation stack traceback: [C]: in ? [C]: in function 'require' /usr/local/share/lua/5.4/readline.lua:95: in main chunk [C]: in function 'require' /home/bsturk/.fennelrc:1: in main chunk [C]: in function 'xpcall' [string "src.launcher"]:6365: in function ? [string "src.launcher"]:6181: in function ?

not sure how to get around this without recompiling lua.

technomancy commented 7 months ago

Hm; why did you install readline using luarocks if you have apt available? How did you install Fennel?

If you pull in both Lua and lua-readline from apt, there should be no problem provided you use the system Lua for Fennel. (meaning use the script download instead of the binary one)

bsturk commented 7 months ago

I can do that, I didn't think to install lua-readline via apt (didn't think it would be a package), but I will do that. My lua install is via apt (including 5.4).

I also noticed that I don't get that error if I load the readline module from the lua5.4 prompt, just an FYI.

The script version works! Didn't know that was even an option. Just curious, why would this work but not the binary?

technomancy commented 7 months ago

We're working towards allowing you to apt install fennel, but it will take some time to make it out into the repositories for various distros.

You can use the system Lua with a manually installed Fennel (with the script download); using the system Lua is almost always better than stitching together manual processes. The binary release is really only useful for systems that don't have Lua already installed and really need it to be standalone. Maybe this could be explained better on the download page.

why would this work but not the binary?

It's because the script version has the shebang which uses the system Lua, and the Debian maintainers for Lua have patched it to use a package.path which knows where to find the lua-readline package installed from apt.

Our Fennel binary build has not been patched by the Debian maintainers, so it uses a package.path which only looks in /usr/local... and doesn't look in the place the libraries are actually installed. I think this is probably not ideal. We could patch it as part of our own release process, if it can be done in a portable way that covers more than just Debian.

But on the other hand, if you're using system libraries, what's the point of using the binary release in the first place?

I've opened an issue for that here: https://todo.sr.ht/~technomancy/fennel/192

bsturk commented 7 months ago

Thanks for the explanation. As for why using the binary, I was just looking to try out fennel and it was the first thing I saw on the web site. I'm a vi guy so figured I'd get readline working.

Up and going now though, thanks for the help!

technomancy commented 7 months ago

Cool; sounds good. I've made it clearer to steer people away from the binary if they don't need it in the setup guide.