Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2d31ac0
[ch66649] initial copy from moonshot (and minor template fill in)
hroederld Feb 20, 2020
b41bd5a
[ch66755] Add variationDetail variation handlers (#2)
hroederld Feb 28, 2020
4a001eb
[ch68367] prefix functions with local
hroederld Mar 9, 2020
c66ed75
[ch68610] Basic generated doc (#4)
hroederld Mar 10, 2020
e69359c
[ch70062] rename to launchdarkly-server-sdk.lua
hroederld Mar 19, 2020
24b9487
[ch70700] prepare 1.0.0-beta.1
hroederld Mar 24, 2020
6ed903a
Update CONTRIBUTING.md (#8)
bwoskow-ld Mar 24, 2020
17a35ef
Update README.md (#7)
bwoskow-ld Mar 24, 2020
f2bb53c
Merge github.com:launchdarkly/lua-server-sdk
hroederld Mar 25, 2020
791dd2e
remove circle badge (#9)
hroederld Mar 25, 2020
0e9db0d
Merge github.com:launchdarkly/lua-server-sdk
hroederld Mar 25, 2020
b1f585c
[ch70699] releaser support (#11)
hroederld Apr 1, 2020
3ab1ee2
[ch73979] document version constraints (#12)
hroederld Apr 17, 2020
f2ed7f1
[ch76282] add wrapper meta config (#13)
hroederld May 12, 2020
57517c1
prepare 1.0.0-beta.2 (content approved in previous failed release PR)
hroederld May 12, 2020
153dd3f
Merge github.com:launchdarkly/lua-server-sdk
hroederld May 12, 2020
bf8fd31
[ch80640] logging handler (#14)
hroederld Jun 23, 2020
77e52a1
[ch80816] basic unit tests (#15)
hroederld Jun 23, 2020
89806d4
[ch80958] remove beta warning
hroederld Jun 24, 2020
6b6a4c5
fix timeout (#17)
hroederld Jun 25, 2020
39da875
[ch70870] redis module (#18)
hroederld Jul 7, 2020
cbc133f
[ch70870] ldoc releaser redis (#19)
hroederld Jul 9, 2020
ad96c4e
[ch82399] document c server-side sdk version requirement (#20)
hroederld Jul 9, 2020
5eb0fdc
[ch82565] collect between tests (#21)
hroederld Jul 10, 2020
c5ab6f2
[ch82639] rewrite for lua 5.1 5.2 5.3 (#22)
hroederld Jul 20, 2020
8a76638
[ch83425] prepare beta 3 (#23)
hroederld Jul 20, 2020
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
87 changes: 82 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,94 @@ workflows:
version: 2
all:
jobs:
- build-doc-linux
- build-test-linux-luajit
- build-test-linux-lua53
- build-test-linux-lua52

jobs:
build-doc-linux:
build-test-linux-luajit:
docker:
- image: ubuntu:18.04
- image: redis
steps:
- checkout
- run:
name: Prepare
command: ./.ldrelease/linux-prepare.sh
command: |
apt-get update -y
apt-get install -y luajit libluajit-5.1-dev lua-ldoc zip \
ca-certificates curl zip lua-cjson libpcre3 libcurl4-openssl-dev \
cmake libhiredis-dev git build-essential libpcre3-dev luarocks

- run:
name: Build c-server-sdk
command: ./.ldrelease/build-c-server.sh

- run:
name: Build lua-server-sdk
command: |
luarocks make launchdarkly-server-sdk-1.0-0.rockspec
luarocks make launchdarkly-server-sdk-redis-1.0-0.rockspec

- run:
name: Run tests
command: |
luajit test.lua

build-test-linux-lua53:
docker:
- image: ubuntu:18.04
- image: redis
steps:
- checkout
- run:
name: Prepare
command: |
apt-get update -y
apt-get install -y lua5.3 liblua5.3-dev lua-ldoc zip \
ca-certificates curl zip lua-cjson libpcre3 libcurl4-openssl-dev \
cmake libhiredis-dev git build-essential libpcre3-dev luarocks

- run:
name: Build c-server-sdk
command: ./.ldrelease/build-c-server.sh

- run:
name: Build lua-server-sdk
command: |
luarocks make launchdarkly-server-sdk-1.0-0.rockspec
luarocks make launchdarkly-server-sdk-redis-1.0-0.rockspec

- run:
name: Run tests
command: |
lua5.3 test.lua

build-test-linux-lua52:
docker:
- image: ubuntu:18.04
- image: redis
steps:
- checkout
- run:
name: Prepare
command: |
apt-get update -y
apt-get install -y lua5.2 liblua5.2-dev lua-ldoc zip \
ca-certificates curl zip lua-cjson libpcre3 libcurl4-openssl-dev \
cmake libhiredis-dev git build-essential libpcre3-dev luarocks

- run:
name: Build c-server-sdk
command: ./.ldrelease/build-c-server.sh

- run:
name: Build lua-server-sdk
command: |
luarocks make launchdarkly-server-sdk-1.0-0.rockspec
luarocks make launchdarkly-server-sdk-redis-1.0-0.rockspec

- run:
name: Build Doc
command: ./.ldrelease/linux-build-docs.sh
name: Run tests
command: |
lua5.2 test.lua
11 changes: 11 additions & 0 deletions .ldrelease/build-c-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -e

git clone https://github.com/launchdarkly/c-server-sdk.git
cd c-server-sdk
mkdir build
cd build
cmake -D BUILD_SHARED_LIBS=ON -D BUILD_TESTING=OFF -D REDIS_STORE=ON ..
make
make install
6 changes: 5 additions & 1 deletion .ldrelease/linux-build-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ set -e

PROJECT_DIR=$(pwd)

ldoc launchdarkly-server-sdk.lua
mkdir tmp
cp launchdarkly-server-sdk.c tmp/
cp launchdarkly-server-sdk-redis.c tmp/

ldoc tmp

mkdir -p $PROJECT_DIR/artifacts
cd $PROJECT_DIR/doc
Expand Down
4 changes: 3 additions & 1 deletion .ldrelease/linux-prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

set -e

apt-get update -y && apt-get install -y lua-ldoc zip ca-certificates
apt-get update -y && apt-get install -y luajit lua-ldoc zip ca-certificates \
curl zip lua-cjson libpcre3 libcurl4-openssl-dev cmake libhiredis-dev git \
build-essential libpcre3-dev
2 changes: 1 addition & 1 deletion .ldrelease/update-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -e

sed -i "s/local SDKVersion =.*/local SDKVersion = \"${LD_RELEASE_VERSION}\"/" 'launchdarkly-server-sdk.lua'
sed -i "s/#define SDKVersion .*/#define SDKVersion \"${LD_RELEASE_VERSION}\"/" 'launchdarkly-server-sdk.c'
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ LaunchDarkly overview
Supported Lua versions
-----------

This version of the LaunchDarkly SDK is compatible with the Lua 5.1 interpreter, and LuaJIT. Lua 5.3 is not supported due to FFI constraints.
This version of the LaunchDarkly SDK is compatible with the Lua 5.1-5.3 interpreter, and LuaJIT.

Supported C server-side SDK versions
-----------

This version of the Lua server-side SDK depends on the C server-side SDK. The minimum required version is `2.1.0`, and under `3.0.0`.

Getting started
-----------
Expand Down
12 changes: 12 additions & 0 deletions attribution/luaunit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This software is distributed under the BSD License.

Copyright (c) 2005-2018, Philippe Fremy <phil at freehackers dot org>

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 changes: 29 additions & 0 deletions launchdarkly-server-sdk-1.0-0.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package = "launchdarkly-server-sdk"

version = "1.0-0"

source = {
url = "." -- not online yet!
}

dependencies = {
"lua >= 5.1, <= 5.4",
}

external_dependencies = {
LD = {
header = "launchdarkly/api.h"
}
}

build = {
type = "builtin",
modules = {
["launchdarkly_server_sdk"] = {
sources = { "launchdarkly-server-sdk.c" },
incdirs = {"$(LD_INCDIR)"},
libdirs = {"$(LD_LIBDIR)"},
libraries = {"ldserverapi"}
}
}
}
29 changes: 29 additions & 0 deletions launchdarkly-server-sdk-redis-1.0-0.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package = "launchdarkly-server-sdk-redis"

version = "1.0-0"

source = {
url = "." -- not online yet!
}

dependencies = {
"lua >= 5.1, <= 5.4",
}

external_dependencies = {
LDREDIS = {
header = "launchdarkly/store/redis.h"
}
}

build = {
type = "builtin",
modules = {
["launchdarkly_server_sdk_redis"] = {
sources = { "launchdarkly-server-sdk-redis.c" },
incdirs = {"$(LDREDIS_INCDIR)"},
libdirs = {"$(LDREDIS_LIBDIR)"},
libraries = {"ldserverapi-redis"}
}
}
}
110 changes: 110 additions & 0 deletions launchdarkly-server-sdk-redis.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/***
Server-side SDK for LaunchDarkly Redis store.
@module launchdarkly-server-sdk-redis
*/

#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

#include <launchdarkly/api.h>
#include <launchdarkly/store/redis.h>

/***
Initialize a store backend
@function makeStore
@tparam table fields list of configuration options
@tparam[opt] string fields.host Hostname for Redis.
@tparam[opt] int fields.port Port for Redis.
@tparam[opt] string fields.prefix Redis key prefix for SDK values.
@tparam[opt] int fields.poolSize Number of Redis connections to maintain.
@return A fresh Redis store backend.
*/
static int
LuaLDRedisMakeStore(lua_State *const l)
{
struct LDRedisConfig *config;
struct LDStoreInterface *storeInterface;

if (lua_gettop(l) != 1) {
return luaL_error(l, "expecting exactly 1 argument");
}

luaL_checktype(l, 1, LUA_TTABLE);

config = LDRedisConfigNew();

lua_getfield(l, 1, "host");

if (lua_isstring(l, -1)) {
LDRedisConfigSetHost(config, luaL_checkstring(l, -1));
}

lua_getfield(l, 1, "prefix");

if (lua_isstring(l, -1)) {
LDRedisConfigSetPrefix(config, luaL_checkstring(l, -1));
}

lua_getfield(l, 1, "port");

if (lua_isnumber(l, -1)) {
LDRedisConfigSetPort(config, luaL_checkinteger(l, -1));
}

lua_getfield(l, 1, "poolSize");

if (lua_isnumber(l, -1)) {
LDRedisConfigSetPoolSize(config, luaL_checkinteger(l, -1));
}

storeInterface = LDStoreInterfaceRedisNew(config);

struct LDStoreInterface **i =
(struct LDStoreInterface **)lua_newuserdata(l, sizeof(storeInterface));

*i = storeInterface;

luaL_getmetatable(l, "LaunchDarklyStoreInterface");
lua_setmetatable(l, -2);

return 1;
}

static const struct luaL_Reg launchdarkly_functions[] = {
{ "makeStore", LuaLDRedisMakeStore },
{ NULL, NULL }
};

#if !defined LUA_VERSION_NUM || LUA_VERSION_NUM==501
/*
** Adapted from Lua 5.2.0
*/
static void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
luaL_checkstack(L, nup+1, "too many upvalues");
for (; l->name != NULL; l++) { /* fill the table with given functions */
int i;
lua_pushstring(L, l->name);
for (i = 0; i < nup; i++) /* copy upvalues to the top */
lua_pushvalue(L, -(nup+1));
lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
lua_settable(L, -(nup + 3));
}
lua_pop(L, nup); /* remove upvalues */
}
#endif

int
luaopen_launchdarkly_server_sdk_redis(lua_State *const l)
{
#if LUA_VERSION_NUM == 503 || LUA_VERSION_NUM == 502
luaL_newlib(l, launchdarkly_functions);
#else
luaL_register(l, "launchdarkly-server-sdk-redis",
launchdarkly_functions);
#endif

return 1;
}
Loading