Skip to content

Commit

Permalink
Added web repl support code.
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Oct 11, 2014
1 parent 425b359 commit dcbe588
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/web-repl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
function moveCaretToEnd(el) {
if (typeof el.selectionStart == "number") {
el.selectionStart = el.selectionEnd = el.value.length;
} else if (typeof el.createTextRange != "undefined") {
el.focus();
var range = el.createTextRange();
range.collapse(false);
range.select();
}
}

function handleReplInput(e) {
if (e.target.value.indexOf("\n") != -1) {
var input = e.target.value;
document.getElementById("repl-out").innerHTML += "---> " + input;

e.target.value = '';
replInvokeCnt++;

var stmt = "Shell_Class_" + replInvokeCnt++ + " = ( run: it = ( | tmp | tmp := ("
+ input + " ). 'it = ' print. ^tmp println ) )";
var myClass = compileClassString(stmt, null);
var myObject = universe.newInstance(myClass);
var shellMethod = myClass.lookupInvokable(universe.symbolFor("run:"));
try {
it = shellMethod.invoke(null, [myObject, it]);
} catch (e) {
document.getElementById("repl-out").innerHTML += "Error: " + e.toString();
}
}
}

universe.print = function(msg) {
document.getElementById("repl-out").innerHTML += msg;
};

universe.println = function(msg) {
document.getElementById("repl-out").innerHTML += msg + "\n";
};

universe.errorPrint = function(msg) {
document.getElementById("repl-out").innerHTML += "Error" + msg;
};

universe.errorPrintln = function(msg) {
document.getElementById("repl-out").innerHTML += "Error" + msg + "\n";
};


universe.initializeForStandardRepl();
it = som.nilObject;

moveCaretToEnd(document.getElementById("repl-in"));

replInvokeCnt = 0;
document.getElementById("example-div").style.display = "none";
document.getElementById("repl").style.display = "block";

0 comments on commit dcbe588

Please sign in to comment.