1

I want to write a function

whenever I call it must be make a sound alert is it possible in Lua ?

2
  • 1
    It's certainly possible, but not without work; There's no such function in the lua standard library. Are you sure you need this? There are few things more annoying than beeping programs.
    – Cubic
    Aug 5, 2014 at 9:42
  • 2
    How about print '\a' ?
    – Yu Hao
    Aug 5, 2014 at 11:10

1 Answer 1

2

This should be your solution:

os.execute("echo \7")

or

os.execute("echo \a")

This creates a short beep (using the speaker, not the beeper).

** Tested on Windows. But should work in UNIX also.

4
  • I could not execute it on SciTE or Eclipse Lua, I am taking the following error: "'' is not recognized as an internal or external command, operable program or batch file." how did you run it ? Aug 5, 2014 at 10:34
  • I get the same error, that is normal - but the beep comes anyway. You can look here: superuser.com/questions/227939/… I use only Notepad++ and Windows CMD.. No special thing like Eclipse or SciTE, i dont like them. It can be that your System does not accept the beep. Look the link above.
    – Mijago
    Aug 5, 2014 at 10:39
  • os.execute("echo \7") is better than os.execute("\7"). I edited it. Now you wont get the error message, but the beep will stay.
    – Mijago
    Aug 8, 2014 at 11:36
  • Doesn't work in my case. No error reported. Windows 10.
    – Sany
    Oct 15, 2020 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.