0

I'm trying to make a script that will prompt the user and wait for them to press a key indicating the answer, or if no key is pressed for a fixed amount of time choose the default option.

Sadly, I'm doing this in an environment with lua embedded into it, so I cannot add libraries or modify the source. Also io.read blocks until the user presses enter and io.popen is not available.

Is it possible to do this?

P.S. I need this for a game where something is happening by time, proceeding in stages, and you need to decide when to take action without much time to think about it. If you can think of another way to do this, please tell me.

2
  • It's not possible to know how to do this without knowing something about the environment in which your Lua is being embedded. You seem to have access to certain standard Lua libraries. Are you able to load external libraries (via require and so forth)? Commented Jun 25, 2012 at 17:59
  • @NicolBolas I tried, but all ones included in the environment are loaded by default. Commented Jun 25, 2012 at 19:06

1 Answer 1

1

wait for them to press a key [..] II cannot add libraries or modify the source [..] io.read blocks until the user presses enter [..] Is it possible to do this?

No. Lua's IO libraries are based on C's IO libraries, which are all stream based. There's no way to detect keypresses. So, no, without extending Lua with native code (which you say you cannot do), this is not possible.

Sign up to request clarification or add additional context in comments.

4 Comments

In that case, can you think of another way to reach my goal? (edited the post)
Other than requiring them to press a key then press ENTER, no. If you told us the environment you're working in, we might be able to help you find an option you overlooked.
Ahh... so this is something you're doing for fun. You have no solution, other than asking the author of TouchLua to add this feature for you. You could jailbreak and run a console version of Lua in BASH via OpenSSH + iOS SSH client. If you had an iPad, you could run Codea, which lets your write complete games with graphics and sound in Lua.
Now that I think of it, I requested a fix for the same issue in the author's app HandBASIC (which is now fixed). I guess they wouldn't mind doing this too, right? And thanks for the answer, it will probably save a lot of newbies from hours of research.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.