Skip to content

Commit 7e6fcb3

Browse files
0-8-15mgorges
authored andcommitted
EVENTLOOP: Add support for a new jScheme related event (#387)
Allocates a single event number (126) and dispatches it to a possibly registered receiver - or is ignored as before.
1 parent 20b33a1 commit 7e6fcb3

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

LNCONFIG.h.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
LambdaNative - a cross-platform Scheme framework
3-
Copyright (c) 2009-2013, University of British Columbia
3+
Copyright (c) 2009-2020, University of British Columbia
44
All rights reserved.
55
66
Redistribution and use in source and binary forms, with or
@@ -64,6 +64,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6464

6565
#define EVENT_DEBUG 64
6666

67+
#define EVENT_JSCM_RESULT 126
6768
#define EVENT_INIT 127
6869
#define EVENT_TERMINATE 128
6970

modules/eventloop/eventloop.scm

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#|
22
LambdaNative - a cross-platform Scheme framework
3-
Copyright (c) 2009-2016, University of British Columbia
3+
Copyright (c) 2009-2020, University of British Columbia
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or
@@ -75,6 +75,7 @@ end-of-c-declare
7575
(define EVENT_BUTTON3DOWN ((c-lambda () int "___result = EVENT_BUTTON3DOWN;")))
7676
(define EVENT_CLOSE ((c-lambda () int "___result = EVENT_CLOSE;")))
7777
(define EVENT_REDRAW ((c-lambda () int "___result = EVENT_REDRAW;")))
78+
(define EVENT_JSCM_RESULT ((c-lambda () int "___result = EVENT_JSCM_RESULT;")))
7879
(define EVENT_INIT ((c-lambda () int "___result = EVENT_INIT;")))
7980
(define EVENT_TERMINATE ((c-lambda () int "___result = EVENT_TERMINATE;")))
8081
(define EVENT_BATTERY ((c-lambda () int "___result = EVENT_BATTERY;")))
@@ -148,9 +149,35 @@ end-of-c-declare
148149
(define (event-push t x y)
149150
(set! event:fifo (append event:fifo (list (list t x y)))))
150151
(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))))))
154181

155182
(define eventloop:mutex (make-mutex 'eventloop))
156183
(define (eventloop:grab!) (mutex-lock! eventloop:mutex))
@@ -180,6 +207,8 @@ end-of-c-declare
180207
(hook:event t (if app:scale? (fix (* app:xscale x)) x)
181208
(if app:scale? (fix (* app:yscale y)) y))
182209
)
210+
((fx= t EVENT_JSCM_RESULT)
211+
((on-jscm-result) t x y))
183212
((fx= t EVENT_INIT)
184213
;; prevent multiple inits
185214
(if app:mustinit (begin

0 commit comments

Comments
 (0)