1

I am running lua script via scite in Ubuntu 12.04. When I execute an io.read program. example: (each command is on a separate line)

io.write("Please enter a number: ")
user_input = io.read()
print(user_input)

When I execute the program, I don't get a separate pop-up dialogue window asking for the user input.

I get, on the right hand side of the code, the following output:

> lua5.1 "io_examples.lua"
Please enter a number: nil

I know this may sound stupid, but how do I get the pop-up output window asking the the user's input?

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
user174743
  • 11
  • 1

2 Answers2

0

The nil returned by io.read could be a hint that an error has occurred during reading. You can check this by surrounding your io.read statement with an assert:

local user_input = assert(io.read())

or

local user_input = assert(io.read("*number")).

My initial guess is that you received a: bad file descriptor caused because the standard input (stdin) is not set.

More information can be found here:

http://www.lua.org/pil/21.1.html

http://www.lua.org/pil/8.html

Enigma
  • 1,699
  • 10
  • 14
  • Thank you for the reply! I tried both suggestions and here is what happened:io.write("Please enter a number: ") local user_input = assert(io.read()) print(user_input)>lua5.1 "io_examples.lua" lua5.1: io_examples.lua:2: assertion failed! stack traceback: [C]: in function 'assert' io_examples.lua:2: in main chunk [C]: ? Please enter a number: >Exit code: 1 – user174743 Aug 06 '13 at 18:50
  • Both suggestions returned the same result:Thank you for the reply! I tried both suggestions and here is what happened for both: >lua5.1 "io_examples.lua" lua5.1: io_examples.lua:2: assertion failed! stack traceback: [C]: in function 'assert' io_examples.lua:2: in main chunk [C]: ? Please enter a number: >Exit code: 1 – user174743 Aug 06 '13 at 18:57
  • My confusion is that the program is executing, but not allowing for the user to input anything. How do I make it so the program will wait and when the user actually enters a number, or whatever, the program will complete the execution? Is there another program I need to have installed besides scite to allow for the interactive window? – user174743 Aug 08 '13 at 03:33
0

How I finally got the program to execute correctly was from running it via ubuntu terminal. I simply had to cd to the directory where the program was located, then type "lua . I didn't get the neat pop-up window, but the code executed correctly.

user174743
  • 11
  • 1