PubNub LogoDocs
SupportContact SalesLoginTry Our APIs

›API Reference

lUA

  • Getting Started
  • API Reference

    • Configuration
    • Publish & Subscribe
    • Presence
    • Message Persistence
    • Miscellaneous
  • Change Log
  • Feature Support
  • Platform Support

Configuration API for PubNub Lua SDK

Lua complete API reference for building real-time applications on PubNub, including basic usage and sample code.

Initialization

Including the code

require "pubnub"

Description

This function is used for initializing the PubNub Client API context. This function must be called before attempting to utilize any API functionality in order to establish account level credentials such as publish_key and subscribe_key.

Method(s)

To Initialize PubNub you can use the following method(s) in the Lua SDK:

pubnub_obj = pubnub.new(configuration)
ParameterTypeRequiredDescription
configurationtableYesTable of initialization parameters (a kind of prototype to construct the PubNub object from). See Configuration Parameters for more details.

Configuration Parameters:

PropertiesTypeRequiredDefaultsDescription
publish_keystringOptional (required only for publish)noneThe PubNub publish key.
subscribe_keystringYesnoneThe PubNub subscribe key.
secret_keystringOptionalnoneThe secret key.
auth_keystringOptionalnoneThe auth key to access channels.
sslbooleanOptionalfalseWhether to use SSL to connect to PubNub.
originstringOptionalps.pndsn.comThe domain name to use to connect to PubNub.
uuidstringYesUUID to use. You should set a unique UUID to identify the user or the device that connects to PubNub.
If you don't set the UUID, you won't be able to connect to PubNub.

Basic Usage

Initialize the PubNub client API:

Note

Always set the UUID to uniquely identify the user or device that connects to PubNub. This UUID should be persisted, and should remain unchanged for the lifetime of the user or the device. If you don't set the UUID, you won't be able to connect to PubNub.

require "pubnub"

local pubnub_obj = pubnub.new({
    publish_key = "demo",
    subscribe_key = "demo",
    secret_key = "demo",
    ssl = false,
    origin = "ps.pndsn.com"
})

Returns

It returns the PubNub instance for invoking PubNub APIs like publish(), subscribe(), history(), here_now(), etc.

← Getting StartedPublish & Subscribe →
  • Initialization
    • Description
    • Method(s)
    • Basic Usage
    • Returns
© PubNub Inc. - Privacy Policy