In this chapter you'll see that it's possible to have a complete WIMP program running in less than 10 lines. That looks promising doesn't it?
The first little steps...
The first thing we have to do is initialise the library. Ceylon needs to know the name of the program and the path of the message file. This can be done using this function:
The first argument,
Demo1, is the name of the application. The second argument is the path of the messagefile. Because our program will be very simple, we will use the default set of messages provided by Ceylon.
Where the action takes place
After the program has been initialised, we have to wait for things to happen. Remember, the program does not control the action; the user does. So this is where we enter the event loop:
This function takes care of all events, and takes corresponding action. The function will only return when the program finishes. Ah, now you think this can't happen, because we have written no code for that? And besides, there is no iconbar menu to quit the program! However, applications can also be killed from the taskmanager. And precisely that is handled by Ceylon automatically.
So now the application has apparently ended, all that rests it proper finishing of the program:
Completing the program
All that is left is adding some includes for the functions used and binding together the above statements. It's wise to put "
ceylon:" in the include statement to avoid name clashing with other libraries. You can leave them out if you only use OSLib and Ceylon, because between the two libraries, there are no duplicate names. So now, we end up with the following complete program:
Didn't I tell you? A complete, working program in less than 10 lines of code! Ok, its functionality is rather limited, but I'm sure it's a hell of a lot better than the usual, boring, "Hello World"... B.T.W. this program has full protection agains fatal errors like "Address exception", "Division by zero" and more. Even some commercial applications don't provide this service!