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