Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
suggestion for Timer.delayedCall — Gideros Forum

suggestion for Timer.delayedCall

alexzhengalexzheng Guru
edited May 2012 in Suggestions & requests
It's a very handy function, will it support to call mutiple arguments function in future version?

for example

function test(a, b, c)
print(a, b, c)
end

Timer.delayedCall(1000, test, 1, 2, 3)

Comments

  • You could make your own while you wait for Atilim:
    Timer._originalDelayedCall = Timer.delayedCall
    Timer.delayedCall = function(delay, func, ...)
       Timer._originalDelayedCall(delay, function() func(unpack(arg)) end)
    end
  • isn't that similar to another API from the Mexican Beer, that is timer.performWithDelay(delay, function)
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • You could make your own while you wait for Atilim:
    Timer._originalDelayedCall = Timer.delayedCall
    Timer.delayedCall = function(delay, func, ...)
       Timer._originalDelayedCall(delay, function() func(unpack(arg)) end)
    end
    great,thanks!
    Is arg deprecated?
  • http://www.luafaq.org/#T1.23

    I think the way I used it is not deprecated, but according to the faq it's not robust in the case where one if the arguments is nil?
  • petecpetec Member
    I've always used this sort of thing when I want to include arguemnts in a delayed call:
    function test(a, b, c)
        print(a, b, c)
    end
     
    Timer.delayedCall(1000, function() test(1, 2, 3) end)
    Might that cause a problem too? If I miss the final argument it prints 1 2 nil.
  • http://www.luafaq.org/#T1.23

    I think the way I used it is not deprecated, but according to the faq it's not robust in the case where one if the arguments is nil?
    I got a little confused whether it is safe to use arg?

    From this thread, he said arg does not work in lua 5.2,although it works in 5.1

    http://stackoverflow.com/questions/9786051/getting-arg-to-work-in-a-varag-function-in-lua-5-2-integrated-in-delphi

  • Your link is a little clearer than mine...it does look deprecated
  • alexzhengalexzheng Guru
    edited May 2012
    so, will this be safe?
    Timer._originalDelayedCall = Timer.delayedCall
    Timer.delayedCall = function(delay, func, ...)
       local arg = {...}
       Timer._originalDelayedCall(delay, function() func(unpack(arg)) end)
    end
  • ndossndoss Guru
    edited May 2012
    @alexzheng, your approach works for me and handles nils. I also saw the "{n=select('#',...),...}" construct used and recommended (see below). Don't know which is best / future-proof?
    Timer.oldDelayedCall = Timer.delayedCall
    Timer.delayedCall = function(delay, func, ...)
       local arg = {n=select('#', ...), ...}
       Timer.oldDelayedCall(delay, function() func(unpack(arg)) end)
    end
     
    function test(data1, data2, data3, data4) 
       print("GOT DATA:" , data1, data2, data3, data4)
    end
     
    Timer.delayedCall(4000, test, 4, 5, nil, "hello")
  • Very cool stuff, thanks for figuring this all out.
Sign In or Register to comment.