moontalk/server/eventloop-server-experiment/eventhandlers.4th
Emil Williams 7721b77c93
update
2024-02-03 17:37:01 +00:00

27 lines
872 B
Forth

32 constant MAX_EVENTHANDLERS
0
cell +field eventhandler.eventid
cell +field eventhandler.xt
constant /EVENTHANDLER
MAX_EVENTHANDLERS /EVENTHANDLER * constant EVENTHANDLERS_SIZE
create eventhandlers EVENTHANDLERS_SIZE allot
eventhandlers EVENTHANDLERS_SIZE erase
: (translate) ( index-u -- eventhandler-addr ) /EVENTHANDLER * eventhandlers + ;
: (eventhandler-set?) ( eventhandler-addr -- flag ) eventhandler.xt @ 0<> ;
: (set-eventhandler) ( handler-xt eventid-u eventhandler-addr -- )
tuck eventhandler.eventid ! eventhandler.xt ! ;
: eventhandlers.remove ( index-u -- )
(translate) /EVENTHANDLER erase ;
: eventhandlers.append ( handler-xt eventid-u -- index-u )
MAX_EVENTHANDLERS 0 DO
I (translate) dup (eventhandler-set?) invert IF
(set-eventhandler) UNLOOP EXIT
ELSE
drop
THEN
LOOP
true abort" no free eventhandler slots!" ;