Merge: nitx: add hierarchy lookup commands
[nit.git] / examples / callback_chimpanze.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2013 Matthieu Lucas <lucasmatthieu@gmail.com>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # This sample has been implemented to show you how simple is it to relay
18 # native callbacks from C to a Nit program.
19 module callback_chimpanze
20
21 import callback_monkey
22
23 class Chimpanze
24 super MonkeyActionCallable
25
26 fun create
27 do
28 var monkey = new Monkey
29 print "Hum, I'm sleeping ..."
30
31 # Invoking method which will take some time to compute, and
32 # will be back in woke_up method with information.
33 # - Callback method defined in MonkeyActionCallable Interface
34 monkey.woke_up_action(self, "Hey, I'm awake.")
35 end
36
37 # Inherit callback method, defined by MonkeyActionCallable interface
38 # - Back of woke_up_action method
39 redef fun woke_up(sender:Monkey, message:Object)
40 do
41 print message
42 end
43 end
44
45 var m = new Chimpanze
46 m.create