changing the success continuation passed to js-function->procedure so it can return multiple values back easily.
This commit is contained in:
parent
5a35785c7a
commit
ebc3191676
|
@ -1,8 +1,14 @@
|
|||
#lang planet dyoo/whalesong
|
||||
|
||||
;; 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
|
||||
|
@ -15,7 +21,7 @@ function(success, fail, key, sensor) {
|
|||
window[callbackName] = function() {
|
||||
delete(window[callbackName]);
|
||||
// At this point, we know the API has been instantiated ok.
|
||||
success();
|
||||
success(plt.runtime.VOID);
|
||||
};
|
||||
|
||||
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))
|
||||
(unless (boolean? 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.
|
||||
(printf "Loading google maps api\n");
|
||||
(initialize-google-maps-api! "AIzaSyCRKQNI_nbyyN1286cssEy3taKj5IZcHN8" #f)
|
||||
|
|
|
@ -191,6 +191,8 @@
|
|||
for (i = 0; i < MACHINE.a ; i = i+1) {
|
||||
args.push(MACHINE.e[MACHINE.e.length - 1 - i]);
|
||||
}
|
||||
MACHINE.e.length -= MACHINE.a;
|
||||
MACHINE.a = 0;
|
||||
return plt.runtime.PAUSE(
|
||||
function(restart) {
|
||||
var onFail = function(e) {
|
||||
|
@ -204,9 +206,22 @@
|
|||
});
|
||||
};
|
||||
var onSuccess = function(v) {
|
||||
restart(function(MACHINE) {
|
||||
plt.runtime.finalizeClosureCall(MACHINE, v);
|
||||
});
|
||||
// Common case, return single argument
|
||||
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(onSuccess);
|
||||
|
|
Loading…
Reference in New Issue
Block a user