Murga-Projects Forums

Full Version: User Prompt
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Does anyone know how to prompt a user for input from a console application? Ideally, it would be able to mask the input for a password type field.
try io.read()

As a simple example, open up lua interactively.
type "var=io.read()"; it will wait for input.
type something else.
type "print(var)"; it will print whatever you typed previously.

I'm not sure about masking, but I'd be surprised if it's not available.
That is so basic. You think this would be step 2 after hello world.

Code:
--[[ lua command line user user input

o = the print() function
p = a prompt to the user
r = response from the computer
i =  i returns input waiting until line feed to continue execution
This example is all one line of code.
--]]

o ,p ,r = print, "Enter your name.","Hello "; o(p); i=io.read(); if i then o(r..i) end;


I had no  idea how to interactively give values to programs running in the command line until now. I'm sure its been in our telnet chat script forever and I totally overlooked it.

Thanks!

There is an interesting example of a text-based menu at lua-users:
http://lua-users.org/wiki/SampleCode (AsciiMenu)
Good examples. Thanx.
Reference URL's