From: Jean Privat Date: Mon, 9 Jun 2014 14:03:20 +0000 (-0400) Subject: lib/app: move stuff from `App::init` to a new function, `App::sepup` X-Git-Tag: v0.6.6~42^2 X-Git-Url: http://nitlanguage.org lib/app: move stuff from `App::init` to a new function, `App::sepup` Because of the `app` method is a `once new App`, the result of the `new` is not stored until the `new` returns. Therefore, suggests to doing stuff during the construction of App might invoke something that use `app` as a global symbol, thus causing an infinite recursions. --- diff --git a/lib/android/native_app_glue.nit b/lib/android/native_app_glue.nit index 8b622f3..6090450 100644 --- a/lib/android/native_app_glue.nit +++ b/lib/android/native_app_glue.nit @@ -123,7 +123,7 @@ extern class NativeActivity in "Java" `{ android.app.NativeActivity `} end redef class App - redef init + redef fun setup do var native_app_glue = native_app_glue native_app_glue.user_data = self diff --git a/lib/app.nit b/lib/app.nit index bd74daa..3e2d737 100644 --- a/lib/app.nit +++ b/lib/app.nit @@ -27,6 +27,10 @@ module app class App protected init do end + # Starts the internal setup of graphical and other stuff + # Is called just before run + protected fun setup do end + # Main entry point of your application fun run do end @@ -49,4 +53,5 @@ class App end protected fun app: App do return once new App +app.setup app.run diff --git a/lib/mnit_linux/linux_app.nit b/lib/mnit_linux/linux_app.nit index 5534d5a..4b599ed 100644 --- a/lib/mnit_linux/linux_app.nit +++ b/lib/mnit_linux/linux_app.nit @@ -29,7 +29,7 @@ redef class App redef type D: Opengles1Display redef type I: Opengles1Image - redef init + redef fun setup do display = new Opengles1Display diff --git a/lib/mnit_linux/linux_assets.nit b/lib/mnit_linux/linux_assets.nit index 9247991..2c75bb5 100644 --- a/lib/mnit_linux/linux_assets.nit +++ b/lib/mnit_linux/linux_assets.nit @@ -22,7 +22,7 @@ import linux_app redef class App var assets_dir: String - redef init + redef fun setup do assets_dir = sys.program_name.dirname + "/../assets/"