Skip to content

Instantly share code, notes, and snippets.

@badboy
Last active September 5, 2018 02:24
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save badboy/7032fe739742caf22eaf to your computer and use it in GitHub Desktop.
Save badboy/7032fe739742caf22eaf to your computer and use it in GitHub Desktop.
diff --git i/deps/Makefile w/deps/Makefile
index 5a95545..9ec62be 100644
--- i/deps/Makefile
+++ w/deps/Makefile
@@ -58,8 +58,8 @@ ifeq ($(uname_S),SunOS)
LUA_CFLAGS= -D__C99FEATURES__=1
endif
-LUA_CFLAGS+= -O2 -Wall -DLUA_ANSI $(CFLAGS)
-LUA_LDFLAGS+= $(LDFLAGS)
+LUA_CFLAGS+= -O2 -Wall -DLUA_ANSI -DLUA_USE_DLOPEN $(CFLAGS)
+LUA_LDFLAGS+= -ldl $(LDFLAGS)
lua: .make-prerequisites
@printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR)
diff --git i/src/scripting.c w/src/scripting.c
index ef00eed..c7f3735 100644
--- i/src/scripting.c
+++ w/src/scripting.c
@@ -549,10 +549,8 @@ void luaLoadLibraries(lua_State *lua) {
luaLoadLib(lua, "struct", luaopen_struct);
luaLoadLib(lua, "cmsgpack", luaopen_cmsgpack);
-#if 0 /* Stuff that we don't load currently, for sandboxing concerns. */
luaLoadLib(lua, LUA_LOADLIBNAME, luaopen_package);
luaLoadLib(lua, LUA_OSLIBNAME, luaopen_os);
-#endif
}
/* Remove a functions that we don't want to expose to the Redis scripting

First patch your redis to enable the internal package module with the included patch:

patch -p1 < enable-lua-package.patch

Compile it as usual:

make distclean # In case it was built before
make

Grab the copy of LGMP from here: http://members.chello.nl/~w.couwenberg/ (make sure you pick the 5.1 version), direct link: http://members.chello.nl/~w.couwenberg/lgmp.zip

Unpack it to a location, e.g. ~/code/lgmp/ and compile it:

gcc -O2 -Wall -lgmp -o c-gmp.so lgmp.c -shared -fPIC -L ~/code/redis/deps/lua/src/ -I ~/code/redis/deps/lua/src

Adjust the paths for -L and -I to point to the Lua bundled with Redis.

When this is done, start Redis from the directory with the gmp.lua and c-gmp.so:

~/code/redis/src/redis-server &

Now fire up redis-cli and use gmp:

~/code/redis/src/redis-cli
127.0.0.1:6379> eval "local gmp=require'gmp'; return gmp.version" 0
"6.0.0"
127.0.0.1:6379> eval "local gmp=require'gmp'; local x = gmp.z(123); local y = gmp.z(456); return x:add(y):__tostring()"  0
"579"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment