【发布时间】:2014-08-21 08:39:16
【问题描述】:
我使用 corona sdk 已经有一段时间了,想开始用我的多用户应用程序实现 pubnub。
我下载了 lua-master zip 文件并将其解压缩。我需要在我的 corona 应用程序目录中使用哪些文件和文件夹才能开始测试? - 谢谢
【问题讨论】:
我使用 corona sdk 已经有一段时间了,想开始用我的多用户应用程序实现 pubnub。
我下载了 lua-master zip 文件并将其解压缩。我需要在我的 corona 应用程序目录中使用哪些文件和文件夹才能开始测试? - 谢谢
【问题讨论】:
通过访问开始: https://github.com/pubnub/lua/tree/master/corona
用于构建和扩展多人移动游戏的 PubNub 数据流网络。游戏状态变化、玩家移动、位置感知和监控。
请务必将"pubnub.lua" 复制到您的项目目录中,
并查看3.3目录中的示例代码以获得完整的代码示例!
pubnub.lua-> https://github.com/pubnub/lua/blob/master/corona/pubnub.lua
require "pubnub"
multiplayer = pubnub.new({
publish_key = "demo", -- YOUR PUBLISH KEY
subscribe_key = "demo", -- YOUR SUBSCRIBE KEY
secret_key = nil, -- YOUR SECRET KEY
ssl = nil, -- ENABLE SSL?
origin = "pubsub.pubnub.com" -- PUBNUB CLOUD ORIGIN
})
multiplayer:publish({
channel = "lua-corona-demo-channel",
message = { "1234", 2, 3, 4 },
callback = function(info)
-- WAS MESSAGE DELIVERED?
if info[1] then
print("MESSAGE DELIVERED SUCCESSFULLY!")
else
print("MESSAGE FAILED BECAUSE -> " .. info[2])
end
end
})
multiplayer:subscribe({
channel = "lua-corona-demo-channel",
callback = function(message)
-- MESSAGE RECEIVED!!!
print(Json.Encode(message))
end,
errorback = function()
print("Network Connection Lost")
end
})
multiplayer:unsubscribe({
channel = "lua-corona-demo-channel"
})
function detailedHistory(channel, count, reverse)
pubnub_obj:detailedHistory({
channel = channel,
count = count,
reverse = reverse,
callback = function(response)
if response then
for k, v in pairs(response[1])
do
print( type (v) )
if (type (v) == 'string')
then print(v)
elseif (type (v) == 'table')
then
for i,line in ipairs(v) do
print(line)
end
end
end
end
end
})
end
local my_channel = 'hello_world'
detailedHistory( my_channel, 5, false )
【讨论】: