nested callback

Hi.

I’m trying to use Pubnub with Corona SDK:

https://github.com/pubnub/lua/tree/master/corona

I can subscribe and send messages ok, but when I try to use the “time” function, I get this error:

Runtime error     /Users/Frode/Documents/Corona\_Files/Roto/pubnub.lua:534: attempt to call upvalue 'callback' (a table value)

I require Pubnub like this:

require "pubnub" pubnub\_obj = pubnub.new({     publish\_key = "xxx",     subscribe\_key = "xxx",     secret\_key = "xxx",     ssl = nil, origin = "pubsub.pubnub.com" }) function getPubNubTime()     pubnub\_obj:time({         callback = function(time) -- PRINT TIME             print("PUBNUB SERVER TIME: " .. time)         end     }) end   getPubNubTime( )  

I’m not a lua wizard, but it seems strange to have two “callback’s” in the self:time function??

This is what the “time” functions looks like inside the “pubnub.lua” file:

function self:time(callback)         if not callback then             return print("Missing Time Callback")         end         self:\_request({             url = build\_url({ "time", "0" }),             callback = function(response)                 if response then                     return callback(response[1])                 end                     callback(nil)             end,             fail = function(response)                 callback(nil)             end         })     end  

Best Regards,

Frode

Have you tried using it like this :

[lua]

function getPubNubTime()
    pubnub_obj:time(function(time)
        print("PUBNUB SERVER TIME: " … time)
    end)
end
getPubNubTime( )
[/lua]

Regards,

Keyosk

Yes that worked. Thank you. I’ve spoken to the Pubnub people and they have allready updated the docs :slight_smile:

Have you tried using it like this :

[lua]

function getPubNubTime()
    pubnub_obj:time(function(time)
        print("PUBNUB SERVER TIME: " … time)
    end)
end
getPubNubTime( )
[/lua]

Regards,

Keyosk

Yes that worked. Thank you. I’ve spoken to the Pubnub people and they have allready updated the docs :slight_smile: