variable renaming
This commit is contained in:
parent
3315d65f43
commit
ce0e1259b5
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
|
|
||||||
;; Let's attach the send-event function to a toplevel function on the window.
|
;; Let's attach the send-event function to a toplevel function on the window.
|
||||||
(void ((js-function (js-eval "function(send) { $(window).bind('message', function(e) { send(e.originalEvent.data); })}"))
|
(void ((js-function->procedure "function(send) { $(window).bind('message', function(e) { send(e.originalEvent.data); })}")
|
||||||
send))
|
send))
|
||||||
;; js-function lifts JavaScript functions to regular function we can call.
|
;; js-function lifts JavaScript functions to regular function we can call.
|
||||||
|
|
||||||
|
|
31
js.rkt
31
js.rkt
|
@ -1,3 +1,32 @@
|
||||||
#lang s-exp "lang/base.rkt"
|
#lang s-exp "lang/base.rkt"
|
||||||
(require "js/main.rkt")
|
(require "js/main.rkt")
|
||||||
(provide (all-from-out "js/main.rkt"))
|
(provide [except-out (all-from-out "js/main.rkt")
|
||||||
|
js-function->procedure
|
||||||
|
js-async-function->procedure]
|
||||||
|
[rename-out [-js-function->procedure js-function->procedure]
|
||||||
|
[-js-async-function->procedure js-async-function->procedure]]
|
||||||
|
js-function?)
|
||||||
|
|
||||||
|
(define raw-js-function?
|
||||||
|
(js-function->procedure (js-eval "function(x) { return typeof(x) === 'function'}")))
|
||||||
|
|
||||||
|
(define (js-function? x)
|
||||||
|
(raw-js-function? x))
|
||||||
|
|
||||||
|
(define (-js-function->procedure x)
|
||||||
|
(cond
|
||||||
|
[(string? x)
|
||||||
|
(js-function->procedure (js-eval x))]
|
||||||
|
[(js-function? x)
|
||||||
|
(js-function->procedure x)]
|
||||||
|
[else
|
||||||
|
(raise-type-error 'js-function->procedure "js-function or string" x)]))
|
||||||
|
|
||||||
|
(define (-js-async-function->procedure x)
|
||||||
|
(cond
|
||||||
|
[(string? x)
|
||||||
|
(js-async-function->procedure (js-eval x))]
|
||||||
|
[(js-function? x)
|
||||||
|
(js-async-function->procedure x)]
|
||||||
|
[else
|
||||||
|
(raise-type-error 'js-async-function->procedure "js-function or string" x)]))
|
|
@ -159,9 +159,9 @@
|
||||||
|
|
||||||
|
|
||||||
// Lift JavaScript functions to Whalesong functions.
|
// Lift JavaScript functions to Whalesong functions.
|
||||||
EXPORTS['js-function'] =
|
EXPORTS['js-function->procedure'] =
|
||||||
makePrimitiveProcedure(
|
makePrimitiveProcedure(
|
||||||
'js-function',
|
'js-function->procedure',
|
||||||
1,
|
1,
|
||||||
function(MACHINE) {
|
function(MACHINE) {
|
||||||
var f = checkJSFunction(MACHINE, 'js function', 0);
|
var f = checkJSFunction(MACHINE, 'js function', 0);
|
||||||
|
@ -177,9 +177,9 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPORTS['js-async-function'] =
|
EXPORTS['js-async-function->procedure'] =
|
||||||
makePrimitiveProcedure(
|
makePrimitiveProcedure(
|
||||||
'js-async-function',
|
'js-async-function->procedure',
|
||||||
1,
|
1,
|
||||||
function(MACHINE) {
|
function(MACHINE) {
|
||||||
var f = checkJSFunction(MACHINE, 'js function', 0);
|
var f = checkJSFunction(MACHINE, 'js function', 0);
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
call-method
|
call-method
|
||||||
$
|
$
|
||||||
|
|
||||||
js-function
|
js-function->procedure
|
||||||
js-async-function
|
js-async-function->procedure
|
||||||
|
|
||||||
window
|
window
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,8 @@
|
||||||
|
|
||||||
load-script
|
load-script
|
||||||
|
|
||||||
js-function
|
js-function->procedure
|
||||||
js-async-function
|
js-async-function->procedure
|
||||||
)
|
)
|
||||||
|
|
||||||
(define (alert x)
|
(define (alert x)
|
||||||
|
@ -103,8 +103,8 @@
|
||||||
(error 'load-script "Not available outside JavaScript context."))
|
(error 'load-script "Not available outside JavaScript context."))
|
||||||
|
|
||||||
|
|
||||||
(define (js-function f)
|
(define (js-function->procedure f)
|
||||||
(error 'js-function "Not available outside JavaScript context."))
|
(error 'js-function->procedure "Not available outside JavaScript context."))
|
||||||
|
|
||||||
(define (js-async-function f)
|
(define (js-async-function->procedure f)
|
||||||
(error 'js-async-function "Not available outside JavaScript context."))
|
(error 'js-async-function->procedure "Not available outside JavaScript context."))
|
|
@ -1,6 +1,3 @@
|
||||||
#lang s-exp "../../lang/js/js.rkt"
|
#lang s-exp "../../lang/base.rkt"
|
||||||
(require "../../web-world.rkt")
|
(require "make-js-world-event.rkt")
|
||||||
(declare-implementation
|
(provide (all-from-out "make-js-world-event.rkt"))
|
||||||
#:racket "racket-impl.rkt"
|
|
||||||
#:javascript ("js-impl.js")
|
|
||||||
#:provided-values (make-js-world-event))
|
|
||||||
|
|
6
js/world/make-js-world-event.rkt
Normal file
6
js/world/make-js-world-event.rkt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#lang s-exp "../../lang/js/js.rkt"
|
||||||
|
(require "../../web-world.rkt")
|
||||||
|
(declare-implementation
|
||||||
|
#:racket "racket-impl.rkt"
|
||||||
|
#:javascript ("js-impl.js")
|
||||||
|
#:provided-values (make-js-world-event))
|
|
@ -15,9 +15,10 @@
|
||||||
|
|
||||||
|
|
||||||
;; Let's attach the send-event function to a toplevel function on the window.
|
;; Let's attach the send-event function to a toplevel function on the window.
|
||||||
(void ((js-function (js-eval "function(x) { window.sendTheTick = x; }"))
|
(void ((js-function->procedure (js-eval "function(x) { window.sendTheTick = x; }"))
|
||||||
send-event))
|
send-event))
|
||||||
;; js-function lifts JavaScript functions to regular function we can call.
|
;; js-function->procedure lifts JavaScript functions to regular
|
||||||
|
;; procedures that we can call.
|
||||||
|
|
||||||
|
|
||||||
(define (tick w v)
|
(define (tick w v)
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
(require (planet dyoo/whalesong/js))
|
(require (planet dyoo/whalesong/js))
|
||||||
|
|
||||||
(define js-plus
|
(define js-plus
|
||||||
(js-function (js-eval "function(x, y) { return x + y; }")))
|
(js-function->procedure "function(x, y) { return x + y; }"))
|
||||||
|
|
||||||
(define js-minus
|
(define js-minus
|
||||||
(js-function (js-eval "function(x, y) { return x - y; }")))
|
(js-function->procedure "function(x, y) { return x - y; }"))
|
||||||
|
|
||||||
(define sleep
|
(define sleep
|
||||||
(js-async-function (js-eval "function(success, fail, n) { setTimeout(success, n) }")))
|
(js-async-function->procedure"function(success, fail, n) { setTimeout(success, n) }"))
|
||||||
|
|
||||||
|
|
||||||
"plus: " (js-plus 3 4)
|
"plus: " (js-plus 3 4)
|
||||||
|
@ -25,5 +25,5 @@
|
||||||
;; I need exception handling...
|
;; I need exception handling...
|
||||||
;;
|
;;
|
||||||
;(define i-should-fail
|
;(define i-should-fail
|
||||||
; (js-async-function (js-eval "function(success, fail) { fail('I should fail'); }")))
|
; (js-async-function->procedure "function(success, fail) { fail('I should fail'); }"))
|
||||||
;(i-should-fail)
|
;(i-should-fail)
|
||||||
|
|
|
@ -7,4 +7,4 @@
|
||||||
(provide version)
|
(provide version)
|
||||||
(: version String)
|
(: version String)
|
||||||
|
|
||||||
(define version "1.221")
|
(define version "1.222")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user