MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ldbPrint

Function ldbPrint

app/redis-6.2.6/src/scripting.c:2457–2485  ·  view source on GitHub ↗

Implements the "print " command of the Lua debugger. It scans for Lua * var "varname" starting from the current stack frame up to the top stack * frame. The first matching variable is printed. */

Source from the content-addressed store, hash-verified

2455 * var "varname" starting from the current stack frame up to the top stack
2456 * frame. The first matching variable is printed. */
2457void ldbPrint(lua_State *lua, char *varname) {
2458 lua_Debug ar;
2459
2460 int l = 0; /* Stack level. */
2461 while (lua_getstack(lua,l,&ar) != 0) {
2462 l++;
2463 const char *name;
2464 int i = 1; /* Variable index. */
2465 while((name = lua_getlocal(lua,&ar,i)) != NULL) {
2466 i++;
2467 if (strcmp(varname,name) == 0) {
2468 ldbLogStackValue(lua,"<value> ");
2469 lua_pop(lua,1);
2470 return;
2471 } else {
2472 lua_pop(lua,1); /* Discard the var name on the stack. */
2473 }
2474 }
2475 }
2476
2477 /* Let's try with global vars in two selected cases */
2478 if (!strcmp(varname,"ARGV") || !strcmp(varname,"KEYS")) {
2479 lua_getglobal(lua, varname);
2480 ldbLogStackValue(lua,"<value> ");
2481 lua_pop(lua,1);
2482 } else {
2483 ldbLog(sdsnew("No such variable."));
2484 }
2485}
2486
2487/* Implements the "print" command (without arguments) of the Lua debugger.
2488 * Prints all the variables in the current stack frame. */

Callers 1

ldbReplFunction · 0.85

Calls 7

strcmpFunction · 0.85
ldbLogStackValueFunction · 0.85
lua_getglobalFunction · 0.85
ldbLogFunction · 0.85
sdsnewFunction · 0.85
lua_getstackFunction · 0.50
lua_getlocalFunction · 0.50

Tested by

no test coverage detected