fixing argument passing to the callback

This commit is contained in:
Danny Yoo 2012-03-15 15:07:24 -04:00
parent 45ef3b21f9
commit 441c40d305
4 changed files with 38 additions and 21 deletions

View File

@ -1,6 +1,7 @@
#lang s-exp "../lang/base.rkt"
(require "../js/world.rkt"
"../js.rkt")
#lang s-exp "../../lang/base.rkt"
(require "../../js.rkt")
(require "../../js/world.rkt")
(provide on-geo)
@ -8,8 +9,10 @@
(js-function->procedure
"function(locationCallback) {
return navigator.geolocation.watchPosition(
function(evt) { locationCallback(plt.runtime.makeFloat(evt.latitude),
plt.runtime.makeFloat(evt.longitude)); })}"))
function(evt) {
var coords = evt.coords;
locationCallback(plt.runtime.makeFloat(coords.latitude),
plt.runtime.makeFloat(coords.longitude)); })}"))
(define shutdown-geo
(js-function->procedure

View File

@ -24,9 +24,12 @@
var enabled = false;
var fireEvent;
var sender = function(v) {
var sender = function() {
var args;
if (enabled) {
fireEvent(void(0), v);
args = Array.prototype.slice.call(arguments, 0);
args.unshift(void(0));
fireEvent.apply(void(0), args);
}
};
@ -75,11 +78,11 @@
var shutdownProcedure = wrapFunction(checkProcedure(M, 'make-world-event-handler', 1));
var eventSource = makeJsEventSource(setupProcedure, shutdownProcedure);
var makeHandler = makePrimitiveProcedure(
'make-js-world-event',
'world-event-handler',
1,
function(M) {
var onEvent = wrapFunction(checkProcedure(M, 'js-world-event-handler', 0));
return new EventHandler('js-world-event', eventSource, onEvent);
var onEvent = wrapFunction(checkProcedure(M, 'world-event-handler', 0));
return new EventHandler('world-event-handler', eventSource, onEvent);
});
finalizeClosureCall(M, makeHandler);
});

9
js/world/test-geo.rkt Normal file
View File

@ -0,0 +1,9 @@
#lang planet dyoo/whalesong
(require (planet dyoo/whalesong/web-world)
"geo.rkt")
(big-bang (list 'undefined 'undefined)
(on-geo (lambda (w v lat lng)
(list lat lng))))

View File

@ -16,7 +16,7 @@
var makeList = plt.baselib.lists.makeList;
var makePair = plt.baselib.lists.makePair;
var makeSymbol = plt.baselib.symbols.makeSymbol;
var isArityMatching = plt.baselib.arity.isArityMatching;
// EventHandler and the other classes here will be defined below.
@ -1258,7 +1258,7 @@
// Apply all the events on the queue, call toDraw, and then stop.
// If the world ever satisfies stopWhen, stop immediately and quit.
var nextEvent;
var data;
var args;
var racketWorldCallback;
var mockView;
dispatchingEvents = true;
@ -1271,9 +1271,8 @@
mockView = mockView.updateFocus(nextEvent.who.id);
}
// FIXME: deal with event data here
racketWorldCallback = nextEvent.handler.racketWorldCallback;
data = nextEvent.data[0];
args = nextEvent.data.slice(0);
var onGoodWorldUpdate =
function(newWorld) {
world = newWorld;
@ -1290,19 +1289,22 @@
},
fail);
};
if (plt.baselib.arity.isArityMatching(racketWorldCallback.racketArity, 3)) {
if (isArityMatching(racketWorldCallback.racketArity, 1)) {
racketWorldCallback(internalCall,
world,
onGoodWorldUpdate,
fail);
} else if (isArityMatching(racketWorldCallback.racketArity, 2)) {
racketWorldCallback(internalCall,
world,
mockView,
data,
onGoodWorldUpdate,
fail);
} else {
racketWorldCallback(internalCall,
world,
mockView,
onGoodWorldUpdate,
fail);
args = ([internalCall, world, mockView]
.concat(args)
.concat([onGoodWorldUpdate, fail]));
racketWorldCallback.apply(null, args);
}
} else {
dispatchingEvents = false;