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. */
| 2556 | * passed fragment of code and executes it, showing the result left on |
| 2557 | * the stack. */ |
| 2558 | void 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 |
no test coverage detected