lua函数中的事件是什么
我了解函数中的参数,但不知道事件是什么。我也听说过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Lua 中没有什么特别的可以称为“事件”。我猜你正在谈论一般事件(来自维基百科):
事件的示例包括鼠标单击、按键、下载完成,以及您可以想象的任何内容。
为了对事件做出反应,您需要编写一个所谓的 处理程序 ,有时也称为监听器或回调,这是您注册以对特定事件做出反应的一段代码。可用的事件、处理过程和处理程序注册都由您使用的库/框架决定,即它不是 Lua 特定的,但 Lua 确实提供了函数作为编写处理程序的方式。
例如,在 Corona SDK(事件/监听器概述)中,您可以处理'触摸'事件如下:
There is nothing special in Lua that can be called 'event'. I guess you are talking about general events (from Wikipedia):
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:
标准 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.