Paste number 60578: patch?

Index of paste annotations: 1

Paste number 60578: patch?
Pasted by: aks44
5 days, 15 hours ago
None
Paste contents:
Raw Source | XML | Display As
{
hunk ./javascript/sw/sw-ajax.js 59
-  [_$_]
+
+  $.swRun = function(code_id, async, json, func)
+  {
+    try
+    {
+      if (async)
+        func();
+      else
+        $.swReturnValue(code_id, json, func);
+    }
+    catch(exception)
+    {
+      $.swReturnFail(code_id, exception);
+    }
+  }
+
+
hunk ./src/ajax.lisp 41
-                     (post-parameter "exception-str")))))
+                     (sw-decode-json (post-parameter "exception-str"))))))
hunk ./src/code.lisp 24
-(defun js-ack (code-id code json)
-  (if *async*
-      code
-      (concatenate 'string "
-$.swReturnValue(
\"" code-id "\"," (if json "true" "false") ", function(){
-"
code "
-});"
)
)
)

-
-
-(defun js-fail (code-id)
-  "This can only be executed in a context where the variable `exception' exist."
-  (concatenate 'string "
-$.swReturnFail(
\"" code-id "\", exception);"
)
)

-
-
hunk ./src/code.lisp 45
-          (run-js (concatenate 'string "
-try{
-"
(js-ack (code-id-of code) (code-of code) json) "
-} catch(exception){
-"
(js-fail (code-id-of code)) "
-}"
)
)

+          (run-js (concatenate 'string "$.swRun(\"" (code-id-of code) "\","
+                               (if *async* "1" "0") ","
+                               (if json "1" "0")
+                               ",function(){" (code-of code) "})"
)
)

}

Annotations for this paste:

Annotation number 1: with-options macro
Pasted by: aks44
5 days, 14 hours ago
Paste contents:
Raw Source | Display As
(defun %with-options-error (context)
  (wotstr context ": ~A option ~S.")
)



(defun %with-options-parse (options assocs context)
  (let ((options (mkprlist options)))
    (dolist (option options)
      (block option-found
        (dolist (assoc assocs)
          (let ((kw (car assoc))
                (value (cdr assoc))
)

            (when (eq option kw)
              (ensure (not (car value))
                      (%with-options-error context) "duplicate" kw context
)

              (setf (car value) t)
              (return-from option-found)
)
)
)

          (error (%with-options-error context) "incorrect" option context)
)
)
)
)



(defmacro with-options (((&rest allowed-options) options &key (prefix "") (context "WITH-OPTIONS")) &body body)
  "Check a list of OPTIONS (keywords) against the ALLOWED-OPTIONS, and generate bindings accordingly.
Each keyword in OPTIONS generates a T binding, each missing keyword generates a NIL binding.
Bindings are named according to the keyword, optionally PREFIX'ed."

  (when-safe-compilation
    (%check nempty-keywords-list allowed-options 'with-options)
)

  (let ((symbols (loop :for option :in allowed-options
                    :collect (cons option (read-from-string (catstr prefix (symbol-name option))))
)
)
)

    `(let ,(loop :for symbol :in symbols :collect `(,(cdr symbol) (cons nil nil)))
       (%with-options-parse ,options
                            (list ,@(loop :for symbol :in symbols :collect `(cons ,(car symbol) ,(cdr symbol))))
                            ,context
)

       (let ,(loop :for symbol :in symbols :collect `(,(cdr symbol) (car ,(cdr symbol))))
         ,@body
)
)
)
)




(defun test (arg &rest options)
  (with-options ((:a :b :c) options :prefix "OPT-")
    (list arg opt-a opt-b opt-c)
)
)



(test 0)       => (0 NIL NIL NIL)
(test 1 :b)    => (1 NIL T NIL)
(test 2 :a :c) => (2 T NIL T)
(test 0 :x)    => ERROR, :X NOT AN ALLOWED OPTION

Colorize as:
Show Line Numbers
Index of paste annotations: 1

Ads absolutely not by Google

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.