In my lua program, i want to stop and ask user for confirmation before proceeding with an operation. I'm not sure how to stop and wait for user input, how can it be done?
DESCRIPTION. lua is the stand-alone Lua interpreter. It loads and executes Lua programs, either in textual source form or in precompiled binary form. (Precompiled binaries are output by luac, the Lua compiler.) lua can be used as a batch interpreter and also interactively.
The call io. read("*all") reads the whole current input file, starting at its current position. If we are at the end of file, or if the file is empty, the call returns an empty string.
Software developers typically open and modify LUA files with source code editors, such as Microsoft Visual Studio Code and MacroMates TextMate. Plain text editors, which include Microsoft Notepad and Apple TextEdit, may also be used to open and modify LUA files.
local answer
repeat
io.write("continue with this operation (y/n)? ")
io.flush()
answer=io.read()
until answer=="y" or answer=="n"
Take a look at the io
library, which by default has standard-input as the default input file:
http://www.lua.org/pil/21.1.html
I've worked with code like this. I will type this in a way it will work:
io.write("continue with this operation (y/n)?")
answer=io.read()
if answer=="y" then
--(put what you want it to do if you say y here)
elseif answer=="n" then
--(put what you want to happen if you say n)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With