lua函数中的事件是什么

发布于 2024-12-15 02:04:58 字数 74 浏览 3 评论 0原文

我了解函数中的参数,但不知道事件是什么。我也听说过 JavaScript 函数事件,但由于我没有 js 经验,所以我不知道它们是什么。

I get the idea of parameters in functions, but I don't know what an event is. I have also heard of JavaScript function events but since I have no js experience, I don't know what they are.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

但可醉心 2024-12-22 02:04:58

Lua 中没有什么特别的可以称为“事件”。我猜你正在谈论一般事件(来自维基百科):

在计算中,事件是通常在程序范围之外启动并由程序内部的一段代码处理的操作

事件的示例包括鼠标单击、按键、下载完成,以及您可以想象的任何内容。

为了对事件做出反应,您需要编写一个所谓的 处理程序 ,有时也称为监听器回调,这是您注册以对特定事件做出反应的一段代码。可用的事件、处理过程和处理程序注册都由您使用的库/框架决定,即它不是 Lua 特定的,但 Lua 确实提供了函数作为编写处理程序的方式。

例如,在 Corona SDK(事件/监听器概述)中,您可以处理'触摸'事件如下:

Runtime:addEventListener("touch", function(event)
    print("A touch event is being handled")
    ...
end)

There is nothing special in Lua that can be called 'event'. I guess you are talking about general events (from Wikipedia):

In computing an event is an action that is usually initiated outside the scope of a program and that is handled by a piece of code inside the program

An example of events are a mouse click, key press, download finished, anything you can imagine.

In order to react to an event, you need to write a so-called handler, sometimes also called listener or callback, which is a piece of code that you register to react to a certain event. The available events, handling process and handler registration are all dictated by the library/framework you are using, i.e. it's not Lua specific, but Lua does provide functions as way to write handlers.

For example, in Corona SDK (overview of events/listeners), you can handle the 'touch' event as follows:

Runtime:addEventListener("touch", function(event)
    print("A touch event is being handled")
    ...
end)
格子衫的從容 2024-12-22 02:04:58

标准 Lua 函数中不存在“事件”这样的东西。也许有一些库可以为您提供它们,或者您可以编写脚本来模拟所需的行为。

如果您提供有关您想要完成的任务的信息并显示一些代码,您可以获得更具体的答案。

There is no such thing as an 'event' in a standard Lua function. Perhaps there is some library that provides you with them, or you could script your way around to emulate the wanted behaviour.

You can get more concrete answers if you provide info about what you want to accomplish, and show some code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文