2

Luaで現在実行中の匿名関数を参照する方法はありますか? JavaScript でarguments.callee.

例えば:

local function newLiftAnimator(obj)
  local count = 0
  return function(event)
    -- animate obj's properties here on each "enterFrame" event
    obj.y = obj.y - 1
    count = count + 1
    -- when done, remove event listener
    if count >= 100 then
      Runtime:removeEventListener("enterFrame", **<this_function>**)
    end
  end
end

Runtime:addEventListener("enterFrame", newLiftAnimator(ball))
4

3 に答える 3

4

試す

local f
f=function (event) ... Runtime:removeEventListener("enterFrame", f) ... end
return f
于 2011-11-09T13:52:26.400 に答える
2

別の可能性は次を使用しています。

debug.getinfo(1,'f').func
于 2011-11-09T13:59:37.173 に答える
2

どうでも。Lua のメーリング リストでこの古いメッセージを読んだ後、私は明らかな解決策を思いつきました。

local function newLiftAnimator(obj)
  ...
  local function animator()
    ...
    Runtime:removeEventListener("enterFrame", animator)
  end
  return animator
end
于 2011-11-09T13:56:11.610 に答える