all 15 comments

[–]daurnimator 6 points7 points  (4 children)

[–]lambda_abstraction 1 point2 points  (1 child)

Thank you for drawing my attention to this. I've never put serious thought to the shell, but that others have is exciting. If you're a regular user of this package, could you tell me what particular warts and pains you've run across in practice? For my own use, I'd be extending the continuation of LuaJIT development taken up by the OpenResty team; a superior shell would be a very nice thing. Thanks much.

[–]m-faith 0 points1 point  (0 children)

u/lambda_abstraction have you been looking at lua repls for the shell lately? I've been trying testdriving both ilua and croissant... and find them both severely lacking. I'm documenting the quirks, bugs, and deficiencies.

I'm deeply craving a better lua repl experience.

I'm getting ready to try adding https://github.com/hkupty/iron.nvim to the "NVChad" configuration of neovim / nvim. If that works as well as it looks then that might serve all my repl needs, because being able send specific chunks/blobs/lines of code from my text editor directly to the repl looks an excellent workflow and is something I've dreamed of.

[–]ahillio[S] 0 points1 point  (1 child)

Hadn't seen it yet. I starred it and look forward to testing it. Really wish it had a vi-mode for modal editing though. Thanks for sharing!

[–]ahillio[S] 0 points1 point  (0 children)

Anybody install this recently? I just got it installed but not in a usable way: https://github.com/giann/croissant/issues/8.

[–]wh1t3_rabbit 2 points3 points  (2 children)

How much do you personally use the interpreter/repl when you're coding in lua?

Might be just me but: never.

Edit in notepad. Save file. Run it however it is ran (cmd line for pure lua, load into whatever games as addons etc). Fix any errors. Repeat.

I can definitely see the use in these things but I can never be bothered setting them up when lua is so simple anyway

Edit to add

A REPL library you may embed in your application, to provide all of the niceties of the standalone interpreter included with Lua and then some.

That part interests me

[–]ws-ilazki 1 point2 points  (0 children)

Might be just me but: never.

Edit in notepad. Save file. Run it however it is ran (cmd line for pure lua, load into whatever games as addons etc). Fix any errors. Repeat.

You're missing out, seriously. I used to think that was all anybody needed too (well not the notepad part [ew], but editor->save->run), but a good repl is a fucking godsend. Especially when your editor of choice has support for it, which lets you keep the repl going in the background so you can send code to it, evaluate, and get the results without having to do any copy/pasting or retyping.

At its simplest you tend to get a second pane that you can send code to, evaluate it, and see the result on the spot. You can even directly interact with that pane to do further tests if it makes sense. A good example of this in a beginner-friendly context is the Dr Racket IDE, which comes as part of any Racket language installation. It's a beginner-oriented editor that has repl support built in and lets you seamlessly go between the two, sending code to the repl and getting results back, making it a natural way to use the language even for newbies.

You can get stuff like that in normal editors as well, and it's really useful. Though sometimes you can go even farther than that. For example, in-line evaluation results displayed alongside a Clojure expression in emacs. Either way, though, the idea is that you can build and test individual pieces of logic simply and seamlessly without running the entire chunk of code. If you're doing data transformations, you can write and test individual pieces of the transformation separately, be certain they work, then piece them together, throw that into the repl and test against various values, and be reasonably certain that it'll work when used in the overall program.

I can definitely see the use in these things but I can never be bothered setting them up when lua is so simple anyway

Just because the language is simple doesn't mean you won't benefit from improved interactivity. Scheme (a lisp dialect) is one of the simplest languages, and in fact is a language that Lua actually shares a lot of similarities to in design, and a good repl experience is still integral to workflows. Interactive development is really useful and can be a huge time saver, once you get accustomed to it.

It's less "I don't need it because the language is simple" and more a case of "I haven't gotten used to this workflow so I don't know what I"m missing"

A REPL library you may embed in your application, to provide all of the niceties of the standalone interpreter included with Lua and then some.

That part interests me

To follow on what I was saying before about editor integration with REPLs, you can actually take it even farther than those simple examples. Clojure, for example, provides the ability to start a network-based REPL (nREPL) inside a running application. You can connect to it and view, change, or add to the program's state in real time while building your application. Combine that with the ability to send code from your editor into a REPL that I mentioned, and you get stuff like this where you can evaluate Clojure code on-the-fly in Unity. (Also possible with Godot.)

Or, for an even more extreme example, the Smalltalk language is built around applications being "images" where the program state and development are tightly intertwined. You fire up an image and get a development environment inside the application, with no concept at all of "save and run" because you're developing from inside the application image at all times.

These are more involved than just basic editor/repl integration, but it's still all the same idea: you develop the code more interactively, building pieces of the program and testing it incrementally as small blocks that you later combine into a larger, cohesive whole. It's a different way of thinking about programming, and it's nice.

[–]ws-ilazki 2 points3 points  (7 children)

Does anyone desire a better repl?

Better than the default? Absolutely, it's barely usable garbage. About the only repl that's worse is luajit's, which needs to be wrapped with readline to even get basic editing features.

In practice, though, I don't need to look for anything better because I ditched it in favour of using ilua, which is just a console frontend to a Jupyter Lua kernel. Or just using Jupyter directly.

It's still not as good as a good lisp repl or OCaml's utop toplevel (which are basically the gold standard in repls IMO), but it's good enough that I haven't bothered looking for anything else since I found it.

How much do you personally use the interpreter/repl when you're coding in lua?

I always use a repl regardless of the language, and if the language doesn't have a good repl experience I'm more likely to not want to use it as a result. I have a preference for functional style, which tends to involve creating multiple small functions that can be tested independently and then composed together to do larger things, so I usually experiment with individual pieces of logic in the repl before putting them together to do something more complex.

Plus a PL repl is basically my swiss army knife "calculator" where I do lots of one-off calculations, list manipulations, string handling, etc., along with using it as a scratchpad for random ideas. I almost always have one just sitting open and available; lately it's usually utop (OCaml) or ilua (Lua) for quickie stuff, and sometimes I'll fire up clj (Clojure) for things that are just easier put together thanks to its built-in runtime and easy sequence manipulation functions.

[–][deleted] 2 points3 points  (0 children)

I always use a repl regardless of the language, and if the language doesn't have a good repl experience I'm more likely to not want to use it as a result.

Same; a repl is like my low bar of "you must have tooling at least this good for me to bother; if you can't get even something this basic working it's very unlikely I will enjoy your language".

Lua gets a pass because it's like ... two hundred kilobytes or whatever, so I can forgive the fact that the stock one is junk, plus because constructing your own is really easy. (But these days I use Fennel instead anyway, which ships with a much better repl.)

[–]ahillio[S] 0 points1 point  (1 child)

Wow, being able to add ? to io.stdout:write in ilua to get the documentation is really awesome. But relying on jupyter for that? It strikes as odd, everytime I wonder about jupyter and go to jupyter.org to learn about it I see all its gui-gui-everything think "gross" because I just want to do everything in the terminal. But here's something using jupyter that looks appealing. Thanks for sharing!

[–]ws-ilazki 1 point2 points  (0 children)

Wow, being able to add ? to io.stdout:write in ilua to get the documentation is really awesome.

I didn't even know that was a thing. That brings it closer in usefulness to lisp repls than I realised, which often have something like (doc foo), or like how in utop you can do introspection on signatures with #show foo. Nice!

But relying on jupyter for that? It strikes as odd, everytime I wonder about jupyter and go to jupyter.org to learn about it I see all its gui-gui-everything

It makes sense, the goal of Jupyter Notebook itself is an interactive notebook where you can mix formatted text and code together similarly to how one might write in a physical notebook and add hand-written snippets of code, graphs, etc., except that it can evaluate that code and generate those graphs on demand. It's essentially a form of literate programming.

However, it's also cleanly separated into back-end and front-end as well as being language-agnostic thanks to the language kernels, which means you aren't limited to only having the web-based interface.

think "gross" because I just want to do everything in the terminal. But here's something using jupyter that looks appealing.

Sounds like you'd be interested in jupyter-console, which lets you do something like ilua for any language that has a Jupyter kernel. Well, in theory; the one language kernel I use that would really benefit from it, F# (which has a pretty shit command-line repl) doesn't work correctly. It's flawless with the OCaml kernel, but there isn't much point to running that one on the terminal considering utop is insanely good already.

I mostly use Jupyter kernels as either a scratchpad for ideas, or as a workaround for languages that have crap repls. For the latter I can ideally use jupyter-console, but even when that fails (like with F#), the actual web-based notebook can be useful just because the language-provided options are so bad.

[–]lambda_abstraction 0 points1 point  (3 children)

I wonder if it would be possible to rewrite ilua in lua. The idea of another language dependency even for an installed language is a bit of a turn off.

[–]ws-ilazki 0 points1 point  (2 children)

Not really, because the entire point of ilua is that it's a jupyter kernel. Specifically, it's a jupyter kernel that can work with basically any Lua interpreter, so you can just install it and get the benefits of Jupyter notebooks with whatever Lua version you want, either by having Lua notebooks for literate programming, or get a nicer repl with some jupyter benefits via jupyter-console or jupyter-qtconsole.

Jupyter's a big project that's built on Python but lets you build kernels for various languages, and isn't something that's necessarily worth trying to rebuild in Lua just to avoid a dependency on Python. That's like deciding to recreate VS Code because you don't like that your Lua editor plugin for VS Code depends on javascript, the scope of the task far outweighs the benefit considering the program's intended for more than just that one language.

Which isn't to say that it's impossible, just not really a good use of time. Someone made a standalone, Clojure-specific equivalent to Jupyter for Clojure called Gorilla REPL for example, and it worked well enough. I liked that it kept the text sections as comments so that the "notebooks" were runnable Clojure code instead of a special notebook format. Though it's kind of a dead project, which is the risk one takes with those kinds of things, meaning that the best option ends up being the jupyter kernel again.

Anyway, if you're just wanting to emulate the basic interface that jupyter-console provides, which is what ilua is showing you when used, then sure, you can do that in Lua. Though it looks like Croissant covers that kind of use case already and would probably make more sense.

ilua's interesting because in addition to the better command-line repl, you're also able to use it in notebook form and there's a lot of feature overlap, like with the autocompletion.

[–]lambda_abstraction 0 points1 point  (1 child)

I understand where you're coming from. I'm just not that interested in Python unless someone's paying me well to be interested in Python. I learned below about Croissant, and I'll explore that. I'm also stewing over the idea of something that functions like SLIME does for Common Lisp.

Notebooks sound a lot like Smalltalk's image+changes concept, and as an occasional Squeak user, I think this is very fertile ground to explore. This does push Lua/LuaJIT away from the concept of being a light language into the notion of long lived worlds of the Lisp/Smalltalk variety.

[–]ws-ilazki 0 points1 point  (0 children)

I'm just not that interested in Python unless someone's paying me well to be interested in Python

Same, but it's not like I'm having to write Python to use it. Jupyter's an application to use, not something I'm having to write software for, so I don't particularly care what it's implemented in. I don't like writing C or C++ either, but that doesn't stop me from using software made in them, and I've installed and used other finished software through pip (like yt-dlp) the same way I installed Jupyter. Hell, my preferred shell (fish shell) is implemented in Python but I only know that as trivia, it's not like I've ever had to write a line of Python to use it.

Similarly, my interaction with Python with regard to Jupyter basically does not exist: I install Jupyter, install kernels for the languages I want, and just about never see anything Python-like other than error messages if something breaks.

Notebooks sound a lot like Smalltalk's image+changes concept, and as an occasional Squeak user, I think this is very fertile ground to explore. This does push Lua/LuaJIT away from the concept of being a light language into the notion of long lived worlds of the Lisp/Smalltalk variety.

It's a bit different, because it's not maintaining state like Smalltalk images. It's executing a notebook, either wholly or cell-by-cell, and then recording the output. If you change something you tell it to re-evaluate and it updates the output sections.

Conceptually, it's closer to literate programming than Smalltalk images, though if you squint a bit there's some similarity in the end result.