calog/examples/scripts/libraries/timerInMyBasic.bas

20 lines
639 B
QBasic

' Timer callbacks in my-basic. calog's my-basic fork (vendor/ourbasic) makes def/lambda
' routines first-class values, so a BASIC script can hand a callback to a native just like
' every other engine. Here a def is armed on a repeating timer; it counts ticks in a
' global, and after the third tick cancels its own timer and ends the run.
' run: bin/calog examples/scripts/libraries/timerInMyBasic.bas
n = 0
tid = 0
def tick()
n = n + 1
calogPrint("my-basic tick", n)
if n >= 3 then
timerCancel(tid)
calogExit(0)
endif
enddef
tid = timerEvery(80, tick)
calogPrint("my-basic armed a repeating timer with a def callback")