summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/debug_shell.lua40
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