]> gitweb.factorcode.org Git - factor.git/commitdiff
fjsc: various bug fixes
authorchris.double <chris.double@double.co.nz>
Sun, 17 Dec 2006 05:45:59 +0000 (05:45 +0000)
committerchris.double <chris.double@double.co.nz>
Sun, 17 Dec 2006 05:45:59 +0000 (05:45 +0000)
apps/furnace-fjsc/repl.fhtml
apps/furnace-fjsc/resources/bootstrap.factor
apps/furnace-fjsc/resources/bootstrap.js
libs/fjsc/fjsc.factor

index b7a6d7d6dffc8732971757525a448ac26363c4f3..106ebc28933d50691dfafea9bffbf09e899cb5f6 100644 (file)
@@ -6,4 +6,6 @@
 <div id="compiled">
 </div>
 <div id="stack">
+</div>
+<div id="playground">
 </div>
\ No newline at end of file
index 30ac7dd0cac7deca021cd858b016a9bc2d4618b5..7c160492423f847c6238ea1ef07a2cca61664ea5 100644 (file)
@@ -4,9 +4,32 @@
 
 "browser-dom" in
 
-: $ ( string -- result )
+: elements ( string -- result )
   #! Call JQuery's $ function
   window { "result" } "" "$" { "string" } alien-invoke ;
   
+: html ( string -- element ) 
+  #! Set the innerHTML of element using jQuery
+  { } "" "html" { "string" } alien-invoke ;
+
+: bind-event ( name element quot -- )
+  >function swap { } "" "bind" { "string" "function" } alien-invoke ;
 
 "scratchpad" in
+
+: example1 ( -- )
+  "<button id='test'>Press Me</button>" "#playground" elements html ;
+
+: example2 ( -- )
+  "click" "#test" elements [ "clicked" alert ] bind-event ;
+
+: example3 ( -- )
+  [
+    [
+      >r "click" "#test" elements r> [ continue ] curry bind-event
+      "Waiting for click on button" alert
+      continue
+    ] callcc0
+    drop "Click done!" alert 
+  ] callcc0 ;
+  
index 3c8494ef4dc9b387ad4d621bd146b1f255490a90..50b330cf16e5749c262d774f3860be1e26676517 100644 (file)
@@ -330,6 +330,25 @@ factor.add_word("kernel", "forget", "primitive", function(next) {
   factor.call_next(next);  
 });
 
+factor.add_word("kernel", ">function", "primitive", function(next) {   
+  var stack = factor.cont.data_stack;
+  var word = stack.pop();
+  stack.push(function() { word.func(function() { }) });
+  factor.call_next(next);  
+});
+
+factor.add_word("kernel", "curry", "primitive", function(next) {   
+  var stack = factor.cont.data_stack;
+  var quot = stack.pop();
+  var value = stack.pop();
+  
+  stack.push(factor.make_quotation("quotation", function(next) {
+    factor.cont.data_stack.push(value);   
+    quot.execute(factor.cont.next);
+  }));
+  factor.call_next(next);
+});
+
 /* Math vocabulary */
 factor.add_word("math", "*", "primitive", function(next) {
   var stack = factor.cont.data_stack;
@@ -384,7 +403,7 @@ factor.add_word("alien", "alien-invoke", "primitive", function(next) {
   for(var i = 0; i < arg_types.length; ++i) {
     args[i] = stack.pop();
   }
-  var v = obj[method_name].apply(obj, args);
+  var v = obj[method_name].apply(obj, args.reverse());
   if(return_values.length > 0)
     stack.push(v);
   factor.call_next(next);
@@ -399,6 +418,15 @@ factor.add_word("alien", "alien-property", "primitive", function(next) {
   factor.call_next(next);
 });
 
+factor.add_word("alien", "set-alien-property", "primitive", function(next) {  
+  var stack = factor.cont.data_stack;
+  var obj = stack.pop();
+  var property_name = stack.pop();
+  var data = stack.pop();
+  obj[property_name] = v;
+  factor.call_next(next);
+});
+
 factor.add_word("words", "vocabs", "primitive", function(next) {   
   var stack = factor.cont.data_stack;
   var result = [];
index 08b3ba038c7f738171af6e97ea70749f942aa5df..a4109647050f5aa0b15b8cee3b6686c2e950286e 100644 (file)
@@ -129,9 +129,9 @@ M: ast-number (compile)
   "," , ;
 
 M: ast-string (literal) 
-  "'" ,
+  "\"" ,
   ast-string-value ,
-  "'" , ;
+  "\"" , ;
 
 M: ast-string (compile) 
   "factor.push_data(" ,