Mercurial Hosting > luan
changeset 1246:299996e03876
clean up http/tools
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 17 Jul 2018 15:43:11 -0600 |
parents | 2de84f128be3 |
children | 728d8e75f476 |
files | src/luan/modules/http/tools/Java_threads.luan src/luan/modules/http/tools/Luan_threads.luan src/luan/modules/http/tools/Run.luan src/luan/modules/http/tools/java_threads.html.luan src/luan/modules/http/tools/luan_threads.html.luan src/luan/modules/http/tools/run.luan src/luan/modules/http/tools/shell.html.luan |
diffstat | 7 files changed, 221 insertions(+), 210 deletions(-) [+] |
line wrap: on
line diff
diff -r 2de84f128be3 -r 299996e03876 src/luan/modules/http/tools/Java_threads.luan --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/luan/modules/http/tools/Java_threads.luan Tue Jul 17 15:43:11 2018 -0600 @@ -0,0 +1,55 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local Io = require "luan:Io.luan" +local Time = require "luan:Time.luan" +local Http = require "luan:http/Http.luan" +java() +local Thread = require "java:java.lang.Thread" + + +local Java_threads = {} + +function Java_threads.respond() + Io.stdout = Http.response.text_writer() + + local threads = Thread.getAllStackTraces() + local threads = {} + for thread, trace in Luan.pairs(Thread.getAllStackTraces()) do + threads[#threads+1] = { + trace = trace + string = thread.toString() + state = thread.getState() + } + end +%> +<!doctype html> +<html> + <body> + <h1>Java Threads</h1> + <p><%=Http.request.headers["host"]%> - <%=Time.format(Time.now())%></p> + <% + local count = 0 + for _, thread in Luan.ipairs(threads) do + %> + <p><%=thread.string%> <%=thread.state%> + <ul> + <% + local trace = thread.trace + for i in Luan.range( 0 , trace.length - 1 ) do + local line = trace[i].toString() + %><li><%=line%></li><% + end + %> + </ul></p> + <% + count = count + 1 + end + %> + <p><%=count%> threads found</p> + + </body> +</html> +<% +end + +return Java_threads
diff -r 2de84f128be3 -r 299996e03876 src/luan/modules/http/tools/Luan_threads.luan --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/luan/modules/http/tools/Luan_threads.luan Tue Jul 17 15:43:11 2018 -0600 @@ -0,0 +1,59 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local Io = require "luan:Io.luan" +local Time = require "luan:Time.luan" +local Http = require "luan:http/Http.luan" +java() +local Thread = require "java:java.lang.Thread" +local LuanException = require "java:luan.LuanException" +local JavaLuan = require "java:luan.Luan" + + +local Luan_threads = {} + +function Luan_threads.respond() + Io.stdout = Http.response.text_writer() + + local threads = Thread.getAllStackTraces() + local threads = {} + for thread, trace in Luan.pairs(Thread.getAllStackTraces()) do + threads[#threads+1] = { + trace = trace + string = thread.toString() + state = thread.getState() + } + end +%> +<!doctype html> +<html> + <body> + <h1>Luan Threads</h1> + <p><%=Http.request.headers["host"]%> - <%=Time.format(Time.now())%></p> + <% + local count = 0 + for _, thread in Luan.ipairs(threads) do + local luan_trace = JavaLuan.table(LuanException.justLuan(thread.trace)) + if #luan_trace > 0 then + %> + <p><%=thread.string%> <%=thread.state%> + <ul> + <% + for i, el in Luan.ipairs(luan_trace) do + local line = LuanException.toString(el); + %><li><%=line%></li><% + end + %> + </ul></p> + <% + count = count + 1 + end + end + %> + <p><%=count%> threads found</p> + + </body> +</html> +<% +end + +return Luan_threads
diff -r 2de84f128be3 -r 299996e03876 src/luan/modules/http/tools/Run.luan --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/luan/modules/http/tools/Run.luan Tue Jul 17 15:43:11 2018 -0600 @@ -0,0 +1,107 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local load = Luan.load or error() +local try = Luan.try or error() +local Io = require "luan:Io.luan" +local print = Io.print or error() +local String = require "luan:String.luan" +local gmatch = String.gmatch or error() +local Http = require "luan:http/Http.luan" + + +local Run = {} + +local function lines(s) + local matcher = gmatch(s,"([^\n]*)\n|([^\n])+$") + return function() + local m1, m2 = matcher() + return m1 or m2 + end +end + +local function print_with_line_numbers(s) + local i = 1 + for line in lines(s) do + print(i,line) + i = i + 1 + end +end + +local function form() %> +<!doctype html> +<html> + <head> + <title>Run Luan Code</title> + <style> + body { + font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; + text-align: center; + margin-top: 1em; + } + h2 { + margin-bottom: .3em; + font-weight: normal; + } + textarea { + font: inherit; + border-radius: 4px; + padding: .5em .8em; + } + input[type="submit"] { + margin-top: .3em; + color: white; + background: #337ab7; + border-color: #337ab7; + font: inherit; + padding: .5em; + border-radius: 4px; + } + input[type="submit"]:hover { + background: #236aa7 !important; + } + </style> + </head> + <body> + <h2>Run Luan Code</h2> + <form method="post"> + <input type="hidden" name="content_type" value="text/plain; charset=utf-8" /> + <div> + <textarea name="code" rows="20" cols="90" wrap="off" autofocus></textarea> + </div> + <div> + <input type="submit" value="Execute Luan Code"/> + </div> + </form> + </body> +</html> +<% end + +function Run.respond() + local content_type = Http.request.parameters.content_type + if content_type ~= nil then + Http.response.headers["content-type"] = content_type + end + Io.stdout = Http.response.text_writer() + local code = Http.request.parameters.code + if code == nil then + form() + return + end + try { + function() + local run = load(code,"<web_run>") + run() + end; + catch = function(e) + Http.response.reset() + Http.response.headers["content-type"] = "text/plain; charset=utf-8" + Io.stdout = Http.response.text_writer() + print(e) + print"" + print"" + print_with_line_numbers(code) + end; + } +end + +return Run
diff -r 2de84f128be3 -r 299996e03876 src/luan/modules/http/tools/java_threads.html.luan --- a/src/luan/modules/http/tools/java_threads.html.luan Mon Jul 16 17:26:45 2018 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -local Luan = require "luan:Luan.luan" -local error = Luan.error -local Io = require "luan:Io.luan" -local Time = require "luan:Time.luan" -local Http = require "luan:http/Http.luan" -java() -local Thread = require "java:java.lang.Thread" - - -return function() - Io.stdout = Http.response.text_writer() - - local threads = Thread.getAllStackTraces() - local threads = {} - for thread, trace in Luan.pairs(Thread.getAllStackTraces()) do - threads[#threads+1] = { - trace = trace - string = thread.toString() - state = thread.getState() - } - end -%> -<!doctype html> -<html> - <body> - <h1>Java Threads</h1> - <p><%=Http.request.headers["host"]%> - <%=Time.format(Time.now())%></p> - <% - local count = 0 - for _, thread in Luan.ipairs(threads) do - %> - <p><%=thread.string%> <%=thread.state%> - <ul> - <% - local trace = thread.trace - for i in Luan.range( 0 , trace.length - 1 ) do - local line = trace[i].toString() - %><li><%=line%></li><% - end - %> - </ul></p> - <% - count = count + 1 - end - %> - <p><%=count%> threads found</p> - - </body> -</html> -<% -end
diff -r 2de84f128be3 -r 299996e03876 src/luan/modules/http/tools/luan_threads.html.luan --- a/src/luan/modules/http/tools/luan_threads.html.luan Mon Jul 16 17:26:45 2018 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -local Luan = require "luan:Luan.luan" -local error = Luan.error -local Io = require "luan:Io.luan" -local Time = require "luan:Time.luan" -local Http = require "luan:http/Http.luan" -java() -local Thread = require "java:java.lang.Thread" -local LuanException = require "java:luan.LuanException" -local JavaLuan = require "java:luan.Luan" - - -return function() - Io.stdout = Http.response.text_writer() - - local threads = Thread.getAllStackTraces() - local threads = {} - for thread, trace in Luan.pairs(Thread.getAllStackTraces()) do - threads[#threads+1] = { - trace = trace - string = thread.toString() - state = thread.getState() - } - end -%> -<!doctype html> -<html> - <body> - <h1>Luan Threads</h1> - <p><%=Http.request.headers["host"]%> - <%=Time.format(Time.now())%></p> - <% - local count = 0 - for _, thread in Luan.ipairs(threads) do - local luan_trace = JavaLuan.table(LuanException.justLuan(thread.trace)) - if #luan_trace > 0 then - %> - <p><%=thread.string%> <%=thread.state%> - <ul> - <% - for i, el in Luan.ipairs(luan_trace) do - local line = LuanException.toString(el); - %><li><%=line%></li><% - end - %> - </ul></p> - <% - count = count + 1 - end - end - %> - <p><%=count%> threads found</p> - - </body> -</html> -<% -end
diff -r 2de84f128be3 -r 299996e03876 src/luan/modules/http/tools/run.luan --- a/src/luan/modules/http/tools/run.luan Mon Jul 16 17:26:45 2018 -0600 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +0,0 @@ -local Luan = require "luan:Luan.luan" -local error = Luan.error -local load = Luan.load or error() -local try = Luan.try or error() -local Io = require "luan:Io.luan" -local print = Io.print or error() -local String = require "luan:String.luan" -local gmatch = String.gmatch or error() -local Http = require "luan:http/Http.luan" - - -local function lines(s) - local matcher = gmatch(s,"([^\n]*)\n|([^\n])+$") - return function() - local m1, m2 = matcher() - return m1 or m2 - end -end - -local function print_with_line_numbers(s) - local i = 1 - for line in lines(s) do - print(i,line) - i = i + 1 - end -end - -local function form() %> -<!doctype html> -<html> - <head> - <title>Run Luan Code</title> - <style> - body { - font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; - text-align: center; - margin-top: 1em; - } - h2 { - margin-bottom: .3em; - font-weight: normal; - } - textarea { - font: inherit; - border-radius: 4px; - padding: .5em .8em; - } - input[type="submit"] { - margin-top: .3em; - color: white; - background: #337ab7; - border-color: #337ab7; - font: inherit; - padding: .5em; - border-radius: 4px; - } - input[type="submit"]:hover { - background: #236aa7 !important; - } - </style> - </head> - <body> - <h2>Run Luan Code</h2> - <form method="post"> - <input type="hidden" name="content_type" value="text/plain; charset=utf-8" /> - <div> - <textarea name="code" rows="20" cols="90" wrap="off" autofocus></textarea> - </div> - <div> - <input type="submit" value="Execute Luan Code"/> - </div> - </form> - </body> -</html> -<% end - -return function() - local content_type = Http.request.parameters.content_type - if content_type ~= nil then - Http.response.headers["content-type"] = content_type - end - Io.stdout = Http.response.text_writer() - local code = Http.request.parameters.code - if code == nil then - form() - return - end - try { - function() - local run = load(code,"<web_run>") - run() - end; - catch = function(e) - Http.response.reset() - Http.response.headers["content-type"] = "text/plain; charset=utf-8" - Io.stdout = Http.response.text_writer() - print(e) - print"" - print"" - print_with_line_numbers(code) - end; - } -end