diff --git a/.github/actions/ci/action.yml b/.github/actions/ci/action.yml index f9f88ba..4f5a176 100644 --- a/.github/actions/ci/action.yml +++ b/.github/actions/ci/action.yml @@ -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 diff --git a/examples/hello-lua-server/hello.lua b/examples/hello-lua-server/hello.lua new file mode 100644 index 0000000..32f5f93 --- /dev/null +++ b/examples/hello-lua-server/hello.lua @@ -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")