Lines Matching refs:lua
41 char *redisProtocolToLuaType_Int(lua_State *lua, char *reply);
42 char *redisProtocolToLuaType_Bulk(lua_State *lua, char *reply);
43 char *redisProtocolToLuaType_Status(lua_State *lua, char *reply);
44 char *redisProtocolToLuaType_Error(lua_State *lua, char *reply);
45 char *redisProtocolToLuaType_MultiBulk(lua_State *lua, char *reply);
52 void luaLdbLineHook(lua_State *lua, lua_Debug *ar);
55 sds ldbCatStackValue(sds s, lua_State *lua, int idx);
127 char *redisProtocolToLuaType(lua_State *lua, char* reply) { in redisProtocolToLuaType() argument
131 case ':': p = redisProtocolToLuaType_Int(lua,reply); break; in redisProtocolToLuaType()
132 case '$': p = redisProtocolToLuaType_Bulk(lua,reply); break; in redisProtocolToLuaType()
133 case '+': p = redisProtocolToLuaType_Status(lua,reply); break; in redisProtocolToLuaType()
134 case '-': p = redisProtocolToLuaType_Error(lua,reply); break; in redisProtocolToLuaType()
135 case '*': p = redisProtocolToLuaType_MultiBulk(lua,reply); break; in redisProtocolToLuaType()
140 char *redisProtocolToLuaType_Int(lua_State *lua, char *reply) { in redisProtocolToLuaType_Int() argument
145 lua_pushnumber(lua,(lua_Number)value); in redisProtocolToLuaType_Int()
149 char *redisProtocolToLuaType_Bulk(lua_State *lua, char *reply) { in redisProtocolToLuaType_Bulk() argument
155 lua_pushboolean(lua,0); in redisProtocolToLuaType_Bulk()
158 lua_pushlstring(lua,p+2,bulklen); in redisProtocolToLuaType_Bulk()
163 char *redisProtocolToLuaType_Status(lua_State *lua, char *reply) { in redisProtocolToLuaType_Status() argument
166 lua_newtable(lua); in redisProtocolToLuaType_Status()
167 lua_pushstring(lua,"ok"); in redisProtocolToLuaType_Status()
168 lua_pushlstring(lua,reply+1,p-reply-1); in redisProtocolToLuaType_Status()
169 lua_settable(lua,-3); in redisProtocolToLuaType_Status()
173 char *redisProtocolToLuaType_Error(lua_State *lua, char *reply) { in redisProtocolToLuaType_Error() argument
176 lua_newtable(lua); in redisProtocolToLuaType_Error()
177 lua_pushstring(lua,"err"); in redisProtocolToLuaType_Error()
178 lua_pushlstring(lua,reply+1,p-reply-1); in redisProtocolToLuaType_Error()
179 lua_settable(lua,-3); in redisProtocolToLuaType_Error()
183 char *redisProtocolToLuaType_MultiBulk(lua_State *lua, char *reply) { in redisProtocolToLuaType_MultiBulk() argument
191 lua_pushboolean(lua,0); in redisProtocolToLuaType_MultiBulk()
194 lua_newtable(lua); in redisProtocolToLuaType_MultiBulk()
196 lua_pushnumber(lua,j+1); in redisProtocolToLuaType_MultiBulk()
197 p = redisProtocolToLuaType(lua,p); in redisProtocolToLuaType_MultiBulk()
198 lua_settable(lua,-3); in redisProtocolToLuaType_MultiBulk()
208 void luaPushError(lua_State *lua, char *error) { in luaPushError() argument
217 lua_newtable(lua); in luaPushError()
218 lua_pushstring(lua,"err"); in luaPushError()
221 if(lua_getstack(lua, 1, &dbg) && lua_getinfo(lua, "nSl", &dbg)) { in luaPushError()
224 lua_pushstring(lua, msg); in luaPushError()
227 lua_pushstring(lua, error); in luaPushError()
229 lua_settable(lua,-3); in luaPushError()
236 int luaRaiseError(lua_State *lua) { in luaRaiseError() argument
237 lua_pushstring(lua,"err"); in luaRaiseError()
238 lua_gettable(lua,-2); in luaRaiseError()
239 return lua_error(lua); in luaRaiseError()
248 void luaSortArray(lua_State *lua) { in luaSortArray() argument
250 lua_getglobal(lua,"table"); in luaSortArray()
251 lua_pushstring(lua,"sort"); in luaSortArray()
252 lua_gettable(lua,-2); /* Stack: array, table, table.sort */ in luaSortArray()
253 lua_pushvalue(lua,-3); /* Stack: array, table, table.sort, array */ in luaSortArray()
254 if (lua_pcall(lua,1,0,0)) { in luaSortArray()
261 lua_pop(lua,1); /* Stack: array, table */ in luaSortArray()
262 lua_pushstring(lua,"sort"); /* Stack: array, table, sort */ in luaSortArray()
263 lua_gettable(lua,-2); /* Stack: array, table, table.sort */ in luaSortArray()
264 lua_pushvalue(lua,-3); /* Stack: array, table, table.sort, array */ in luaSortArray()
265 lua_getglobal(lua,"__redis__compare_helper"); in luaSortArray()
267 lua_call(lua,2,0); in luaSortArray()
270 lua_pop(lua,1); /* Stack: array (sorted) */ in luaSortArray()
277 void luaReplyToRedisReply(client *c, lua_State *lua) { in luaReplyToRedisReply() argument
278 int t = lua_type(lua,-1); in luaReplyToRedisReply()
282 addReplyBulkCBuffer(c,(char*)lua_tostring(lua,-1),lua_strlen(lua,-1)); in luaReplyToRedisReply()
285 addReply(c,lua_toboolean(lua,-1) ? shared.cone : shared.nullbulk); in luaReplyToRedisReply()
288 addReplyLongLong(c,(long long)lua_tonumber(lua,-1)); in luaReplyToRedisReply()
295 lua_pushstring(lua,"err"); in luaReplyToRedisReply()
296 lua_gettable(lua,-2); in luaReplyToRedisReply()
297 t = lua_type(lua,-1); in luaReplyToRedisReply()
299 sds err = sdsnew(lua_tostring(lua,-1)); in luaReplyToRedisReply()
303 lua_pop(lua,2); in luaReplyToRedisReply()
307 lua_pop(lua,1); in luaReplyToRedisReply()
308 lua_pushstring(lua,"ok"); in luaReplyToRedisReply()
309 lua_gettable(lua,-2); in luaReplyToRedisReply()
310 t = lua_type(lua,-1); in luaReplyToRedisReply()
312 sds ok = sdsnew(lua_tostring(lua,-1)); in luaReplyToRedisReply()
316 lua_pop(lua,1); in luaReplyToRedisReply()
321 lua_pop(lua,1); /* Discard the 'ok' field value we popped */ in luaReplyToRedisReply()
323 lua_pushnumber(lua,j++); in luaReplyToRedisReply()
324 lua_gettable(lua,-2); in luaReplyToRedisReply()
325 t = lua_type(lua,-1); in luaReplyToRedisReply()
327 lua_pop(lua,1); in luaReplyToRedisReply()
330 luaReplyToRedisReply(c, lua); in luaReplyToRedisReply()
339 lua_pop(lua,1); in luaReplyToRedisReply()
348 int luaRedisGenericCommand(lua_State *lua, int raise_error) { in luaRedisGenericCommand() argument
349 int j, argc = lua_gettop(lua); in luaRedisGenericCommand()
377 luaPushError(lua,recursion_warning); in luaRedisGenericCommand()
384 luaPushError(lua, in luaRedisGenericCommand()
387 return raise_error ? luaRaiseError(lua) : 1; in luaRedisGenericCommand()
401 if (lua_type(lua,j+1) == LUA_TNUMBER) { in luaRedisGenericCommand()
404 lua_Number num = lua_tonumber(lua,j+1); in luaRedisGenericCommand()
409 obj_s = (char*)lua_tolstring(lua,j+1,&obj_len); in luaRedisGenericCommand()
436 luaPushError(lua, in luaRedisGenericCommand()
439 return raise_error ? luaRaiseError(lua) : 1; in luaRedisGenericCommand()
473 luaPushError(lua, in luaRedisGenericCommand()
476 luaPushError(lua,"Unknown Redis command called from Lua script"); in luaRedisGenericCommand()
483 luaPushError(lua, "This Redis command is not allowed from scripts"); in luaRedisGenericCommand()
493 luaPushError(lua, in luaRedisGenericCommand()
500 luaPushError(lua, shared.roslaveerr->ptr); in luaRedisGenericCommand()
504 luaPushError(lua, shared.bgsaveerr->ptr); in luaRedisGenericCommand()
509 luaPushError(lua, aof_write_err); in luaRedisGenericCommand()
527 luaPushError(lua, shared.oomerr->ptr); in luaRedisGenericCommand()
547 luaPushError(lua, in luaRedisGenericCommand()
599 redisProtocolToLuaType(lua,reply); in luaRedisGenericCommand()
610 luaSortArray(lua); in luaRedisGenericCommand()
650 return luaRaiseError(lua); in luaRedisGenericCommand()
657 int luaRedisCallCommand(lua_State *lua) { in luaRedisCallCommand() argument
658 return luaRedisGenericCommand(lua,1); in luaRedisCallCommand()
662 int luaRedisPCallCommand(lua_State *lua) { in luaRedisPCallCommand() argument
663 return luaRedisGenericCommand(lua,0); in luaRedisPCallCommand()
668 int luaRedisSha1hexCommand(lua_State *lua) { in luaRedisSha1hexCommand() argument
669 int argc = lua_gettop(lua); in luaRedisSha1hexCommand()
675 lua_pushstring(lua, "wrong number of arguments"); in luaRedisSha1hexCommand()
676 return lua_error(lua); in luaRedisSha1hexCommand()
679 s = (char*)lua_tolstring(lua,1,&len); in luaRedisSha1hexCommand()
681 lua_pushstring(lua,digest); in luaRedisSha1hexCommand()
692 int luaRedisReturnSingleFieldTable(lua_State *lua, char *field) { in luaRedisReturnSingleFieldTable() argument
693 if (lua_gettop(lua) != 1 || lua_type(lua,-1) != LUA_TSTRING) { in luaRedisReturnSingleFieldTable()
694 luaPushError(lua, "wrong number or type of arguments"); in luaRedisReturnSingleFieldTable()
698 lua_newtable(lua); in luaRedisReturnSingleFieldTable()
699 lua_pushstring(lua, field); in luaRedisReturnSingleFieldTable()
700 lua_pushvalue(lua, -3); in luaRedisReturnSingleFieldTable()
701 lua_settable(lua, -3); in luaRedisReturnSingleFieldTable()
706 int luaRedisErrorReplyCommand(lua_State *lua) { in luaRedisErrorReplyCommand() argument
707 return luaRedisReturnSingleFieldTable(lua,"err"); in luaRedisErrorReplyCommand()
711 int luaRedisStatusReplyCommand(lua_State *lua) { in luaRedisStatusReplyCommand() argument
712 return luaRedisReturnSingleFieldTable(lua,"ok"); in luaRedisStatusReplyCommand()
721 int luaRedisReplicateCommandsCommand(lua_State *lua) { in luaRedisReplicateCommandsCommand() argument
723 lua_pushboolean(lua,0); in luaRedisReplicateCommandsCommand()
730 lua_pushboolean(lua,1); in luaRedisReplicateCommandsCommand()
740 int luaRedisBreakpointCommand(lua_State *lua) { in luaRedisBreakpointCommand() argument
743 lua_pushboolean(lua,1); in luaRedisBreakpointCommand()
745 lua_pushboolean(lua,0); in luaRedisBreakpointCommand()
755 int luaRedisDebugCommand(lua_State *lua) { in luaRedisDebugCommand() argument
757 int argc = lua_gettop(lua); in luaRedisDebugCommand()
760 log = ldbCatStackValue(log,lua,-1 - argc); in luaRedisDebugCommand()
771 int luaRedisSetReplCommand(lua_State *lua) { in luaRedisSetReplCommand() argument
772 int argc = lua_gettop(lua); in luaRedisSetReplCommand()
776 …lua_pushstring(lua, "You can set the replication behavior only after turning on single commands re… in luaRedisSetReplCommand()
777 return lua_error(lua); in luaRedisSetReplCommand()
779 lua_pushstring(lua, "redis.set_repl() requires two arguments."); in luaRedisSetReplCommand()
780 return lua_error(lua); in luaRedisSetReplCommand()
783 flags = lua_tonumber(lua,-1); in luaRedisSetReplCommand()
785 …lua_pushstring(lua, "Invalid replication flags. Use REPL_AOF, REPL_REPLICA, REPL_ALL or REPL_NONE.… in luaRedisSetReplCommand()
786 return lua_error(lua); in luaRedisSetReplCommand()
793 int luaLogCommand(lua_State *lua) { in luaLogCommand() argument
794 int j, argc = lua_gettop(lua); in luaLogCommand()
799 lua_pushstring(lua, "redis.log() requires two arguments or more."); in luaLogCommand()
800 return lua_error(lua); in luaLogCommand()
801 } else if (!lua_isnumber(lua,-argc)) { in luaLogCommand()
802 lua_pushstring(lua, "First argument must be a number (log level)."); in luaLogCommand()
803 return lua_error(lua); in luaLogCommand()
805 level = lua_tonumber(lua,-argc); in luaLogCommand()
807 lua_pushstring(lua, "Invalid debug level."); in luaLogCommand()
808 return lua_error(lua); in luaLogCommand()
817 s = (char*)lua_tolstring(lua,(-argc)+j,&len); in luaLogCommand()
832 void luaLoadLib(lua_State *lua, const char *libname, lua_CFunction luafunc) { in luaLoadLib() argument
833 lua_pushcfunction(lua, luafunc); in luaLoadLib()
834 lua_pushstring(lua, libname); in luaLoadLib()
835 lua_call(lua, 1, 0); in luaLoadLib()
843 void luaLoadLibraries(lua_State *lua) { in luaLoadLibraries() argument
844 luaLoadLib(lua, "", luaopen_base); in luaLoadLibraries()
845 luaLoadLib(lua, LUA_TABLIBNAME, luaopen_table); in luaLoadLibraries()
846 luaLoadLib(lua, LUA_STRLIBNAME, luaopen_string); in luaLoadLibraries()
847 luaLoadLib(lua, LUA_MATHLIBNAME, luaopen_math); in luaLoadLibraries()
848 luaLoadLib(lua, LUA_DBLIBNAME, luaopen_debug); in luaLoadLibraries()
849 luaLoadLib(lua, "cjson", luaopen_cjson); in luaLoadLibraries()
850 luaLoadLib(lua, "struct", luaopen_struct); in luaLoadLibraries()
851 luaLoadLib(lua, "cmsgpack", luaopen_cmsgpack); in luaLoadLibraries()
852 luaLoadLib(lua, "bit", luaopen_bit); in luaLoadLibraries()
855 luaLoadLib(lua, LUA_LOADLIBNAME, luaopen_package); in luaLoadLibraries()
856 luaLoadLib(lua, LUA_OSLIBNAME, luaopen_os); in luaLoadLibraries()
862 void luaRemoveUnsupportedFunctions(lua_State *lua) { in luaRemoveUnsupportedFunctions() argument
863 lua_pushnil(lua); in luaRemoveUnsupportedFunctions()
864 lua_setglobal(lua,"loadfile"); in luaRemoveUnsupportedFunctions()
865 lua_pushnil(lua); in luaRemoveUnsupportedFunctions()
866 lua_setglobal(lua,"dofile"); in luaRemoveUnsupportedFunctions()
874 void scriptingEnableGlobalsProtection(lua_State *lua) { in scriptingEnableGlobalsProtection() argument
903 luaL_loadbuffer(lua,code,sdslen(code),"@enable_strict_lua"); in scriptingEnableGlobalsProtection()
904 lua_pcall(lua,0,0,0); in scriptingEnableGlobalsProtection()
919 lua_State *lua = lua_open(); in scriptingInit() local
928 luaLoadLibraries(lua); in scriptingInit()
929 luaRemoveUnsupportedFunctions(lua); in scriptingInit()
938 lua_newtable(lua); in scriptingInit()
941 lua_pushstring(lua,"call"); in scriptingInit()
942 lua_pushcfunction(lua,luaRedisCallCommand); in scriptingInit()
943 lua_settable(lua,-3); in scriptingInit()
946 lua_pushstring(lua,"pcall"); in scriptingInit()
947 lua_pushcfunction(lua,luaRedisPCallCommand); in scriptingInit()
948 lua_settable(lua,-3); in scriptingInit()
951 lua_pushstring(lua,"log"); in scriptingInit()
952 lua_pushcfunction(lua,luaLogCommand); in scriptingInit()
953 lua_settable(lua,-3); in scriptingInit()
955 lua_pushstring(lua,"LOG_DEBUG"); in scriptingInit()
956 lua_pushnumber(lua,LL_DEBUG); in scriptingInit()
957 lua_settable(lua,-3); in scriptingInit()
959 lua_pushstring(lua,"LOG_VERBOSE"); in scriptingInit()
960 lua_pushnumber(lua,LL_VERBOSE); in scriptingInit()
961 lua_settable(lua,-3); in scriptingInit()
963 lua_pushstring(lua,"LOG_NOTICE"); in scriptingInit()
964 lua_pushnumber(lua,LL_NOTICE); in scriptingInit()
965 lua_settable(lua,-3); in scriptingInit()
967 lua_pushstring(lua,"LOG_WARNING"); in scriptingInit()
968 lua_pushnumber(lua,LL_WARNING); in scriptingInit()
969 lua_settable(lua,-3); in scriptingInit()
972 lua_pushstring(lua, "sha1hex"); in scriptingInit()
973 lua_pushcfunction(lua, luaRedisSha1hexCommand); in scriptingInit()
974 lua_settable(lua, -3); in scriptingInit()
977 lua_pushstring(lua, "error_reply"); in scriptingInit()
978 lua_pushcfunction(lua, luaRedisErrorReplyCommand); in scriptingInit()
979 lua_settable(lua, -3); in scriptingInit()
980 lua_pushstring(lua, "status_reply"); in scriptingInit()
981 lua_pushcfunction(lua, luaRedisStatusReplyCommand); in scriptingInit()
982 lua_settable(lua, -3); in scriptingInit()
985 lua_pushstring(lua, "replicate_commands"); in scriptingInit()
986 lua_pushcfunction(lua, luaRedisReplicateCommandsCommand); in scriptingInit()
987 lua_settable(lua, -3); in scriptingInit()
990 lua_pushstring(lua,"set_repl"); in scriptingInit()
991 lua_pushcfunction(lua,luaRedisSetReplCommand); in scriptingInit()
992 lua_settable(lua,-3); in scriptingInit()
994 lua_pushstring(lua,"REPL_NONE"); in scriptingInit()
995 lua_pushnumber(lua,PROPAGATE_NONE); in scriptingInit()
996 lua_settable(lua,-3); in scriptingInit()
998 lua_pushstring(lua,"REPL_AOF"); in scriptingInit()
999 lua_pushnumber(lua,PROPAGATE_AOF); in scriptingInit()
1000 lua_settable(lua,-3); in scriptingInit()
1002 lua_pushstring(lua,"REPL_SLAVE"); in scriptingInit()
1003 lua_pushnumber(lua,PROPAGATE_REPL); in scriptingInit()
1004 lua_settable(lua,-3); in scriptingInit()
1006 lua_pushstring(lua,"REPL_REPLICA"); in scriptingInit()
1007 lua_pushnumber(lua,PROPAGATE_REPL); in scriptingInit()
1008 lua_settable(lua,-3); in scriptingInit()
1010 lua_pushstring(lua,"REPL_ALL"); in scriptingInit()
1011 lua_pushnumber(lua,PROPAGATE_AOF|PROPAGATE_REPL); in scriptingInit()
1012 lua_settable(lua,-3); in scriptingInit()
1015 lua_pushstring(lua,"breakpoint"); in scriptingInit()
1016 lua_pushcfunction(lua,luaRedisBreakpointCommand); in scriptingInit()
1017 lua_settable(lua,-3); in scriptingInit()
1020 lua_pushstring(lua,"debug"); in scriptingInit()
1021 lua_pushcfunction(lua,luaRedisDebugCommand); in scriptingInit()
1022 lua_settable(lua,-3); in scriptingInit()
1025 lua_setglobal(lua,"redis"); in scriptingInit()
1028 lua_getglobal(lua,"math"); in scriptingInit()
1030 lua_pushstring(lua,"random"); in scriptingInit()
1031 lua_pushcfunction(lua,redis_math_random); in scriptingInit()
1032 lua_settable(lua,-3); in scriptingInit()
1034 lua_pushstring(lua,"randomseed"); in scriptingInit()
1035 lua_pushcfunction(lua,redis_math_randomseed); in scriptingInit()
1036 lua_settable(lua,-3); in scriptingInit()
1038 lua_setglobal(lua,"math"); in scriptingInit()
1048 luaL_loadbuffer(lua,compare_func,strlen(compare_func),"@cmp_func_def"); in scriptingInit()
1049 lua_pcall(lua,0,0,0); in scriptingInit()
1069 luaL_loadbuffer(lua,errh_func,strlen(errh_func),"@err_handler_def"); in scriptingInit()
1070 lua_pcall(lua,0,0,0); in scriptingInit()
1085 scriptingEnableGlobalsProtection(lua); in scriptingInit()
1087 server.lua = lua; in scriptingInit()
1095 lua_close(server.lua); in scriptingRelease()
1105 void luaSetGlobalArray(lua_State *lua, char *var, robj **elev, int elec) { in luaSetGlobalArray() argument
1108 lua_newtable(lua); in luaSetGlobalArray()
1110 lua_pushlstring(lua,(char*)elev[j]->ptr,sdslen(elev[j]->ptr)); in luaSetGlobalArray()
1111 lua_rawseti(lua,-2,j+1); in luaSetGlobalArray()
1113 lua_setglobal(lua,var); in luaSetGlobalArray()
1180 sds luaCreateFunction(client *c, lua_State *lua, robj *body) { in luaCreateFunction() argument
1201 if (luaL_loadbuffer(lua,funcdef,sdslen(funcdef),"@user_script")) { in luaCreateFunction()
1205 lua_tostring(lua,-1)); in luaCreateFunction()
1207 lua_pop(lua,1); in luaCreateFunction()
1214 if (lua_pcall(lua,0,0,0)) { in luaCreateFunction()
1217 lua_tostring(lua,-1)); in luaCreateFunction()
1219 lua_pop(lua,1); in luaCreateFunction()
1235 void luaMaskCountHook(lua_State *lua, lua_Debug *ar) { in luaMaskCountHook() argument
1238 UNUSED(lua); in luaMaskCountHook()
1255 lua_pushstring(lua,"Script killed by user with SCRIPT KILL..."); in luaMaskCountHook()
1256 lua_error(lua); in luaMaskCountHook()
1261 lua_State *lua = server.lua; in evalGenericCommand() local
1318 lua_getglobal(lua, "__redis__err__handler"); in evalGenericCommand()
1321 lua_getglobal(lua, funcname); in evalGenericCommand()
1322 if (lua_isnil(lua,-1)) { in evalGenericCommand()
1323 lua_pop(lua,1); /* remove the nil from the stack */ in evalGenericCommand()
1328 lua_pop(lua,1); /* remove the error handler from the stack. */ in evalGenericCommand()
1332 if (luaCreateFunction(c,lua,c->argv[1]) == NULL) { in evalGenericCommand()
1333 lua_pop(lua,1); /* remove the error handler from the stack. */ in evalGenericCommand()
1339 lua_getglobal(lua, funcname); in evalGenericCommand()
1340 serverAssert(!lua_isnil(lua,-1)); in evalGenericCommand()
1345 luaSetGlobalArray(lua,"KEYS",c->argv+3,numkeys); in evalGenericCommand()
1346 luaSetGlobalArray(lua,"ARGV",c->argv+3+numkeys,c->argc-3-numkeys); in evalGenericCommand()
1362 lua_sethook(lua,luaMaskCountHook,LUA_MASKCOUNT,100000); in evalGenericCommand()
1365 lua_sethook(server.lua,luaLdbLineHook,LUA_MASKLINE|LUA_MASKCOUNT,100000); in evalGenericCommand()
1372 err = lua_pcall(lua,0,1,-2); in evalGenericCommand()
1375 if (delhook) lua_sethook(lua,NULL,0,0); /* Disable hook */ in evalGenericCommand()
1398 lua_gc(lua,LUA_GCSTEP,LUA_GC_CYCLE_PERIOD); in evalGenericCommand()
1405 funcname, lua_tostring(lua,-1)); in evalGenericCommand()
1406 lua_pop(lua,2); /* Consume the Lua reply and remove error handler. */ in evalGenericCommand()
1410 luaReplyToRedisReply(c,lua); /* Convert and consume the reply. */ in evalGenericCommand()
1411 lua_pop(lua,1); /* Remove the error handler. */ in evalGenericCommand()
1517 sds sha = luaCreateFunction(c,server.lua,c->argv[2]); in scriptCommand()
1921 sds ldbCatStackValueRec(sds s, lua_State *lua, int idx, int level) { in ldbCatStackValueRec() argument
1922 int t = lua_type(lua,idx); in ldbCatStackValueRec()
1931 char *strp = (char*)lua_tolstring(lua,idx,&strl); in ldbCatStackValueRec()
1936 s = sdscat(s,lua_toboolean(lua,idx) ? "true" : "false"); in ldbCatStackValueRec()
1939 s = sdscatprintf(s,"%g",(double)lua_tonumber(lua,idx)); in ldbCatStackValueRec()
1953 lua_pushnil(lua); /* The first key to start the iteration is nil. */ in ldbCatStackValueRec()
1954 while (lua_next(lua,idx-1)) { in ldbCatStackValueRec()
1957 (lua_type(lua,-2) != LUA_TNUMBER || in ldbCatStackValueRec()
1958 lua_tonumber(lua,-2) != expected_index)) is_array = 0; in ldbCatStackValueRec()
1961 repr1 = ldbCatStackValueRec(repr1,lua,-1,level); in ldbCatStackValueRec()
1965 repr2 = ldbCatStackValueRec(repr2,lua,-2,level); in ldbCatStackValueRec()
1967 repr2 = ldbCatStackValueRec(repr2,lua,-1,level); in ldbCatStackValueRec()
1969 lua_pop(lua,1); /* Stack: table, key. Ready for next iteration. */ in ldbCatStackValueRec()
1988 const void *p = lua_topointer(lua,idx); in ldbCatStackValueRec()
2006 sds ldbCatStackValue(sds s, lua_State *lua, int idx) { in ldbCatStackValue() argument
2007 return ldbCatStackValueRec(s,lua,idx,0); in ldbCatStackValue()
2013 void ldbLogStackValue(lua_State *lua, char *prefix) { in ldbLogStackValue() argument
2015 s = ldbCatStackValue(s,lua,-1); in ldbLogStackValue()
2103 void ldbPrint(lua_State *lua, char *varname) { in ldbPrint() argument
2107 while (lua_getstack(lua,l,&ar) != 0) { in ldbPrint()
2111 while((name = lua_getlocal(lua,&ar,i)) != NULL) { in ldbPrint()
2114 ldbLogStackValue(lua,"<value> "); in ldbPrint()
2115 lua_pop(lua,1); in ldbPrint()
2118 lua_pop(lua,1); /* Discard the var name on the stack. */ in ldbPrint()
2125 lua_getglobal(lua, varname); in ldbPrint()
2126 ldbLogStackValue(lua,"<value> "); in ldbPrint()
2127 lua_pop(lua,1); in ldbPrint()
2135 void ldbPrintAll(lua_State *lua) { in ldbPrintAll() argument
2139 if (lua_getstack(lua,0,&ar) != 0) { in ldbPrintAll()
2142 while((name = lua_getlocal(lua,&ar,i)) != NULL) { in ldbPrintAll()
2146 ldbLogStackValue(lua,prefix); in ldbPrintAll()
2150 lua_pop(lua,1); in ldbPrintAll()
2204 void ldbEval(lua_State *lua, sds *argv, int argc) { in ldbEval() argument
2210 if (luaL_loadbuffer(lua,expr,sdslen(expr),"@ldb_eval")) { in ldbEval()
2211 lua_pop(lua,1); in ldbEval()
2213 if (luaL_loadbuffer(lua,code,sdslen(code),"@ldb_eval")) { in ldbEval()
2214 ldbLog(sdscatfmt(sdsempty(),"<error> %s",lua_tostring(lua,-1))); in ldbEval()
2215 lua_pop(lua,1); in ldbEval()
2224 if (lua_pcall(lua,0,1,0)) { in ldbEval()
2225 ldbLog(sdscatfmt(sdsempty(),"<error> %s",lua_tostring(lua,-1))); in ldbEval()
2226 lua_pop(lua,1); in ldbEval()
2229 ldbLogStackValue(lua,"<retval> "); in ldbEval()
2230 lua_pop(lua,1); in ldbEval()
2237 void ldbRedis(lua_State *lua, sds *argv, int argc) { in ldbRedis() argument
2240 lua_getglobal(lua,"redis"); in ldbRedis()
2241 lua_pushstring(lua,"call"); in ldbRedis()
2242 lua_gettable(lua,-2); /* Stack: redis, redis.call */ in ldbRedis()
2244 lua_pushlstring(lua,argv[j],sdslen(argv[j])); in ldbRedis()
2247 lua_pcall(lua,argc-1,1,0); /* Stack: redis, result */ in ldbRedis()
2250 lua_pop(lua,2); /* Discard the result and clean the stack. */ in ldbRedis()
2255 void ldbTrace(lua_State *lua) { in ldbTrace() argument
2259 while(lua_getstack(lua,level,&ar)) { in ldbTrace()
2260 lua_getinfo(lua,"Snl",&ar); in ldbTrace()
2293 int ldbRepl(lua_State *lua) { in ldbRepl() argument
2357 ldbTrace(lua); in ldbRepl()
2366 ldbEval(lua,argv,argc); in ldbRepl()
2369 lua_pushstring(lua, "script aborted for user request"); in ldbRepl()
2370 lua_error(lua); in ldbRepl()
2373 ldbRedis(lua,argv,argc); in ldbRepl()
2377 ldbPrint(lua,argv[1]); in ldbRepl()
2379 ldbPrintAll(lua); in ldbRepl()
2410 void luaLdbLineHook(lua_State *lua, lua_Debug *ar) { in luaLdbLineHook() argument
2411 lua_getstack(lua,0,ar); in luaLdbLineHook()
2412 lua_getinfo(lua,"Sl",ar); in luaLdbLineHook()
2446 if (ldbRepl(lua) == C_ERR && timeout) { in luaLdbLineHook()
2450 lua_pushstring(lua, "timeout during Lua debugging with client closing connection"); in luaLdbLineHook()
2451 lua_error(lua); in luaLdbLineHook()