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


Lua SDK reference

Read time: 1 minute
Last edited: Sep 24, 2021


This reference guide documents basic usage of our Lua server-side SDK, and explains in detail how its functions work. Our SDKs are open source. To learn more, read Lua SDK GitHub repository. The online API docs contain the programmatic definitions of every type and method. You can also try this SDK out by cloning and running a sample application. We provide documentation for running the SDK in NGINX, and also HAProxy.

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 will need the C/C++ server-side SDK dynamic library to be installed somewhere accessible by the linker.

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

To get started, include the library:

1local ld = require("launchdarkly_server_sdk")

Once the SDK is installed and imported, you'll want to create a single, shared instance of the client. Specify your SDK key here so that your application will be authorized to connect to LaunchDarkly and for your application and environment.

LDClient should be a singleton

It's important to make this a singleton. The client instance maintains internal state that allows us to serve feature flags without making any remote requests. Be sure that you're not instantiating 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 has completed initialization, you receive the default flag value.

Here is an example:

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

Using client, you can check which variation a particular user should receive for a given feature flag:

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

Supported features

This SDK supports the following features: