Built in REPL was broken because it was installing from examples tree (now seed-examp...
authorRobert Carr <racarr@gnome.org>
Thu, 17 Dec 2009 22:09:48 +0000 (17:09 -0500)
committerRobert Carr <racarr@gnome.org>
Thu, 17 Dec 2009 22:09:48 +0000 (17:09 -0500)
extensions/Makefile.am
extensions/repl.js [new file with mode: 0755]

index 37c253c..13f0150 100644 (file)
@@ -2,3 +2,6 @@ EXTRA_DIST= Gio.js Seed.js.in Gtk.js GObject.js Clutter.js Gst.js
 
 extensiondir=$(datadir)/seed/extensions
 extension_DATA = Gio.js Seed.js Gtk.js GObject.js Clutter.js Gst.js
+
+repldir=$(datadir)/seed
+repl_DATA = repl.js
diff --git a/extensions/repl.js b/extensions/repl.js
new file mode 100755 (executable)
index 0000000..6e80cf3
--- /dev/null
@@ -0,0 +1,49 @@
+#!/usr/bin/env seed
+
+readline = imports.readline;
+sandbox = imports.sandbox;
+os = imports.os;
+
+var lastLastLength = '-1';
+
+context = new sandbox.Context();
+context.add_globals();
+
+bind_cr = function(){
+    var buffer = readline.buffer();
+    if (buffer.length == lastLastLength)
+       readline.done();
+    try {
+       Seed.check_syntax(buffer);
+       readline.done();
+    }
+    catch (e){
+       os.write(1, "\n..");
+       lastLastLength = buffer.length;
+       return;
+    }
+    os.write(1, "\n");
+    lastLastLength = buffer.length;
+}
+
+readline.bind('\n', bind_cr);
+readline.bind('\r', bind_cr);
+readline.bind('\t', function(){
+    readline.insert("\t");
+});
+
+//var re = /[^=<>*-^/]=[^=<>*-^/]\(*\s*(new\s*)?[^:punct:]|'|"+\)*$/
+
+while(1){
+    try{
+       item = readline.readline("> ");
+       result = context.eval(item);
+//     if (!re.exec(item) && (result != undefined))
+       if (result != undefined)
+           print(result)
+
+    }
+    catch(e){
+       print(e.name + " " + e.message);
+    }
+}