English 中文(简体)
分析论点。 Lua的电话用户
原标题:Analog of arguments.callee in Lua

是否有办法提及目前在卢阿执行匿名职能? 就像我们在 Java里可以做的那样,用arguments.questee

例如:

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))
最佳回答

提 出

local f
f=function (event) ... Runtime:removeEventListener("enterFrame", f) ... end
return f
问题回答

另一种可能性是:

debug.getinfo(1, f ).func




相关问题
Why I can t pass two chars as function arguments in C?

I have a function: int get_symbol(tab *tp, FILE *fp, char delim) and I call it like this: get_symbol(tp, fp, ; ) I always have it declared in the header as: int get_symbol(tab *, FILE *, char); ...

problem w/ linking static function g++

I am trying to build a small program and I have my own library libfoo. I have a camera class that is calling a static function from my Vector3 class (i.e. crossProduct). My camera class and Vector3 ...

taking java method names as function arg in clojure

All, I want to create a function that takes a symbol representing a java method and applies it to some object: (user=> (defn f [m] (. "foo" (m))) When I execute this, I get a result much ...

Def, Void, Function?

Recently, I ve been learning different programming langages, and come across many different names to initalize a function construct. For instance, ruby and python use the def keyword, and php and ...

热门标签