mirror of
https://github.com/vishapoberon/compiler.git
synced 2026-04-06 06:22:25 +00:00
parent
31c5b31dae
commit
7d5cab1590
3 changed files with 66 additions and 0 deletions
7
src/test/events/README.md
Normal file
7
src/test/events/README.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
**events example in oberon**
|
||||
|
||||
Just a simple example which helps to explain how events are implemented, what is callback procedure, and how easy it is.
|
||||
|
||||
Some languages simplify programmer's work, hide details, so that it's not obvious to him what's going on when he defines it's own OnSomething function.
|
||||
|
||||
Callbacks are common when dealing with gui events like OnClick but they can be used with any events. I guess code is simple enough, it doesn't need explanation.
|
||||
55
src/test/events/clb.Mod
Normal file
55
src/test/events/clb.Mod
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
MODULE clb;
|
||||
|
||||
IMPORT Console;
|
||||
|
||||
TYPE OnSomething = PROCEDURE (x, y : INTEGER);
|
||||
|
||||
PROCEDURE ProcessEvents(x, y : INTEGER; onsomething : OnSomething);
|
||||
|
||||
BEGIN
|
||||
|
||||
IF onsomething # NIL THEN onsomething(x, y)
|
||||
ELSE
|
||||
Console.String("didn't happen"); Console.Ln
|
||||
END;
|
||||
|
||||
END ProcessEvents;
|
||||
|
||||
|
||||
PROCEDURE OnEvent(x, y : INTEGER);
|
||||
|
||||
BEGIN
|
||||
|
||||
Console.String("event happened"); Console.Ln
|
||||
|
||||
END OnEvent;
|
||||
|
||||
PROCEDURE OnEvent2(x, y : INTEGER);
|
||||
|
||||
BEGIN
|
||||
|
||||
Console.String("happened"); Console.Ln
|
||||
|
||||
END OnEvent2;
|
||||
|
||||
PROCEDURE Something;
|
||||
VAR onsmth : OnSomething;
|
||||
|
||||
BEGIN
|
||||
|
||||
onsmth := NIL;
|
||||
ProcessEvents(0, 0, onsmth);
|
||||
|
||||
onsmth := OnEvent;
|
||||
ProcessEvents(0, 0, onsmth);
|
||||
|
||||
END Something;
|
||||
|
||||
BEGIN
|
||||
Something;
|
||||
(*
|
||||
ProcessEvents(0, 0, NIL);
|
||||
ProcessEvents(0, 0, OnEvent);
|
||||
ProcessEvents(0, 0, OnEvent2);
|
||||
*)
|
||||
END clb.
|
||||
4
src/test/events/makefile
Normal file
4
src/test/events/makefile
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
|
||||
all:
|
||||
/opt/voc/bin/voc -M clb.Mod
|
||||
Loading…
Add table
Add a link
Reference in a new issue