From c6c5ad56c9b4421e1bf8a5bc2f38323734a9d2eb Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 23 Aug 2012 19:27:12 +0400 Subject: Track lua event listener count, and let the C++ host know. This allows completely avoiding the call overhead if there are none. The downside is that the event object now has to be a userdata with lots of metamethods. --- Lua API.html | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'Lua API.html') diff --git a/Lua API.html b/Lua API.html index 0f1ecc3b..c4ab9c8c 100644 --- a/Lua API.html +++ b/Lua API.html @@ -1596,8 +1596,8 @@ Using timeout_active(id,nil) cancels the timer

Event type

-

An event is just a lua table with a predefined metatable that -contains a __call metamethod. When it is invoked, it loops +

An event is a native object transparently wrapping a lua table, +and implementing a __call metamethod. When it is invoked, it loops through the table with next and calls all contained values. This is intended as an extensible way to add listeners.

This type itself is available in any context, but only the @@ -1608,9 +1608,15 @@ core context has the actual events defined by C++ code.

Creates a new instance of an event.

  • event[key] = function

    -

    Sets the function as one of the listeners.

    +

    Sets the function as one of the listeners. Assign nil to remove it.

    NOTE: The df.NULL key is reserved for the use by -the C++ owner of the event, and has some special semantics.

    +the C++ owner of the event; it is an error to try setting it.

    +
  • +
  • #event

    +

    Returns the number of non-nil listeners.

    +
  • +
  • pairs(event)

    +

    Iterates over all listeners in the table.

  • event(args...)

    Invokes all listeners contained in the event in an arbitrary -- cgit v1.2.1