lune
lune copied to clipboard
REPL configuration & ergonomics
Right now, accessing a built-in library in the REPL always needs to be done explicitly:
lune # Start the REPL
> require("@lune/net").request("...")
or
lune # Start the REPL
> fs = require("@lune/fs")
> net = require("@lune/net")
> print(fs.writeFile("myFile", net.request("...")))
This is not great since the point of the REPL is to have an environment to quickly iterate and experiment with Lune. Having to type out all this boilerplate every time you want to use it turns people away. There are a couple different solutions we could implement:
- We could add a flag to add in built-in libraries as globals:
lune -g # same as lune --global-builtins , or some variant of that
> fs.writeFile("downloadedFile.json", serde.encode("json", net.request("...")))
- We could allow a user to specify a small script that runs each time the REPL starts (something like
~/.lune/repl.luau
?~/.lunerc
?):
local fs = require("@lune/fs")
local net = require("@lune/net")
local serde = require("@lune/serde")
function downloadJsonFile(name: string, url: string)
fs.writeFile(name, serde.encode("json", net.request(url)))
end
lune # Start the REPL
> downloadJsonFile("downloadedFile.json", "...")
This is probably the better long-term approach, but is also slightly more complicated to implement and may have additional concerns since the REPL is no longer "pure" and can suddenly run additional files.