如何在Lua中制作GUI应用程序

如何在Lua中制作GUI应用程序

问题描述:

首先,我将向您展示我所谈论的示例: GUI示例

First I'll show you an example of what I am talking about: GUI Example

我已经学习Lua大约一个星期了,我真的很好奇我将如何做.基本上(现在和出于学习目的),我只想制作一个带有2个按钮的GUI,一个按钮用于启动指定的(.exe),一个按钮用于退出GUI.

I've been studying Lua for around a week now, and I'm really curious of how I would do this. Basically (for now, and learning purposes), I just want to make a GUI with 2 buttons, 1 to start the specified (.exe), and one to exit the GUI.

这可能吗?我将如何去做呢?任何信息都很棒!

Is this possible? How would I go about doing this? Any information would be great!

如果您是绝对的初学者,即您没有任何其他编程语言的编程经验,我建议您很好地学习Lua,不要试图搞乱.使用GUI编程,这从本质上讲要困难得多. 当您对Lua有了一个很好的了解后,请使用Lua的GUI工具包.我使用 wxLua ,所以我只能给你一些提示.

If you are an absolute beginner, i.e. you don't have any programming experience in other programming languages, I advice you to learn Lua very well without trying to mess with GUI programming, which is inherently much harder. When you will have a good understanding of Lua, then go for a GUI toolkit for Lua. I use wxLua so I can only give you some hints on that.

由于它不是Lua工具包,而是对著名的跨平台GUI库的绑定".

Since it is not a "native" Lua toolkit, but it is a "binding" to a well-known cross-platform GUI library (wxWidgets) you must study both the wxLua documentation and wxWidgets manual (at least to some degree).

wxLua二进制发行版附带使用它所需的一切(您甚至不需要单独的Lua解释器,它都有自己的),并且包含大量示例应用程序.

wxLua binary distribution comes with everything needed to use it (you don't even need a separate Lua interpreter, it has its own) and contains a good number of example applications.

以下脚本是您想要做的事情的一个简单概括,但是(我再说一遍),在尝试进行GUI编程之前,您应该真正学习Lua的基础知识.

The following script is a trivial approximation of what you want to do, but (I repeat myself) you should really learn the basics of Lua before attempting GUI programming.

local wx = require 'wx'

local PATH_TO_APPLICATION = [[notepad.exe]]     -- Windows assumed for sake of exemplification

local ans = wx.wxMessageBox( "Should the application be started?", "Hi there!",
    wx.wxOK + wx.wxCANCEL + wx.wxICON_QUESTION )
if ans == wx.wxOK then
    wx.wxExecute( PATH_TO_APPLICATION )
end

要运行先前的脚本,必须确保在解释程序搜索路径中正确安装了wxLua.否则,您必须使用发行版随附的wxlua.exe解释器.

To run the previous script you must be sure that wxLua is installed correctly in your interpreter search path. Otherwise you must use the wxlua.exe interpreter that comes with the distribution.

还要注意,wxLua解释器(最新的wxLua稳定发行版)与Lua 5.1版本一起运行,因此请尽量不要在脚本中使用Lua 5.2的功能.基本的Lua语法和语义几乎相同,但是有一些细微的差异,并且Lua 5.2具有几个附加功能.因此,请小心您的学习路径.

Note also that wxLua interpreter (latest wxLua stable release) runs with a version of Lua 5.1, so try not to use features of Lua 5.2 in your scripts. Basic Lua syntax and semantics is almost the same, but there are some slight differences and Lua 5.2 has a couple of added features. So be careful with your learning path.