changing the success continuation passed to js-function->procedure so it can return multiple values back easily.

This commit is contained in:
Danny Yoo 2012-03-19 21:50:59 -04:00
parent 5a35785c7a
commit ebc3191676
2 changed files with 33 additions and 6 deletions

View File

@ -1,8 +1,14 @@
#lang planet dyoo/whalesong #lang planet dyoo/whalesong
;; A simple binding to Google Maps. ;; A simple binding to Google Maps.
;;
;; Some of this comes from:
;;
;; https://developers.google.com/maps/documentation/javascript/tutorial
;;
(require (planet dyoo/whalesong/js)) (require (planet dyoo/whalesong/js)
(planet dyoo/whalesong/js/world))
;; initialize-google-maps-api!: string boolean -> void ;; initialize-google-maps-api!: string boolean -> void
@ -15,7 +21,7 @@ function(success, fail, key, sensor) {
window[callbackName] = function() { window[callbackName] = function() {
delete(window[callbackName]); delete(window[callbackName]);
// At this point, we know the API has been instantiated ok. // At this point, we know the API has been instantiated ok.
success(); success(plt.runtime.VOID);
}; };
var script = document.createElement("script"); var script = document.createElement("script");
@ -48,6 +54,11 @@ EOF
)) ))
;; We can listen to certain events, like click.
;; https://developers.google.com/maps/documentation/javascript/events
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -56,11 +67,12 @@ EOF
(raise-type-error 'initialize-google-maps-api! "string" 0 key)) (raise-type-error 'initialize-google-maps-api! "string" 0 key))
(unless (boolean? sensor) (unless (boolean? sensor)
(raise-type-error 'initialize-google-maps-api! "boolean" 1 sensor)) (raise-type-error 'initialize-google-maps-api! "boolean" 1 sensor))
(void (raw-initialize-google-maps-api! key sensor))) (raw-initialize-google-maps-api! key sensor))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; This is dyoo's API key. ;; This is dyoo's API key.
(printf "Loading google maps api\n"); (printf "Loading google maps api\n");
(initialize-google-maps-api! "AIzaSyCRKQNI_nbyyN1286cssEy3taKj5IZcHN8" #f) (initialize-google-maps-api! "AIzaSyCRKQNI_nbyyN1286cssEy3taKj5IZcHN8" #f)

View File

@ -191,6 +191,8 @@
for (i = 0; i < MACHINE.a ; i = i+1) { for (i = 0; i < MACHINE.a ; i = i+1) {
args.push(MACHINE.e[MACHINE.e.length - 1 - i]); args.push(MACHINE.e[MACHINE.e.length - 1 - i]);
} }
MACHINE.e.length -= MACHINE.a;
MACHINE.a = 0;
return plt.runtime.PAUSE( return plt.runtime.PAUSE(
function(restart) { function(restart) {
var onFail = function(e) { var onFail = function(e) {
@ -204,9 +206,22 @@
}); });
}; };
var onSuccess = function(v) { var onSuccess = function(v) {
restart(function(MACHINE) { // Common case, return single argument
plt.runtime.finalizeClosureCall(MACHINE, v); if (arguments.length === 1) {
}); restart(function(MACHINE) {
MACHINE.a = 0;
plt.runtime.finalizeClosureCall(MACHINE, v);
});
} else {
// General case: return multiple arguments
var args = Array.prototype.slice.call(arguments, 0);
args.unshift(MACHINE);
restart(function(MACHINE) {
MACHINE.a = 0;
plt.runtime.finalizeClosureCall.apply(
null, args);
});
}
} }
args.unshift(onFail); args.unshift(onFail);
args.unshift(onSuccess); args.unshift(onSuccess);