Skip to content

Instantly share code, notes, and snippets.

Last active September 5, 2018 02:24
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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: .make-prerequisites
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);
/* 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

Grab the copy of LGMP from here: (make sure you pick the 5.1 version), direct link:

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

gcc -O2 -Wall -lgmp -o 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

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

Now fire up redis-cli and use gmp:

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