Skip to content

Commit c4917d9

Browse files
1.0.0-beta.3 release (#10)
1 parent ed87f6c commit c4917d9

14 files changed

+4894
-637
lines changed

.circleci/config.yml

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,94 @@ workflows:
44
version: 2
55
all:
66
jobs:
7-
- build-doc-linux
7+
- build-test-linux-luajit
8+
- build-test-linux-lua53
9+
- build-test-linux-lua52
810

911
jobs:
10-
build-doc-linux:
12+
build-test-linux-luajit:
1113
docker:
1214
- image: ubuntu:18.04
15+
- image: redis
1316
steps:
1417
- checkout
1518
- run:
1619
name: Prepare
17-
command: ./.ldrelease/linux-prepare.sh
20+
command: |
21+
apt-get update -y
22+
apt-get install -y luajit libluajit-5.1-dev lua-ldoc zip \
23+
ca-certificates curl zip lua-cjson libpcre3 libcurl4-openssl-dev \
24+
cmake libhiredis-dev git build-essential libpcre3-dev luarocks
25+
26+
- run:
27+
name: Build c-server-sdk
28+
command: ./.ldrelease/build-c-server.sh
29+
30+
- run:
31+
name: Build lua-server-sdk
32+
command: |
33+
luarocks make launchdarkly-server-sdk-1.0-0.rockspec
34+
luarocks make launchdarkly-server-sdk-redis-1.0-0.rockspec
35+
36+
- run:
37+
name: Run tests
38+
command: |
39+
luajit test.lua
40+
41+
build-test-linux-lua53:
42+
docker:
43+
- image: ubuntu:18.04
44+
- image: redis
45+
steps:
46+
- checkout
47+
- run:
48+
name: Prepare
49+
command: |
50+
apt-get update -y
51+
apt-get install -y lua5.3 liblua5.3-dev lua-ldoc zip \
52+
ca-certificates curl zip lua-cjson libpcre3 libcurl4-openssl-dev \
53+
cmake libhiredis-dev git build-essential libpcre3-dev luarocks
54+
55+
- run:
56+
name: Build c-server-sdk
57+
command: ./.ldrelease/build-c-server.sh
58+
59+
- run:
60+
name: Build lua-server-sdk
61+
command: |
62+
luarocks make launchdarkly-server-sdk-1.0-0.rockspec
63+
luarocks make launchdarkly-server-sdk-redis-1.0-0.rockspec
64+
65+
- run:
66+
name: Run tests
67+
command: |
68+
lua5.3 test.lua
69+
70+
build-test-linux-lua52:
71+
docker:
72+
- image: ubuntu:18.04
73+
- image: redis
74+
steps:
75+
- checkout
76+
- run:
77+
name: Prepare
78+
command: |
79+
apt-get update -y
80+
apt-get install -y lua5.2 liblua5.2-dev lua-ldoc zip \
81+
ca-certificates curl zip lua-cjson libpcre3 libcurl4-openssl-dev \
82+
cmake libhiredis-dev git build-essential libpcre3-dev luarocks
83+
84+
- run:
85+
name: Build c-server-sdk
86+
command: ./.ldrelease/build-c-server.sh
87+
88+
- run:
89+
name: Build lua-server-sdk
90+
command: |
91+
luarocks make launchdarkly-server-sdk-1.0-0.rockspec
92+
luarocks make launchdarkly-server-sdk-redis-1.0-0.rockspec
93+
1894
- run:
19-
name: Build Doc
20-
command: ./.ldrelease/linux-build-docs.sh
95+
name: Run tests
96+
command: |
97+
lua5.2 test.lua

.ldrelease/build-c-server.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
git clone https://github.com/launchdarkly/c-server-sdk.git
6+
cd c-server-sdk
7+
mkdir build
8+
cd build
9+
cmake -D BUILD_SHARED_LIBS=ON -D BUILD_TESTING=OFF -D REDIS_STORE=ON ..
10+
make
11+
make install

.ldrelease/linux-build-docs.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ set -e
66

77
PROJECT_DIR=$(pwd)
88

9-
ldoc launchdarkly-server-sdk.lua
9+
mkdir tmp
10+
cp launchdarkly-server-sdk.c tmp/
11+
cp launchdarkly-server-sdk-redis.c tmp/
12+
13+
ldoc tmp
1014

1115
mkdir -p $PROJECT_DIR/artifacts
1216
cd $PROJECT_DIR/doc

.ldrelease/linux-prepare.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22

33
set -e
44

5-
apt-get update -y && apt-get install -y lua-ldoc zip ca-certificates
5+
apt-get update -y && apt-get install -y luajit lua-ldoc zip ca-certificates \
6+
curl zip lua-cjson libpcre3 libcurl4-openssl-dev cmake libhiredis-dev git \
7+
build-essential libpcre3-dev

.ldrelease/update-version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
set -e
44

5-
sed -i "s/local SDKVersion =.*/local SDKVersion = \"${LD_RELEASE_VERSION}\"/" 'launchdarkly-server-sdk.lua'
5+
sed -i "s/#define SDKVersion .*/#define SDKVersion \"${LD_RELEASE_VERSION}\"/" 'launchdarkly-server-sdk.c'

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ LaunchDarkly overview
1313
Supported Lua versions
1414
-----------
1515

16-
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.
16+
This version of the LaunchDarkly SDK is compatible with the Lua 5.1-5.3 interpreter, and LuaJIT.
17+
18+
Supported C server-side SDK versions
19+
-----------
20+
21+
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`.
1722

1823
Getting started
1924
-----------

attribution/luaunit.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
This software is distributed under the BSD License.
2+
3+
Copyright (c) 2005-2018, Philippe Fremy <phil at freehackers dot org>
4+
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
8+
9+
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
10+
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.
11+
12+
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.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package = "launchdarkly-server-sdk"
2+
3+
version = "1.0-0"
4+
5+
source = {
6+
url = "." -- not online yet!
7+
}
8+
9+
dependencies = {
10+
"lua >= 5.1, <= 5.4",
11+
}
12+
13+
external_dependencies = {
14+
LD = {
15+
header = "launchdarkly/api.h"
16+
}
17+
}
18+
19+
build = {
20+
type = "builtin",
21+
modules = {
22+
["launchdarkly_server_sdk"] = {
23+
sources = { "launchdarkly-server-sdk.c" },
24+
incdirs = {"$(LD_INCDIR)"},
25+
libdirs = {"$(LD_LIBDIR)"},
26+
libraries = {"ldserverapi"}
27+
}
28+
}
29+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package = "launchdarkly-server-sdk-redis"
2+
3+
version = "1.0-0"
4+
5+
source = {
6+
url = "." -- not online yet!
7+
}
8+
9+
dependencies = {
10+
"lua >= 5.1, <= 5.4",
11+
}
12+
13+
external_dependencies = {
14+
LDREDIS = {
15+
header = "launchdarkly/store/redis.h"
16+
}
17+
}
18+
19+
build = {
20+
type = "builtin",
21+
modules = {
22+
["launchdarkly_server_sdk_redis"] = {
23+
sources = { "launchdarkly-server-sdk-redis.c" },
24+
incdirs = {"$(LDREDIS_INCDIR)"},
25+
libdirs = {"$(LDREDIS_LIBDIR)"},
26+
libraries = {"ldserverapi-redis"}
27+
}
28+
}
29+
}

launchdarkly-server-sdk-redis.c

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/***
2+
Server-side SDK for LaunchDarkly Redis store.
3+
@module launchdarkly-server-sdk-redis
4+
*/
5+
6+
#include <lua.h>
7+
#include <lauxlib.h>
8+
#include <stdlib.h>
9+
#include <stdbool.h>
10+
#include <string.h>
11+
12+
#include <launchdarkly/api.h>
13+
#include <launchdarkly/store/redis.h>
14+
15+
/***
16+
Initialize a store backend
17+
@function makeStore
18+
@tparam table fields list of configuration options
19+
@tparam[opt] string fields.host Hostname for Redis.
20+
@tparam[opt] int fields.port Port for Redis.
21+
@tparam[opt] string fields.prefix Redis key prefix for SDK values.
22+
@tparam[opt] int fields.poolSize Number of Redis connections to maintain.
23+
@return A fresh Redis store backend.
24+
*/
25+
static int
26+
LuaLDRedisMakeStore(lua_State *const l)
27+
{
28+
struct LDRedisConfig *config;
29+
struct LDStoreInterface *storeInterface;
30+
31+
if (lua_gettop(l) != 1) {
32+
return luaL_error(l, "expecting exactly 1 argument");
33+
}
34+
35+
luaL_checktype(l, 1, LUA_TTABLE);
36+
37+
config = LDRedisConfigNew();
38+
39+
lua_getfield(l, 1, "host");
40+
41+
if (lua_isstring(l, -1)) {
42+
LDRedisConfigSetHost(config, luaL_checkstring(l, -1));
43+
}
44+
45+
lua_getfield(l, 1, "prefix");
46+
47+
if (lua_isstring(l, -1)) {
48+
LDRedisConfigSetPrefix(config, luaL_checkstring(l, -1));
49+
}
50+
51+
lua_getfield(l, 1, "port");
52+
53+
if (lua_isnumber(l, -1)) {
54+
LDRedisConfigSetPort(config, luaL_checkinteger(l, -1));
55+
}
56+
57+
lua_getfield(l, 1, "poolSize");
58+
59+
if (lua_isnumber(l, -1)) {
60+
LDRedisConfigSetPoolSize(config, luaL_checkinteger(l, -1));
61+
}
62+
63+
storeInterface = LDStoreInterfaceRedisNew(config);
64+
65+
struct LDStoreInterface **i =
66+
(struct LDStoreInterface **)lua_newuserdata(l, sizeof(storeInterface));
67+
68+
*i = storeInterface;
69+
70+
luaL_getmetatable(l, "LaunchDarklyStoreInterface");
71+
lua_setmetatable(l, -2);
72+
73+
return 1;
74+
}
75+
76+
static const struct luaL_Reg launchdarkly_functions[] = {
77+
{ "makeStore", LuaLDRedisMakeStore },
78+
{ NULL, NULL }
79+
};
80+
81+
#if !defined LUA_VERSION_NUM || LUA_VERSION_NUM==501
82+
/*
83+
** Adapted from Lua 5.2.0
84+
*/
85+
static void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
86+
luaL_checkstack(L, nup+1, "too many upvalues");
87+
for (; l->name != NULL; l++) { /* fill the table with given functions */
88+
int i;
89+
lua_pushstring(L, l->name);
90+
for (i = 0; i < nup; i++) /* copy upvalues to the top */
91+
lua_pushvalue(L, -(nup+1));
92+
lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */
93+
lua_settable(L, -(nup + 3));
94+
}
95+
lua_pop(L, nup); /* remove upvalues */
96+
}
97+
#endif
98+
99+
int
100+
luaopen_launchdarkly_server_sdk_redis(lua_State *const l)
101+
{
102+
#if LUA_VERSION_NUM == 503 || LUA_VERSION_NUM == 502
103+
luaL_newlib(l, launchdarkly_functions);
104+
#else
105+
luaL_register(l, "launchdarkly-server-sdk-redis",
106+
launchdarkly_functions);
107+
#endif
108+
109+
return 1;
110+
}

0 commit comments

Comments
 (0)