Added js-utils file.
authorVladimir Sedach <vsedach@gmail.com>
Tue, 19 Jun 2007 19:37:48 +0000 (19:37 +0000)
committerVladimir Sedach <vsedach@gmail.com>
Tue, 19 Jun 2007 19:37:48 +0000 (19:37 +0000)
parenscript.asd
src/js-utils.lisp [new file with mode: 0644]

index 17573b7..56f0168 100644 (file)
@@ -11,7 +11,7 @@
   :name "parenscript"
   :author "Manuel Odendahl <manuel@bl0rg.net>"
   :version "0"
-  :maintainer "Edward Marco Baringer <mb@bese.it>"
+  :maintainer "Vladimir Sedach <vsedach@gmail.com>"
   :licence "BSD"
   :description "js - javascript compiler"
   :components ((:static-file "parenscript.asd")
@@ -23,6 +23,7 @@
                              (:file "js-html" :depends-on ("package" "js" "utils"))
                              (:file "css" :depends-on ("package" "utils"))
                              (:file "compile-js" :depends-on ("package" "js"))
+                             (:file "js-utils" :depends-on ("package" "js"))
                              (:module :lib
                                       :components ((:static-file "functional.lisp")))))))
 
diff --git a/src/js-utils.lisp b/src/js-utils.lisp
new file mode 100644 (file)
index 0000000..31afd30
--- /dev/null
@@ -0,0 +1,31 @@
+(in-package :js)
+
+;;; Handy utilities for doing common tasks found in many web browser
+;;; JavaScript implementations
+
+(defjsmacro with-timeout ((timeout) &body body)
+  `(set-timeout (lambda () ,@body) ,timeout))
+
+;;; Arithmetic
+
+(defmacro def-js-maths (&rest mathdefs)
+  `(progn ,@(mapcar (lambda (def) (cons 'defjsmacro def)) mathdefs)))
+
+(def-js-maths
+    (min (&rest nums) `(*math.min ,@nums))
+    (max (&rest nums) `(*math.max ,@nums))
+    (ceiling (n) `(*math.ceil ,n))
+    (abs (n) `(*math.abs ,n))
+    (sin (n) `(*math.sin ,n))
+    (cos (n) `(*math.cos ,n))
+    (tan (n) `(*math.tan ,n))
+    (acos (n) `(*math.acos ,n))
+    (asin (n) `(*math.asin ,n))
+    (atan (n) `(*math.atan ,n))
+    (exp (n) `(*math.exp ,n))
+    (floor (n) `(*math.floor ,n))
+    (expt (base power) `(*math.pow ,base ,power))
+    (round (n) `(*math.round ,n))
+    (random (&optional upto) (if upto
+                                 `(floor (* ,upto (*math.random)))
+                                 '(*math.random))))