inputbox function in Lua
|Opened on:||Friday, September 17, 2010 - 18:13|
|Last modified:||Sunday, November 11, 2012 - 10:04|
It would be useful for Lua to have an inputbox function.
In Visual Basic for Applications (VBA), the programming language used for macros in Microsoft Office, among other things, there is a function named InputBox. There are three arguments:
Inputbox(Prompt, Title, Default)
Title and Default are optional. Title defaults to the application name, i.e. Foldit, and Default defaults to a zero length string.
This function constructs a simple dialog that has a title bar, a label, a textbox, an OK button, and a Cancel button.
The function brings up the dialog and blocks further execution of the code until it returns, which happens when one of the buttons is clicked (Cancelling the script while the dialog is up will take down the dialog, too). The Prompt argument is placed into the label control on the dialog. The Title argument is placed onto the title bar of the dialog. The Default is used for the default text in the textbox. If a default is present, the text is selected when the dialog comes up, so that typing immediately replaces the default with what is typed.
The textbox has the focus when the dialog comes up, so that typing goes directly into the textbox.
The return value is always a string. For this to be useful in Lua, this means that we would need the math functions that allow parsing strings into numbers implemented as well.
This function would allow a Lua script to be able to gather information from a user with the minimum of implementation time. It isn't ideal if 15 pieces of information need to be gathered from the user, since that requires bringing up 15 inputboxes, but it would give our script at least some way of talking to the user with the minimum of development resources.