Lua变量闭包

我刚接触 Lua,遇到了一些闭包问题。我有一个函数:

function cell(x,y,s, group)
    local myCircle = display.newCircle( x, y, s )
    myCircle.la = 1
    local myclosure = function()

      myCircle.la= myCirle.la + 1

    end
    timer.performWithDelay( 1500, myclosure, 0  )
    return true
end

但当定时器回调被执行时,我会收到一个错误:

   file.lua:39: attempt to index global 'myCirle' (a nil value)

函数 myclosure 能够“看到”函数 cell 中的变量吗?如果不行,有没有办法访问它们?

点赞
用户298661
用户298661

你的拼写错误了。错误实际上声称你尝试访问的是 "myCirle" 而不是 "myCircle"。

2012-08-14 18:48:59