ex/tryhy: per request repl instance
This commit is contained in:
parent
a090b86b5e
commit
079e3002a7
@ -1,15 +1,24 @@
|
||||
$(document).ready(function(){
|
||||
var backlog = [];
|
||||
$('#hy-console').console({
|
||||
promptLabel: 'hy=> ',
|
||||
commandValidate:function(line){
|
||||
if (line == "") return false;
|
||||
if (line == '') return false;
|
||||
else return true;
|
||||
},
|
||||
commandHandle:function(line, report){
|
||||
$.getJSON("/eval", {code: line}, function(data) {
|
||||
report([{msg : data.stdout, className:"jquery-console-message-value"},
|
||||
{msg : data.stderr, className:"jquery-console-message-error"}]);
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/eval',
|
||||
data: JSON.stringify({code: line, env: backlog}),
|
||||
contentType: 'application/json',
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
report([{msg : data.stdout, className:'jquery-console-message-value'},
|
||||
{msg : data.stderr, className:'jquery-console-message-error'}]);
|
||||
}
|
||||
});
|
||||
backlog.push(line);
|
||||
},
|
||||
animateScroll:true,
|
||||
promptHistory:true,
|
||||
|
@ -1,4 +1,3 @@
|
||||
(require hy.contrib.meth)
|
||||
(import [hy.cmdline [HyREPL]]
|
||||
[sys]
|
||||
[StringIO [StringIO]]
|
||||
@ -18,9 +17,13 @@
|
||||
(setv sys.stderr old-stderr)
|
||||
{"stdout" (fake-stdout.getvalue) "stderr" (fake-stderr.getvalue)})]])
|
||||
|
||||
|
||||
(def repl (MyHyREPL))
|
||||
|
||||
(def app (Flask __name__))
|
||||
(route hello "/<name>" [name] (.format "(hello \"{0}!\")" name))
|
||||
(route eval-get "/eval" [] (json.dumps (repl.eval (get request.args "code"))))
|
||||
|
||||
(with-decorator (kwapply (app.route "/eval") {"methods" ["POST"]})
|
||||
(fn []
|
||||
(let [[repl (MyHyREPL)] [input (request.get_json)]]
|
||||
(foreach [expr (get input "env")]
|
||||
(repl.eval expr))
|
||||
(json.dumps (repl.eval (get input "code")))
|
||||
)))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user