Hacker News new | ask | show | jobs
by jandy 4680 days ago
Just run `lua` and you'll be dropped into a REPL. It's pretty basic compared to some other REPLs though, and I'd also be interested in hearing if there are some more user-friendly options out there.

My main gripe with the current REPL is it doesn't print anything to the screen without an explicit print call. So myMethod(x) will not print anything, instead you have to assign the result to a variable and print it or wrap everything you do in a call to print.

3 comments

Here is a hacky "REPL" of sorts in Lua:

  while true do
    io.write("> ")
    exp = io.read()
    print((loadstring("return " .. exp) or loadstring(exp))())
  end
Actually kinda works. Example session:

  > 5 + 5
  10
  > msg = "Hello"
  
  > print(msg)
  Hello

  > double = function(x) return x * 2 end

  > double(2)
  4
  > a = 4

  > b = a + 5

  > b
  9
Trading the ability to have multiline expressions for the ability to skip "return" sounds like a bad deal.
You can also get it to print things by returning them or by prepending "=" to them.

  Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
  > return "hi"
  hi
  > print "hi"
  hi
  > ="hi"
  hi
I agree that this is not ideal, though. It's possible to use a loader to make a more expression-oriented Lua, and then make a REPL that uses that.

  rlwrap lua
Might help. rlwrap is a wrapper program that adds readline functionality to programs that otherwise wouldn't have it.