lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Wed, Jun 22, 2016 at 7:10 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> 2016-06-21 2:10 GMT+02:00 Egor Skriptunoff <egor.skriptunoff@gmail.com>:
>
>> https://github.com/Egor-Skriptunoff/pure_lua_alert
>>
>> The functionality is similar to JavaScript alert() function.
>> "alert()" creates a window with specified text and waits
>> until user closed the window (by pressing any key).
>>
>> local alert = require("alert")
>> alert("Hello")
>>
>> "alert.lua" is pure Lua module, compatible with Lua 5.3, 5.2, 5.1, and
>> LuaJIT.
>> It does not depend on any C library, all it needs is "os.execute()" and
>> "io.popen()".
>> It works on Linux, Mac OS X, Windows and Cygwin.
>>
>> "alert()" performs its task by invoking terminal emulator
>> and executing shell command "echo YourMessage" inside it:
>> 1) "CMD.EXE" (Windows Command Prompt) is used on Windows and Cygwin;
>> 2) "Terminal.app" is used on Mac OS X;
>> 3) any of 17 supported terminal emulators (if found to be installed on your
>> system)
>> is used on Linux.
>
> This is fun!
>
> Can the technique be expanded to give pure Lua dialog and
> radio boxes? File selection?
>

On UNIX-based systems, at least, you could wrap around the `dialog`
command, though of course that adds a dependency.

I would point out that there are better alternatives than popping open
a shell window on almost all platforms, though. On OSX, you can invoke
osascript with a tiny little AppleScript to pop open a message box
(though I've heard rumors that Apple has broken this in some contexts
so this needs research). On Linux, there's xmessage, gmessage,
kdialog, zenity, xdialog, shellgui, gxmessage, and gtkdialog that I
can find on a quick search; most users will have one of the first
three installed already. And on Windows, you can shell out to
PowerShell instead of cmd.exe to get a native dialog.

/s/ Adam