• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
    No results for ""


    Lua SDK reference

    Read time: 1 minute
    Last edited: Sep 27, 2022


    This topic documents how to get started with the Lua SDK, and links to reference information on all of the supported features. We also provide documentation for running the SDK in NGINX and HAProxy.

    SDK quick links

    LaunchDarkly's SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and sample applications:

    SDK API documentationSDK API docs
    GitHub repositorylua-server-sdk
    Sample applicationshello-lua-server (Lua)
    hello-haproxy (Lua with HAProxy)
    hello-nginx (Lua with NGINX)
    Published moduleNone

    Getting started

    After you complete the Getting Started process, follow these steps to get started using the LaunchDarkly SDK in your Lua application.

    The Lua server-side SDK is implemented using a foreign function interface that calls the C/C++ server-side SDK. You need to install the C/C++ server-side SDK dynamic library somewhere accessible by the linker.

    To learn more, read C/C++ SDK reference (server-side).

    First, include the library:

    local ld = require("launchdarkly_server_sdk")

    After you install and import the SDK, create a single, shared instance of LDClient. Specify your SDK key here to authorize your application to connect to a particular environment within LaunchDarkly.

    LDClient must be a singleton

    It's important to make LDClient a singleton. The client instance maintains internal state that allows LaunchDarkly to serve feature flags without making any remote requests. Do not instantiate a new client with every request.

    Calling clientInit initiates a remote call to the LaunchDarkly service to fetch feature flags. This call blocks up to the time defined by maxwaitmilliseconds. If you request a feature flag before the client completes initialization, you will receive the default flag value.

    Here is an example:

    local config = {
    key = YOUR_SDK_KEY
    local client = ld.clientInit(config, 1000)

    You can use client to check which variation a particular user will receive for a given feature flag.

    Here's how:

    if client:boolVariation(user, YOUR_FEATURE_KEY, false) then
    print "feature is enabled"
    print "feature is disabled"

    Supported features

    This SDK supports the following features: