|
1 | 1 | #|
|
2 | 2 | LambdaNative - a cross-platform Scheme framework
|
3 |
| -Copyright (c) 2009-2016, University of British Columbia |
| 3 | +Copyright (c) 2009-2020, University of British Columbia |
4 | 4 | All rights reserved.
|
5 | 5 |
|
6 | 6 | Redistribution and use in source and binary forms, with or
|
@@ -75,6 +75,7 @@ end-of-c-declare
|
75 | 75 | (define EVENT_BUTTON3DOWN ((c-lambda () int "___result = EVENT_BUTTON3DOWN;")))
|
76 | 76 | (define EVENT_CLOSE ((c-lambda () int "___result = EVENT_CLOSE;")))
|
77 | 77 | (define EVENT_REDRAW ((c-lambda () int "___result = EVENT_REDRAW;")))
|
| 78 | +(define EVENT_JSCM_RESULT ((c-lambda () int "___result = EVENT_JSCM_RESULT;"))) |
78 | 79 | (define EVENT_INIT ((c-lambda () int "___result = EVENT_INIT;")))
|
79 | 80 | (define EVENT_TERMINATE ((c-lambda () int "___result = EVENT_TERMINATE;")))
|
80 | 81 | (define EVENT_BATTERY ((c-lambda () int "___result = EVENT_BATTERY;")))
|
@@ -148,9 +149,35 @@ end-of-c-declare
|
148 | 149 | (define (event-push t x y)
|
149 | 150 | (set! event:fifo (append event:fifo (list (list t x y)))))
|
150 | 151 | (define (event-pop)
|
151 |
| - (if (fx> (length event:fifo) 0) |
152 |
| - (let ((ret (car event:fifo))) |
153 |
| - (set! event:fifo (cdr event:fifo)) ret) #f)) |
| 152 | + (if (null? event:fifo) |
| 153 | + #f |
| 154 | + (let ((ret (car event:fifo))) |
| 155 | + (set! event:fifo (cdr event:fifo)) |
| 156 | + ret))) |
| 157 | + |
| 158 | +(define on-jscm-result |
| 159 | + (let ((mux (make-mutex 'on-jscm-result))) |
| 160 | + (mutex-specific-set! mux #f) |
| 161 | + (lambda args |
| 162 | + (cond |
| 163 | + ((null? args) |
| 164 | + ;; return receiver procedure |
| 165 | + (lambda (t x y) |
| 166 | + (let ((proc (mutex-specific mux))) |
| 167 | + (when proc |
| 168 | + (mutex-specific-set! mux #f) |
| 169 | + (proc t x y) |
| 170 | + (mutex-unlock! mux))))) |
| 171 | + ;; (<test> => <recipient>) is a clause, where if <test> evaluates to #t, |
| 172 | + ;; <recipient> is evaluated as (<recipient> <result of test>) |
| 173 | + ((let ((proc (car args))) (and (procedure? proc) proc)) |
| 174 | + => |
| 175 | + ;;set 'proc' as inner receiver |
| 176 | + (lambda (proc) |
| 177 | + (mutex-lock! mux) |
| 178 | + (mutex-specific-set! mux proc) |
| 179 | + #t)) |
| 180 | + (else (log-error "illegal arguments" on-jscm-result args)))))) |
154 | 181 |
|
155 | 182 | (define eventloop:mutex (make-mutex 'eventloop))
|
156 | 183 | (define (eventloop:grab!) (mutex-lock! eventloop:mutex))
|
@@ -180,6 +207,8 @@ end-of-c-declare
|
180 | 207 | (hook:event t (if app:scale? (fix (* app:xscale x)) x)
|
181 | 208 | (if app:scale? (fix (* app:yscale y)) y))
|
182 | 209 | )
|
| 210 | + ((fx= t EVENT_JSCM_RESULT) |
| 211 | + ((on-jscm-result) t x y)) |
183 | 212 | ((fx= t EVENT_INIT)
|
184 | 213 | ;; prevent multiple inits
|
185 | 214 | (if app:mustinit (begin
|
|
0 commit comments