MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / ldbPrint

Function ldbPrint

src/scripting.cpp:2480–2508  ·  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

2478 * var "varname" starting from the current stack frame up to the top stack
2479 * frame. The first matching variable is printed. */
2480void ldbPrint(lua_State *lua, char *varname) {
2481 lua_Debug ar;
2482
2483 int l = 0; /* Stack level. */
2484 while (lua_getstack(lua,l,&ar) != 0) {
2485 l++;
2486 const char *name;
2487 int i = 1; /* Variable index. */
2488 while((name = lua_getlocal(lua,&ar,i)) != NULL) {
2489 i++;
2490 if (strcmp(varname,name) == 0) {
2491 ldbLogStackValue(lua,"<value> ");
2492 lua_pop(lua,1);
2493 return;
2494 } else {
2495 lua_pop(lua,1); /* Discard the var name on the stack. */
2496 }
2497 }
2498 }
2499
2500 /* Let's try with global vars in two selected cases */
2501 if (!strcmp(varname,"ARGV") || !strcmp(varname,"KEYS")) {
2502 lua_getglobal(lua, varname);
2503 ldbLogStackValue(lua,"<value> ");
2504 lua_pop(lua,1);
2505 } else {
2506 ldbLog(sdsnew("No such variable."));
2507 }
2508}
2509
2510/* Implements the "print" command (without arguments) of the Lua debugger.
2511 * Prints all the variables in the current stack frame. */

Callers 1

ldbReplFunction · 0.85

Calls 5

lua_getstackFunction · 0.85
lua_getlocalFunction · 0.85
ldbLogStackValueFunction · 0.85
ldbLogFunction · 0.85
sdsnewFunction · 0.85

Tested by

no test coverage detected