From 962c516da2258d31ef4c5bcf3bed7e1e47099a42 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 30 May 2010 22:30:55 +0000 Subject: debug shell is now able to execute lua code --- src/debug_shell.lua | 40 ++++++++++++++++++++++++++++++++-------- 1 file 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 -- cgit v1.2.3