diff --git a/src/script_lua.c b/src/script_lua.c index 22eb58102..29edf344b 100644 --- a/src/script_lua.c +++ b/src/script_lua.c @@ -628,7 +628,7 @@ static void luaReplyToRedisReply(client *c, client* script_client, lua_State *lu /* Handle error reply. */ /* we took care of the stack size on function start */ lua_pushstring(lua,"err"); - lua_gettable(lua,-2); + lua_rawget(lua,-2); t = lua_type(lua,-1); if (t == LUA_TSTRING) { lua_pop(lua, 1); /* pop the error message, we will use luaExtractErrorInformation to get error information */ @@ -646,7 +646,7 @@ static void luaReplyToRedisReply(client *c, client* script_client, lua_State *lu /* Handle status reply. */ lua_pushstring(lua,"ok"); - lua_gettable(lua,-2); + lua_rawget(lua,-2); t = lua_type(lua,-1); if (t == LUA_TSTRING) { sds ok = sdsnew(lua_tostring(lua,-1)); @@ -660,7 +660,7 @@ static void luaReplyToRedisReply(client *c, client* script_client, lua_State *lu /* Handle double reply. */ lua_pushstring(lua,"double"); - lua_gettable(lua,-2); + lua_rawget(lua,-2); t = lua_type(lua,-1); if (t == LUA_TNUMBER) { addReplyDouble(c,lua_tonumber(lua,-1)); @@ -671,7 +671,7 @@ static void luaReplyToRedisReply(client *c, client* script_client, lua_State *lu /* Handle big number reply. */ lua_pushstring(lua,"big_number"); - lua_gettable(lua,-2); + lua_rawget(lua,-2); t = lua_type(lua,-1); if (t == LUA_TSTRING) { sds big_num = sdsnewlen(lua_tostring(lua,-1), lua_strlen(lua,-1)); @@ -685,16 +685,16 @@ static void luaReplyToRedisReply(client *c, client* script_client, lua_State *lu /* Handle verbatim reply. */ lua_pushstring(lua,"verbatim_string"); - lua_gettable(lua,-2); + lua_rawget(lua,-2); t = lua_type(lua,-1); if (t == LUA_TTABLE) { lua_pushstring(lua,"format"); - lua_gettable(lua,-2); + lua_rawget(lua,-2); t = lua_type(lua,-1); if (t == LUA_TSTRING){ char* format = (char*)lua_tostring(lua,-1); lua_pushstring(lua,"string"); - lua_gettable(lua,-3); + lua_rawget(lua,-3); t = lua_type(lua,-1); if (t == LUA_TSTRING){ size_t len; @@ -711,7 +711,7 @@ static void luaReplyToRedisReply(client *c, client* script_client, lua_State *lu /* Handle map reply. */ lua_pushstring(lua,"map"); - lua_gettable(lua,-2); + lua_rawget(lua,-2); t = lua_type(lua,-1); if (t == LUA_TTABLE) { int maplen = 0; @@ -734,7 +734,7 @@ static void luaReplyToRedisReply(client *c, client* script_client, lua_State *lu /* Handle set reply. */ lua_pushstring(lua,"set"); - lua_gettable(lua,-2); + lua_rawget(lua,-2); t = lua_type(lua,-1); if (t == LUA_TTABLE) { int setlen = 0; @@ -761,7 +761,7 @@ static void luaReplyToRedisReply(client *c, client* script_client, lua_State *lu while(1) { /* we took care of the stack size on function start */ lua_pushnumber(lua,j++); - lua_gettable(lua,-2); + lua_rawget(lua,-2); t = lua_type(lua,-1); if (t == LUA_TNIL) { lua_pop(lua,1); diff --git a/tests/unit/scripting.tcl b/tests/unit/scripting.tcl index f1c05a4d4..cca24c1bd 100644 --- a/tests/unit/scripting.tcl +++ b/tests/unit/scripting.tcl @@ -59,6 +59,20 @@ start_server {tags {"scripting"}} { run_script {return 'hello'} 0 } {hello} + test {EVAL - Return _G} { + run_script {return _G} 0 + } {} + + test {EVAL - Return table with a metatable that raise error} { + run_script {local a = {}; setmetatable(a,{__index=function() foo() end}) return a} 0 + } {} + + test {EVAL - Return table with a metatable that call redis} { + run_script {local a = {}; setmetatable(a,{__index=function() redis.call('set', 'x', '1') end}) return a} 0 + # make sure x was not set + r get x + } {} + test {EVAL - Lua integer -> Redis protocol type conversion} { run_script {return 100.5} 0 } {100}