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

Function ldbEval

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

Implements the Lua debugger "eval" command. It just compiles the user * passed fragment of code and executes it, showing the result left on * the stack. */

Source from the content-addressed store, hash-verified

2556 * passed fragment of code and executes it, showing the result left on
2557 * the stack. */
2558void ldbEval(lua_State *lua, sds *argv, int argc) {
2559 /* Glue the script together if it is composed of multiple arguments. */
2560 sds code = sdsjoinsds(argv+1,argc-1," ",1);
2561 sds expr = sdscatsds(sdsnew("return "),code);
2562
2563 /* Try to compile it as an expression, prepending "return ". */
2564 if (luaL_loadbuffer(lua,expr,sdslen(expr),"@ldb_eval")) {
2565 lua_pop(lua,1);
2566 /* Failed? Try as a statement. */
2567 if (luaL_loadbuffer(lua,code,sdslen(code),"@ldb_eval")) {
2568 ldbLog(sdscatfmt(sdsempty(),"<error> %s",lua_tostring(lua,-1)));
2569 lua_pop(lua,1);
2570 sdsfree(code);
2571 sdsfree(expr);
2572 return;
2573 }
2574 }
2575
2576 /* Call it. */
2577 sdsfree(code);
2578 sdsfree(expr);
2579 if (lua_pcall(lua,0,1,0)) {
2580 ldbLog(sdscatfmt(sdsempty(),"<error> %s",lua_tostring(lua,-1)));
2581 lua_pop(lua,1);
2582 return;
2583 }
2584 ldbLogStackValue(lua,"<retval> ");
2585 lua_pop(lua,1);
2586}
2587
2588/* Implement the debugger "redis" command. We use a trick in order to make
2589 * the implementation very simple: we just call the Lua redis.call() command

Callers 1

ldbReplFunction · 0.85

Calls 11

sdsjoinsdsFunction · 0.85
sdscatsdsFunction · 0.85
sdsnewFunction · 0.85
luaL_loadbufferFunction · 0.85
sdslenFunction · 0.85
ldbLogFunction · 0.85
sdscatfmtFunction · 0.85
sdsemptyFunction · 0.85
sdsfreeFunction · 0.85
lua_pcallFunction · 0.85
ldbLogStackValueFunction · 0.85

Tested by

no test coverage detected