Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/actions/ci/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,26 @@ runs:
# what the C++ Server-side SDK shared object expects. Same for hiredis which is bundled
# with the SDK release.
LD_LIBRARY_PATH: ${{ steps.install-boost.outputs.BOOST_ROOT }}/lib;./cpp-sdk/build-dynamic/release/lib

- name: Run hello-lua-server example
if: ${{ !contains(inputs.lua-version, 'jit') }}
shell: bash
env:
LD_SDK_KEY: "fake-sdk-key"
# Needed because boost isn't installed in default system paths, which is
# what the C++ Server-side SDK shared object expects.
LD_LIBRARY_PATH: ${{ steps.install-boost.outputs.BOOST_ROOT }}/lib
run: |
lua ./examples/hello-lua-server/hello.lua


- name: Run hello-lua-server example (JIT)
if: ${{ contains(inputs.lua-version, 'jit') }}
shell: bash
env:
LD_SDK_KEY: "fake-sdk-key"
# Needed because boost isn't installed in default system paths, which is
# what the C++ Server-side SDK shared object expects.
LD_LIBRARY_PATH: ${{ steps.install-boost.outputs.BOOST_ROOT }}/lib
run: |
luajit ./examples/hello-lua-server/hello.lua
37 changes: 37 additions & 0 deletions examples/hello-lua-server/hello.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
local ld = require("launchdarkly_server_sdk")

-- Allows the LaunchDarkly SDK key to be specified as an environment variable (LD_SDK_KEY)
-- or locally in this example code (YOUR_SDK_KEY).
function get_key_from_env_or(existing_key)
if existing_key ~= "" then
return existing_key
end

local env_key = os.getenv("LD_SDK_KEY")
if env_key ~= "" then
return env_key
end

error("No SDK key specified (use LD_SDK_KEY environment variable or set local YOUR_SDK_KEY)")
end

-- Set YOUR_SDK_KEY to your LaunchDarkly SDK key.
local YOUR_SDK_KEY = ""

-- Set YOUR_FEATURE_KEY to the feature flag key you want to evaluate.
local YOUR_FEATURE_KEY = "my-boolean-flag"


local config = {}

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

local user = ld.makeContext({
user = {
key = "example-user-key",
name = "Sandy"
}
})

local value = client:boolVariation(user, YOUR_FEATURE_KEY, false)
print("feature flag "..YOUR_FEATURE_KEY.." is "..tostring(value).." for this user")