• HOME
  • INTEGRATIONS
  • SDKS
  • GUIDES
  • API DOCS
No results for ""
EXPAND ALL
launchdarkly.com

EDIT ON GITHUB

Lua SDK reference

Read time: 1 minute
Last edited: Jun 18, 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. In addition to that, you can clone and run a sample application using this SDK. We provide documentation for running the SDK in NGINX, and also HAProxy.

Getting started

Building on top of our Getting Started guide, 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.

1local config = {
2 key = YOUR_SDK_KEY
3}
4
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"
3else
4 print "feature is disabled"
5end

Supported features

This SDK supports the following features: