diff options
author | Christian Pointner <equinox@anylike.org> | 2010-05-30 22:30:55 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anylike.org> | 2010-05-30 22:30:55 +0000 |
commit | 962c516da2258d31ef4c5bcf3bed7e1e47099a42 (patch) | |
tree | fee94b01ab4b74f2a2dcbc208cbc92aba0a5203a | |
parent | added quit and ping command to debug shell (diff) |
debug shell is now able to execute lua code
-rw-r--r-- | src/debug_shell.lua | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/src/debug_shell.lua b/src/debug_shell.lua index c9bc98c..58fb258 100644 --- a/src/debug_shell.lua +++ b/src/debug_shell.lua @@ -117,15 +117,39 @@ end debug_shell.exec_cmd = function() log.printf(log.DEBUG, "debug shell: received string: '%s'", debug_shell.buffer) - local cmd, sep, param = string.match(debug_shell.buffer, "^(%w+)(.?)(.*)$"); - if(cmd == 'quit') then - if(sep and sep ~= "") then return 0 end - log.printf(log.NOTICE, "debug shell: quit command received") - return 2 - elseif(cmd == 'ping') then - if(sep == ' ') then debug_shell.socks[2]:send("pong " .. (param or "") .. "\n") - else debug_shell.socks[2]:send("pong\n") end + local luacode = string.match(debug_shell.buffer, "^!(.*)$"); + if(luacode and luacode ~= "") then + local chunk = loadstring(luacode) + if(chunk) then + log.printf(log.DEBUG, "debug shell: calling lua command: '%s'", luacode) + local results = { pcall(function() chunk() end) } + if(results[1]) then + for i,result in ipairs(results) do + if(i ~= 1) then + debug_shell.socks[2]:send(string.format("#%d: %s\n", i, tostring(result))) + end + end + else + debug_shell.socks[2]:send("lua call failed\n") + end + else + debug_shell.socks[2]:send("syntax error\n") + end + else + local cmd, sep, param = string.match(debug_shell.buffer, "^(%w+)(.?)(.*)$"); + + if(cmd == 'quit') then + if(sep and sep ~= "") then return 0 end + log.printf(log.NOTICE, "debug shell: quit command received") + return 2 + elseif(cmd == 'ping') then + if(sep == ' ') then debug_shell.socks[2]:send("pong " .. (param or "") .. "\n") + else debug_shell.socks[2]:send("pong\n") end + else + debug_shell.socks[2]:send("unknown command\n") + end end + return 0 end |