nitc: extract common app.nit annotations from Android
[nit.git] / lib / app / app_base.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2011-2014 Alexis Laferrière <alexis.laf@xymus.net>
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 module app_base is
18 new_annotation app_name
19 new_annotation app_namespace
20 new_annotation app_version
21 end
22
23 # App subclasses are cross-platform applications
24 #
25 # This class is redefed by plateform modules and so
26 # App can be specialized directly in the user app.
27 class App
28 protected init do end
29
30 # Starts the internal setup of graphical and other stuff
31 # Is called just before run
32 fun setup do end
33
34 # Main entry point of your application
35 fun run do end
36
37 # Prefix to all log messages, used by `log_error`, `log_warning` and `log_info`.
38 fun log_prefix: String do return "app.nit"
39
40 # Helper function for logging errors
41 fun log_error(msg: String) do sys.stderr.write "{log_prefix} error: {msg}\n"
42
43 # Helper function for logging warnings
44 fun log_warning(msg: String) do sys.stderr.write "{log_prefix} warn: {msg}\n"
45
46 # Main init method for graphical stuff
47 # Is called when display is ready so graphical assets
48 # can be loaded at this time.
49 fun window_created do end
50
51 # Called before destroying the window
52 fun window_closing do end
53 end
54
55 protected fun app: App do return once new App
56 app.setup
57 app.run