commit e8bd062f9536370d76181d2b5ba7468c86a1d355
parent 22ecb9ae672276821e0a01800b2a628865567bf9
Author: Alexander Burger <abu@software-lab.de>
Date: Fri, 10 May 2013 17:22:33 +0200
JavaScript 'lisp': Preserve numeric vs. string types
Diffstat:
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/lib/form.js b/lib/form.js
@@ -1,4 +1,4 @@
-/* 09may13abu
+/* 10may13abu
* (c) Software Lab. Alexander Burger
*/
@@ -489,13 +489,13 @@ function lisp(form, fun) {
var exe = [fun];
for (var i = 2; i < arguments.length; ++i)
- exe[i-1] = encodeURIComponent(arguments[i]);
+ exe[i-1] = (typeof arguments[i] === "number"? "+" : ".") + encodeURIComponent(arguments[i]);
return post(form, exe, null);
}
if (arguments.length > 2) {
- fun += "?" + encodeURIComponent(arguments[2]).replace(/-/,"%2D");
+ fun += "?" + lispVal(arguments[2]);
for (var i = 3; i < arguments.length; ++i)
- fun += "&" + encodeURIComponent(arguments[i]).replace(/-/,"%2D");
+ fun += "&" + lispVal(arguments[i]);
}
var req = new XMLHttpRequest();
try {req.open("GET", SesId + "!" + fun);}
@@ -508,3 +508,11 @@ function lisp(form, fun) {
setTimeout(function(){req.abort();}, 40); // No response expected
return false;
}
+
+function lispVal(x) {
+ if (typeof x === "number")
+ return "+" + x;
+ if (x.charAt(0) == "-")
+ return "%2D" + encodeURIComponent(x.substr(1));
+ return encodeURIComponent(x);
+}
diff --git a/lib/form.l b/lib/form.l
@@ -1,4 +1,4 @@
-# 09may13abu
+# 10may13abu
# (c) Software Lab. Alexander Burger
# *PRG *Top *Gui *Btn *Get *Got *Form *Evt *Lock *Spans
@@ -18,7 +18,7 @@
("+---" "-+--" "--+-" "---+" "--+-" "-+--" .) )
(de tzOffs (Min)
- (setq "*TZO" (* 60 (format Min))) )
+ (setq "*TZO" (* Min 60)) )
# Define GUI form
(de form ("Attr" . "Prg")
@@ -242,7 +242,12 @@
(when (and *Allow (not (idx *Allow Fun)))
(notAllowed Fun)
(throw "stop") )
- (apply (intern Fun) (mapcar cdr *JsArgs)) )
+ (apply (intern Fun)
+ (mapcar
+ '((X)
+ ((if (= "+" (car (setq X (chop (cdr X))))) format pack)
+ (cdr X) ) )
+ *JsArgs ) ) )
(for This (: gui)
(nond
((: id) (setq "*Chart" This))