Skip to content

Commit

Permalink
loader button
Browse files Browse the repository at this point in the history
  • Loading branch information
pwmarcz authored and nishio committed Jun 17, 2012
1 parent 628448c commit 035e5d7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lisp-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,26 @@ lisp.replTerminal = function(elt) {
lisp.terminal = elt.terminal();
};

// Clicking 'button' will load 'source' to the interpreter
lisp.replLoader = function(source, button) {
button.click(
function() {
lisp.terminal.echo('Loading source...');
var parser = new lisp.Parser(source.val());
try {
while (!parser.empty()) {
var term = parser.readTerm();
if (term != null) {
var result = term.eval();
lisp.terminal.echo(result.print());
} else { // term == null
if (!parser.empty())
parser.parseError();
}
}
} catch(err) {
console.log(err);
lisp.terminal.error(err);
}
});
};
1 change: 1 addition & 0 deletions test.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<script>
$(function() {
lisp.replTerminal($('#term'));
lisp.replLoader($('#source'), $('#load'));
lisp.test();
$('body').click(function() { $('#term').terminal().disable(); });
});
Expand Down

0 comments on commit 035e5d7

Please sign in to comment.