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()
370 luaPushError(lua,recursion_warning); in luaRedisGenericCommand()
377 luaPushError(lua, in luaRedisGenericCommand()
380 return raise_error ? luaRaiseError(lua) : 1; in luaRedisGenericCommand()
394 if (lua_type(lua,j+1) == LUA_TNUMBER) { in luaRedisGenericCommand()
397 lua_Number num = lua_tonumber(lua,j+1); in luaRedisGenericCommand()
402 obj_s = (char*)lua_tolstring(lua,j+1,&obj_len); in luaRedisGenericCommand()
429 luaPushError(lua, in luaRedisGenericCommand()
432 return raise_error ? luaRaiseError(lua) : 1; in luaRedisGenericCommand()
460 luaPushError(lua, in luaRedisGenericCommand()
463 luaPushError(lua,"Unknown Redis command called from Lua script"); in luaRedisGenericCommand()
470 luaPushError(lua, "This Redis command is not allowed from scripts"); in luaRedisGenericCommand()
479 luaPushError(lua, in luaRedisGenericCommand()
486 luaPushError(lua, shared.roslaveerr->ptr); in luaRedisGenericCommand()
492 luaPushError(lua, shared.bgsaveerr->ptr); in luaRedisGenericCommand()
505 luaPushError(lua, shared.oomerr->ptr); in luaRedisGenericCommand()
525 luaPushError(lua, in luaRedisGenericCommand()
576 redisProtocolToLuaType(lua,reply); in luaRedisGenericCommand()
587 luaSortArray(lua); in luaRedisGenericCommand()
627 return luaRaiseError(lua); in luaRedisGenericCommand()
634 int luaRedisCallCommand(lua_State *lua) { in luaRedisCallCommand() argument
635 return luaRedisGenericCommand(lua,1); in luaRedisCallCommand()
639 int luaRedisPCallCommand(lua_State *lua) { in luaRedisPCallCommand() argument
640 return luaRedisGenericCommand(lua,0); in luaRedisPCallCommand()
645 int luaRedisSha1hexCommand(lua_State *lua) { in luaRedisSha1hexCommand() argument
646 int argc = lua_gettop(lua); in luaRedisSha1hexCommand()
652 lua_pushstring(lua, "wrong number of arguments"); in luaRedisSha1hexCommand()
653 return lua_error(lua); in luaRedisSha1hexCommand()
656 s = (char*)lua_tolstring(lua,1,&len); in luaRedisSha1hexCommand()
658 lua_pushstring(lua,digest); in luaRedisSha1hexCommand()
669 int luaRedisReturnSingleFieldTable(lua_State *lua, char *field) { in luaRedisReturnSingleFieldTable() argument
670 if (lua_gettop(lua) != 1 || lua_type(lua,-1) != LUA_TSTRING) { in luaRedisReturnSingleFieldTable()
671 luaPushError(lua, "wrong number or type of arguments"); in luaRedisReturnSingleFieldTable()
675 lua_newtable(lua); in luaRedisReturnSingleFieldTable()
676 lua_pushstring(lua, field); in luaRedisReturnSingleFieldTable()
677 lua_pushvalue(lua, -3); in luaRedisReturnSingleFieldTable()
678 lua_settable(lua, -3); in luaRedisReturnSingleFieldTable()
683 int luaRedisErrorReplyCommand(lua_State *lua) { in luaRedisErrorReplyCommand() argument
684 return luaRedisReturnSingleFieldTable(lua,"err"); in luaRedisErrorReplyCommand()
688 int luaRedisStatusReplyCommand(lua_State *lua) { in luaRedisStatusReplyCommand() argument
689 return luaRedisReturnSingleFieldTable(lua,"ok"); in luaRedisStatusReplyCommand()
698 int luaRedisReplicateCommandsCommand(lua_State *lua) { in luaRedisReplicateCommandsCommand() argument
700 lua_pushboolean(lua,0); in luaRedisReplicateCommandsCommand()
707 lua_pushboolean(lua,1); in luaRedisReplicateCommandsCommand()
717 int luaRedisBreakpointCommand(lua_State *lua) { in luaRedisBreakpointCommand() argument
720 lua_pushboolean(lua,1); in luaRedisBreakpointCommand()
722 lua_pushboolean(lua,0); in luaRedisBreakpointCommand()
732 int luaRedisDebugCommand(lua_State *lua) { in luaRedisDebugCommand() argument
734 int argc = lua_gettop(lua); in luaRedisDebugCommand()
737 log = ldbCatStackValue(log,lua,-1 - argc); in luaRedisDebugCommand()
748 int luaRedisSetReplCommand(lua_State *lua) { in luaRedisSetReplCommand() argument
749 int argc = lua_gettop(lua); in luaRedisSetReplCommand()
753 …lua_pushstring(lua, "You can set the replication behavior only after turning on single commands re… in luaRedisSetReplCommand()
754 return lua_error(lua); in luaRedisSetReplCommand()
756 lua_pushstring(lua, "redis.set_repl() requires two arguments."); in luaRedisSetReplCommand()
757 return lua_error(lua); in luaRedisSetReplCommand()
760 flags = lua_tonumber(lua,-1); in luaRedisSetReplCommand()
762 …lua_pushstring(lua, "Invalid replication flags. Use REPL_AOF, REPL_SLAVE, REPL_ALL or REPL_NONE."); in luaRedisSetReplCommand()
763 return lua_error(lua); in luaRedisSetReplCommand()
770 int luaLogCommand(lua_State *lua) { in luaLogCommand() argument
771 int j, argc = lua_gettop(lua); in luaLogCommand()
776 lua_pushstring(lua, "redis.log() requires two arguments or more."); in luaLogCommand()
777 return lua_error(lua); in luaLogCommand()
778 } else if (!lua_isnumber(lua,-argc)) { in luaLogCommand()
779 lua_pushstring(lua, "First argument must be a number (log level)."); in luaLogCommand()
780 return lua_error(lua); in luaLogCommand()
782 level = lua_tonumber(lua,-argc); in luaLogCommand()
784 lua_pushstring(lua, "Invalid debug level."); in luaLogCommand()
785 return lua_error(lua); in luaLogCommand()
794 s = (char*)lua_tolstring(lua,(-argc)+j,&len); in luaLogCommand()
809 void luaLoadLib(lua_State *lua, const char *libname, lua_CFunction luafunc) { in luaLoadLib() argument
810 lua_pushcfunction(lua, luafunc); in luaLoadLib()
811 lua_pushstring(lua, libname); in luaLoadLib()
812 lua_call(lua, 1, 0); in luaLoadLib()
820 void luaLoadLibraries(lua_State *lua) { in luaLoadLibraries() argument
821 luaLoadLib(lua, "", luaopen_base); in luaLoadLibraries()
822 luaLoadLib(lua, LUA_TABLIBNAME, luaopen_table); in luaLoadLibraries()
823 luaLoadLib(lua, LUA_STRLIBNAME, luaopen_string); in luaLoadLibraries()
824 luaLoadLib(lua, LUA_MATHLIBNAME, luaopen_math); in luaLoadLibraries()
825 luaLoadLib(lua, LUA_DBLIBNAME, luaopen_debug); in luaLoadLibraries()
826 luaLoadLib(lua, "cjson", luaopen_cjson); in luaLoadLibraries()
827 luaLoadLib(lua, "struct", luaopen_struct); in luaLoadLibraries()
828 luaLoadLib(lua, "cmsgpack", luaopen_cmsgpack); in luaLoadLibraries()
829 luaLoadLib(lua, "bit", luaopen_bit); in luaLoadLibraries()
832 luaLoadLib(lua, LUA_LOADLIBNAME, luaopen_package); in luaLoadLibraries()
833 luaLoadLib(lua, LUA_OSLIBNAME, luaopen_os); in luaLoadLibraries()
839 void luaRemoveUnsupportedFunctions(lua_State *lua) { in luaRemoveUnsupportedFunctions() argument
840 lua_pushnil(lua); in luaRemoveUnsupportedFunctions()
841 lua_setglobal(lua,"loadfile"); in luaRemoveUnsupportedFunctions()
842 lua_pushnil(lua); in luaRemoveUnsupportedFunctions()
843 lua_setglobal(lua,"dofile"); in luaRemoveUnsupportedFunctions()
851 void scriptingEnableGlobalsProtection(lua_State *lua) { in scriptingEnableGlobalsProtection() argument
880 luaL_loadbuffer(lua,code,sdslen(code),"@enable_strict_lua"); in scriptingEnableGlobalsProtection()
881 lua_pcall(lua,0,0,0); in scriptingEnableGlobalsProtection()
896 lua_State *lua = lua_open(); in scriptingInit() local
907 luaLoadLibraries(lua); in scriptingInit()
908 luaRemoveUnsupportedFunctions(lua); in scriptingInit()
916 lua_newtable(lua); in scriptingInit()
919 lua_pushstring(lua,"call"); in scriptingInit()
920 lua_pushcfunction(lua,luaRedisCallCommand); in scriptingInit()
921 lua_settable(lua,-3); in scriptingInit()
924 lua_pushstring(lua,"pcall"); in scriptingInit()
925 lua_pushcfunction(lua,luaRedisPCallCommand); in scriptingInit()
926 lua_settable(lua,-3); in scriptingInit()
929 lua_pushstring(lua,"log"); in scriptingInit()
930 lua_pushcfunction(lua,luaLogCommand); in scriptingInit()
931 lua_settable(lua,-3); in scriptingInit()
933 lua_pushstring(lua,"LOG_DEBUG"); in scriptingInit()
934 lua_pushnumber(lua,LL_DEBUG); in scriptingInit()
935 lua_settable(lua,-3); in scriptingInit()
937 lua_pushstring(lua,"LOG_VERBOSE"); in scriptingInit()
938 lua_pushnumber(lua,LL_VERBOSE); in scriptingInit()
939 lua_settable(lua,-3); in scriptingInit()
941 lua_pushstring(lua,"LOG_NOTICE"); in scriptingInit()
942 lua_pushnumber(lua,LL_NOTICE); in scriptingInit()
943 lua_settable(lua,-3); in scriptingInit()
945 lua_pushstring(lua,"LOG_WARNING"); in scriptingInit()
946 lua_pushnumber(lua,LL_WARNING); in scriptingInit()
947 lua_settable(lua,-3); in scriptingInit()
950 lua_pushstring(lua, "sha1hex"); in scriptingInit()
951 lua_pushcfunction(lua, luaRedisSha1hexCommand); in scriptingInit()
952 lua_settable(lua, -3); in scriptingInit()
955 lua_pushstring(lua, "error_reply"); in scriptingInit()
956 lua_pushcfunction(lua, luaRedisErrorReplyCommand); in scriptingInit()
957 lua_settable(lua, -3); in scriptingInit()
958 lua_pushstring(lua, "status_reply"); in scriptingInit()
959 lua_pushcfunction(lua, luaRedisStatusReplyCommand); in scriptingInit()
960 lua_settable(lua, -3); in scriptingInit()
963 lua_pushstring(lua, "replicate_commands"); in scriptingInit()
964 lua_pushcfunction(lua, luaRedisReplicateCommandsCommand); in scriptingInit()
965 lua_settable(lua, -3); in scriptingInit()
968 lua_pushstring(lua,"set_repl"); in scriptingInit()
969 lua_pushcfunction(lua,luaRedisSetReplCommand); in scriptingInit()
970 lua_settable(lua,-3); in scriptingInit()
972 lua_pushstring(lua,"REPL_NONE"); in scriptingInit()
973 lua_pushnumber(lua,PROPAGATE_NONE); in scriptingInit()
974 lua_settable(lua,-3); in scriptingInit()
976 lua_pushstring(lua,"REPL_AOF"); in scriptingInit()
977 lua_pushnumber(lua,PROPAGATE_AOF); in scriptingInit()
978 lua_settable(lua,-3); in scriptingInit()
980 lua_pushstring(lua,"REPL_SLAVE"); in scriptingInit()
981 lua_pushnumber(lua,PROPAGATE_REPL); in scriptingInit()
982 lua_settable(lua,-3); in scriptingInit()
984 lua_pushstring(lua,"REPL_ALL"); in scriptingInit()
985 lua_pushnumber(lua,PROPAGATE_AOF|PROPAGATE_REPL); in scriptingInit()
986 lua_settable(lua,-3); in scriptingInit()
989 lua_pushstring(lua,"breakpoint"); in scriptingInit()
990 lua_pushcfunction(lua,luaRedisBreakpointCommand); in scriptingInit()
991 lua_settable(lua,-3); in scriptingInit()
994 lua_pushstring(lua,"debug"); in scriptingInit()
995 lua_pushcfunction(lua,luaRedisDebugCommand); in scriptingInit()
996 lua_settable(lua,-3); in scriptingInit()
999 lua_setglobal(lua,"redis"); in scriptingInit()
1002 lua_getglobal(lua,"math"); in scriptingInit()
1004 lua_pushstring(lua,"random"); in scriptingInit()
1005 lua_pushcfunction(lua,redis_math_random); in scriptingInit()
1006 lua_settable(lua,-3); in scriptingInit()
1008 lua_pushstring(lua,"randomseed"); in scriptingInit()
1009 lua_pushcfunction(lua,redis_math_randomseed); in scriptingInit()
1010 lua_settable(lua,-3); in scriptingInit()
1012 lua_setglobal(lua,"math"); in scriptingInit()
1022 luaL_loadbuffer(lua,compare_func,strlen(compare_func),"@cmp_func_def"); in scriptingInit()
1023 lua_pcall(lua,0,0,0); in scriptingInit()
1043 luaL_loadbuffer(lua,errh_func,strlen(errh_func),"@err_handler_def"); in scriptingInit()
1044 lua_pcall(lua,0,0,0); in scriptingInit()
1059 scriptingEnableGlobalsProtection(lua); in scriptingInit()
1061 server.lua = lua; in scriptingInit()
1068 lua_close(server.lua); in scriptingRelease()
1078 void luaSetGlobalArray(lua_State *lua, char *var, robj **elev, int elec) { in luaSetGlobalArray() argument
1081 lua_newtable(lua); in luaSetGlobalArray()
1083 lua_pushlstring(lua,(char*)elev[j]->ptr,sdslen(elev[j]->ptr)); in luaSetGlobalArray()
1084 lua_rawseti(lua,-2,j+1); in luaSetGlobalArray()
1086 lua_setglobal(lua,var); in luaSetGlobalArray()
1145 int luaCreateFunction(client *c, lua_State *lua, char *funcname, robj *body) { in luaCreateFunction() argument
1154 if (luaL_loadbuffer(lua,funcdef,sdslen(funcdef),"@user_script")) { in luaCreateFunction()
1156 lua_tostring(lua,-1)); in luaCreateFunction()
1157 lua_pop(lua,1); in luaCreateFunction()
1162 if (lua_pcall(lua,0,0,0)) { in luaCreateFunction()
1164 lua_tostring(lua,-1)); in luaCreateFunction()
1165 lua_pop(lua,1); in luaCreateFunction()
1182 void luaMaskCountHook(lua_State *lua, lua_Debug *ar) { in luaMaskCountHook() argument
1185 UNUSED(lua); in luaMaskCountHook()
1201 lua_pushstring(lua,"Script killed by user with SCRIPT KILL..."); in luaMaskCountHook()
1202 lua_error(lua); in luaMaskCountHook()
1207 lua_State *lua = server.lua; in evalGenericCommand() local
1263 lua_getglobal(lua, "__redis__err__handler"); in evalGenericCommand()
1266 lua_getglobal(lua, funcname); in evalGenericCommand()
1267 if (lua_isnil(lua,-1)) { in evalGenericCommand()
1268 lua_pop(lua,1); /* remove the nil from the stack */ in evalGenericCommand()
1273 lua_pop(lua,1); /* remove the error handler from the stack. */ in evalGenericCommand()
1277 if (luaCreateFunction(c,lua,funcname,c->argv[1]) == C_ERR) { in evalGenericCommand()
1278 lua_pop(lua,1); /* remove the error handler from the stack. */ in evalGenericCommand()
1284 lua_getglobal(lua, funcname); in evalGenericCommand()
1285 serverAssert(!lua_isnil(lua,-1)); in evalGenericCommand()
1290 luaSetGlobalArray(lua,"KEYS",c->argv+3,numkeys); in evalGenericCommand()
1291 luaSetGlobalArray(lua,"ARGV",c->argv+3+numkeys,c->argc-3-numkeys); in evalGenericCommand()
1309 lua_sethook(lua,luaMaskCountHook,LUA_MASKCOUNT,100000); in evalGenericCommand()
1312 lua_sethook(server.lua,luaLdbLineHook,LUA_MASKLINE|LUA_MASKCOUNT,100000); in evalGenericCommand()
1319 err = lua_pcall(lua,0,1,-2); in evalGenericCommand()
1322 if (delhook) lua_sethook(lua,NULL,0,0); /* Disable hook */ in evalGenericCommand()
1344 lua_gc(lua,LUA_GCSTEP,LUA_GC_CYCLE_PERIOD); in evalGenericCommand()
1351 funcname, lua_tostring(lua,-1)); in evalGenericCommand()
1352 lua_pop(lua,2); /* Consume the Lua reply and remove error handler. */ in evalGenericCommand()
1356 luaReplyToRedisReply(c,lua); /* Convert and consume the reply. */ in evalGenericCommand()
1357 lua_pop(lua,1); /* Remove the error handler. */ in evalGenericCommand()
1449 if (luaCreateFunction(c,server.lua,funcname,c->argv[2]) in scriptCommand()
1854 sds ldbCatStackValueRec(sds s, lua_State *lua, int idx, int level) { in ldbCatStackValueRec() argument
1855 int t = lua_type(lua,idx); in ldbCatStackValueRec()
1864 char *strp = (char*)lua_tolstring(lua,idx,&strl); in ldbCatStackValueRec()
1869 s = sdscat(s,lua_toboolean(lua,idx) ? "true" : "false"); in ldbCatStackValueRec()
1872 s = sdscatprintf(s,"%g",(double)lua_tonumber(lua,idx)); in ldbCatStackValueRec()
1886 lua_pushnil(lua); /* The first key to start the iteration is nil. */ in ldbCatStackValueRec()
1887 while (lua_next(lua,idx-1)) { in ldbCatStackValueRec()
1890 (lua_type(lua,-2) != LUA_TNUMBER || in ldbCatStackValueRec()
1891 lua_tonumber(lua,-2) != expected_index)) is_array = 0; in ldbCatStackValueRec()
1894 repr1 = ldbCatStackValueRec(repr1,lua,-1,level); in ldbCatStackValueRec()
1898 repr2 = ldbCatStackValueRec(repr2,lua,-2,level); in ldbCatStackValueRec()
1900 repr2 = ldbCatStackValueRec(repr2,lua,-1,level); in ldbCatStackValueRec()
1902 lua_pop(lua,1); /* Stack: table, key. Ready for next iteration. */ in ldbCatStackValueRec()
1921 const void *p = lua_topointer(lua,idx); in ldbCatStackValueRec()
1939 sds ldbCatStackValue(sds s, lua_State *lua, int idx) { in ldbCatStackValue() argument
1940 return ldbCatStackValueRec(s,lua,idx,0); in ldbCatStackValue()
1946 void ldbLogStackValue(lua_State *lua, char *prefix) { in ldbLogStackValue() argument
1948 s = ldbCatStackValue(s,lua,-1); in ldbLogStackValue()
2036 void ldbPrint(lua_State *lua, char *varname) { in ldbPrint() argument
2040 while (lua_getstack(lua,l,&ar) != 0) { in ldbPrint()
2044 while((name = lua_getlocal(lua,&ar,i)) != NULL) { in ldbPrint()
2047 ldbLogStackValue(lua,"<value> "); in ldbPrint()
2048 lua_pop(lua,1); in ldbPrint()
2051 lua_pop(lua,1); /* Discard the var name on the stack. */ in ldbPrint()
2058 lua_getglobal(lua, varname); in ldbPrint()
2059 ldbLogStackValue(lua,"<value> "); in ldbPrint()
2060 lua_pop(lua,1); in ldbPrint()
2068 void ldbPrintAll(lua_State *lua) { in ldbPrintAll() argument
2072 if (lua_getstack(lua,0,&ar) != 0) { in ldbPrintAll()
2075 while((name = lua_getlocal(lua,&ar,i)) != NULL) { in ldbPrintAll()
2079 ldbLogStackValue(lua,prefix); in ldbPrintAll()
2083 lua_pop(lua,1); in ldbPrintAll()
2137 void ldbEval(lua_State *lua, sds *argv, int argc) { in ldbEval() argument
2143 if (luaL_loadbuffer(lua,expr,sdslen(expr),"@ldb_eval")) { in ldbEval()
2144 lua_pop(lua,1); in ldbEval()
2146 if (luaL_loadbuffer(lua,code,sdslen(code),"@ldb_eval")) { in ldbEval()
2147 ldbLog(sdscatfmt(sdsempty(),"<error> %s",lua_tostring(lua,-1))); in ldbEval()
2148 lua_pop(lua,1); in ldbEval()
2157 if (lua_pcall(lua,0,1,0)) { in ldbEval()
2158 ldbLog(sdscatfmt(sdsempty(),"<error> %s",lua_tostring(lua,-1))); in ldbEval()
2159 lua_pop(lua,1); in ldbEval()
2162 ldbLogStackValue(lua,"<retval> "); in ldbEval()
2163 lua_pop(lua,1); in ldbEval()
2170 void ldbRedis(lua_State *lua, sds *argv, int argc) { in ldbRedis() argument
2173 lua_getglobal(lua,"redis"); in ldbRedis()
2174 lua_pushstring(lua,"call"); in ldbRedis()
2175 lua_gettable(lua,-2); /* Stack: redis, redis.call */ in ldbRedis()
2177 lua_pushlstring(lua,argv[j],sdslen(argv[j])); in ldbRedis()
2180 lua_pcall(lua,argc-1,1,0); /* Stack: redis, result */ in ldbRedis()
2183 lua_pop(lua,2); /* Discard the result and clean the stack. */ in ldbRedis()
2188 void ldbTrace(lua_State *lua) { in ldbTrace() argument
2192 while(lua_getstack(lua,level,&ar)) { in ldbTrace()
2193 lua_getinfo(lua,"Snl",&ar); in ldbTrace()
2226 int ldbRepl(lua_State *lua) { in ldbRepl() argument
2290 ldbTrace(lua); in ldbRepl()
2299 ldbEval(lua,argv,argc); in ldbRepl()
2302 lua_pushstring(lua, "script aborted for user request"); in ldbRepl()
2303 lua_error(lua); in ldbRepl()
2306 ldbRedis(lua,argv,argc); in ldbRepl()
2310 ldbPrint(lua,argv[1]); in ldbRepl()
2312 ldbPrintAll(lua); in ldbRepl()
2343 void luaLdbLineHook(lua_State *lua, lua_Debug *ar) { in luaLdbLineHook() argument
2344 lua_getstack(lua,0,ar); in luaLdbLineHook()
2345 lua_getinfo(lua,"Sl",ar); in luaLdbLineHook()
2379 if (ldbRepl(lua) == C_ERR && timeout) { in luaLdbLineHook()
2383 lua_pushstring(lua, "timeout during Lua debugging with client closing connection"); in luaLdbLineHook()
2384 lua_error(lua); in luaLdbLineHook()