> ## Documentation Index
> Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Lua SDK reference

> This topic documents how to get started with the Lua SDK, and links to reference information on all of the supported features.

> For the complete documentation index, see [llms.txt](/llms.txt). For the full documentation snapshot, see [llms-full.txt](/llms-full.txt).

## Overview

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](/guides/sdk/nginx) and [HAProxy](/guides/sdk/haproxy).

<Note title="SDK quick links">
  LaunchDarkly's SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and sample applications:
</Note>

| Resource | Location |
| - | - |
| SDK API documentation | [SDK API docs](https://launchdarkly.github.io/lua-server-sdk/modules/launchdarkly-server-sdk.html) |
| Supported SDK Versions | [Lua server SDK](../concepts/supported-versions#lua-server-sdk) |
| GitHub repository | [lua-server-sdk](https://github.com/launchdarkly/lua-server-sdk) |
| Sample applications | [Lua](https://github.com/launchdarkly/hello-lua-server) ,  [Lua with HAProxy](https://github.com/launchdarkly/hello-haproxy) ,  [Lua with OpenResty NGINX](https://github.com/launchdarkly/hello-nginx) |
| Published module | [LuaRocks](https://luarocks.org/modules/launchdarkly) |

## Get started

After you complete the [Getting Started](/home/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++ server-side SDK. You need to install the C++ server-side SDK dynamic library somewhere accessible by the linker.

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

### Install the SDK

First, include the library:

<CodeGroup>
  ```lua title="Lua" theme={null}
      local ld = require("launchdarkly_server_sdk")
  ```
</CodeGroup>

<Note title="The Lua SDK uses an SDK key">
  The Lua SDK uses an SDK key. Keys are specific to each project and environment. They are available from **Project settings**, on the **Environments** list. To learn more about key types, read [Keys](/sdk/concepts/client-side-server-side#keys).
</Note>

### Initialize the client

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.

<Warning title="LDClient must be a singleton">
  It's important to make `LDClient` a singleton for each LaunchDarkly project. 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.

  If you have multiple LaunchDarkly projects, you can create one `LDClient` for each. In this situation, the clients operate independently. For example, they do not share a single connection to LaunchDarkly.
</Warning>

Calling `clientInit` initiates a remote call to the LaunchDarkly service to fetch feature flags. This call blocks up for the time that you provide in milliseconds. If you request a feature flag before the client completes initialization, you will receive the default flag value.

Here is an example:

<CodeGroup>
  ```lua title="Lua" theme={null}
      -- This will block for 1 second
      local client = ld.clientInit("YOUR_SDK_KEY", 1000, config)
  ```
</CodeGroup>

To learn more about the specific configuration properties that are available in this SDK, read [`clientInit`](https://launchdarkly.github.io/lua-server-sdk/modules/launchdarkly-server-sdk.html#clientInit).

### Evaluate a context

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

Here's how:

<CodeGroup>
  ```lua title="Lua SDK v1.x" theme={null}
      if client:boolVariation(context, "example-flag-key", false) then
          print "feature is enabled"
      else
          print "feature is disabled"
      end
  ```

  ```lua title="Lua SDK v1.x" theme={null}
      if client:boolVariation(user, "example-flag-key", false) then
          print "feature is enabled"
      else
          print "feature is disabled"
      end
  ```
</CodeGroup>

## Supported features

This SDK supports the following features:

* [Aliasing users](/sdk/features/aliasing-users#lua)
* [Anonymous contexts and users](/sdk/features/anonymous#lua)
* [Configuration](/sdk/features/config#lua), including
  * [Application metadata configuration](/sdk/features/app-config#lua)
  * [Service endpoint configuration](/sdk/features/service-endpoint-configuration/server-side#lua)
* [Context configuration](/sdk/features/context-config/server-side#lua)
* [Evaluating flags](/sdk/features/evaluating#lua)
* [Flag evaluation reasons](/sdk/features/evaluation-reasons/server-side#lua)
* [Flushing events](/sdk/features/flush#lua)
* [Getting all flags](/sdk/features/all-flags#lua)
* [Identifying and changing contexts](/sdk/features/identify#lua)
* [Logging](/sdk/features/logging#lua)
* [Offline](/sdk/features/offline-mode#lua)
* [Private attributes](/sdk/features/private-attributes/server-side#lua)
* [Relay Proxy configuration](/sdk/features/relay-proxy-configuration)
  * [Using proxy mode](/sdk/features/relay-proxy-configuration/proxy-mode#lua)
  * [Using daemon mode](/sdk/features/relay-proxy-configuration/daemon-mode#lua)
* [Sending custom events](/sdk/features/events#lua)
* [Storing data](/sdk/features/storing-data#lua)
