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

Function ldbEval

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

2579 * passed fragment of code and executes it, showing the result left on
2580 * the stack. */
2581void ldbEval(lua_State *lua, sds *argv, int argc) {
2582 /* Glue the script together if it is composed of multiple arguments. */
2583 sds code = sdsjoinsds(argv+1,argc-1," ",1);
2584 sds expr = sdscatsds(sdsnew("return "),code);
2585
2586 /* Try to compile it as an expression, prepending "return ". */
2587 if (luaL_loadbuffer(lua,expr,sdslen(expr),"@ldb_eval")) {
2588 lua_pop(lua,1);
2589 /* Failed? Try as a statement. */
2590 if (luaL_loadbuffer(lua,code,sdslen(code),"@ldb_eval")) {
2591 ldbLog(sdscatfmt(sdsempty(),"<error> %s",lua_tostring(lua,-1)));
2592 lua_pop(lua,1);
2593 sdsfree(code);
2594 sdsfree(expr);
2595 return;
2596 }
2597 }
2598
2599 /* Call it. */
2600 sdsfree(code);
2601 sdsfree(expr);
2602 if (lua_pcall(lua,0,1,0)) {
2603 ldbLog(sdscatfmt(sdsempty(),"<error> %s",lua_tostring(lua,-1)));
2604 lua_pop(lua,1);
2605 return;
2606 }
2607 ldbLogStackValue(lua,"<retval> ");
2608 lua_pop(lua,1);
2609}
2610
2611/* Implement the debugger "redis" command. We use a trick in order to make
2612 * 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