menislici
menislici

Reputation: 1167

What are events in lua functions

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.

Upvotes: 2

Views: 4336

Answers (2)

Michal Kottman
Michal Kottman

Reputation: 16753

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)

Upvotes: 3

jpjacobs
jpjacobs

Reputation: 9559

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.

Upvotes: 1

Related Questions