Skip to content

Commit 462a3f3

Browse files
authored
fix: add hello-lua-server example (#41)
This incorporates a hello-lua example directly into the repo, allowing us to archive [hello-lua-server](https://github.com/launchdarkly/hello-lua-server).
1 parent ac483ba commit 462a3f3

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

.github/actions/ci/action.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,26 @@ runs:
9595
# what the C++ Server-side SDK shared object expects. Same for hiredis which is bundled
9696
# with the SDK release.
9797
LD_LIBRARY_PATH: ${{ steps.install-boost.outputs.BOOST_ROOT }}/lib;./cpp-sdk/build-dynamic/release/lib
98+
99+
- name: Run hello-lua-server example
100+
if: ${{ !contains(inputs.lua-version, 'jit') }}
101+
shell: bash
102+
env:
103+
LD_SDK_KEY: "fake-sdk-key"
104+
# Needed because boost isn't installed in default system paths, which is
105+
# what the C++ Server-side SDK shared object expects.
106+
LD_LIBRARY_PATH: ${{ steps.install-boost.outputs.BOOST_ROOT }}/lib
107+
run: |
108+
lua ./examples/hello-lua-server/hello.lua
109+
110+
111+
- name: Run hello-lua-server example (JIT)
112+
if: ${{ contains(inputs.lua-version, 'jit') }}
113+
shell: bash
114+
env:
115+
LD_SDK_KEY: "fake-sdk-key"
116+
# Needed because boost isn't installed in default system paths, which is
117+
# what the C++ Server-side SDK shared object expects.
118+
LD_LIBRARY_PATH: ${{ steps.install-boost.outputs.BOOST_ROOT }}/lib
119+
run: |
120+
luajit ./examples/hello-lua-server/hello.lua
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
local ld = require("launchdarkly_server_sdk")
2+
3+
-- Allows the LaunchDarkly SDK key to be specified as an environment variable (LD_SDK_KEY)
4+
-- or locally in this example code (YOUR_SDK_KEY).
5+
function get_key_from_env_or(existing_key)
6+
if existing_key ~= "" then
7+
return existing_key
8+
end
9+
10+
local env_key = os.getenv("LD_SDK_KEY")
11+
if env_key ~= "" then
12+
return env_key
13+
end
14+
15+
error("No SDK key specified (use LD_SDK_KEY environment variable or set local YOUR_SDK_KEY)")
16+
end
17+
18+
-- Set YOUR_SDK_KEY to your LaunchDarkly SDK key.
19+
local YOUR_SDK_KEY = ""
20+
21+
-- Set YOUR_FEATURE_KEY to the feature flag key you want to evaluate.
22+
local YOUR_FEATURE_KEY = "my-boolean-flag"
23+
24+
25+
local config = {}
26+
27+
local client = ld.clientInit(get_key_from_env_or(YOUR_SDK_KEY), 1000, config)
28+
29+
local user = ld.makeContext({
30+
user = {
31+
key = "example-user-key",
32+
name = "Sandy"
33+
}
34+
})
35+
36+
local value = client:boolVariation(user, YOUR_FEATURE_KEY, false)
37+
print("feature flag "..YOUR_FEATURE_KEY.." is "..tostring(value).." for this user")

0 commit comments

Comments
 (0)