lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> My question, is there a way of addressing an anonymous
> function inside itself ?

Objects are addressed by name/index in Lua.  There are at least two
approaches that I can think of.

1.  Define the function locally:

    do
        local function fun()
            print("hello")
            something.event:Remove(fun)
        end
        something.event:Add(fun)
    end

    (This cannot be done in Lua 4: in the construct "local fun = function
...", the name "fun" would _not_ refer to itself inside the function.)

2.  Extend the event mechanism so that it passes more info to its
subscribers.  Simplified:

    something.event:Add(function(event, subsciber)
        print "hello"
        event:Remove(subscriber)
    end)


--
Wim