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. */
| 2455 | * var "varname" starting from the current stack frame up to the top stack |
| 2456 | * frame. The first matching variable is printed. */ |
| 2457 | void 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. */ |
no test coverage detected