From eb6d50cbbe36c4cb16b5f0155941155177e4121f Mon Sep 17 00:00:00 2001 From: Max Rottenkolber Date: Fri, 4 Nov 2016 14:32:02 +0100 Subject: [PATCH 1/5] core.config: add `configure' callback to apps. --- src/core/config.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/config.lua b/src/core/config.lua index 16492c1a1c..3c8fd53630 100644 --- a/src/core/config.lua +++ b/src/core/config.lua @@ -32,7 +32,11 @@ function app (config, name, class, arg) if status then arg = result else error("failed to configure '"..name.."': "..result) end end - config.apps[name] = { class = class, arg = arg} + if class.configure then + class:configure(config, name, arg) + else + config.apps[name] = { class = class, arg = arg} + end end -- API: Add a link to the configuration. From e43ffcd500d06c474e6fd00aa21ae85bb9a98ae8 Mon Sep 17 00:00:00 2001 From: Max Rottenkolber Date: Thu, 17 Nov 2016 16:45:38 +0100 Subject: [PATCH 2/5] core.app: document `configure' callback. --- src/README.md | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/README.md b/src/README.md index ea61b8466d..33c3b94d29 100644 --- a/src/README.md +++ b/src/README.md @@ -85,10 +85,20 @@ unimplemented are marked as "optional". — Method **myapp:new** *arg* -*Required*. Create an instance of the app with a given argument *arg*. -`Myapp:new` must return an instance of the app. The handling of *arg* is -up to the app but it is encouraged to use `core.config`'s `parse_app_arg` -to parse *arg*. +*Required*. Create an instance of the app with a given argument *arg*. The +`new` method must return an instance of the app. The handling of *arg* is up to +the app but it is encouraged to use `core.config`'s `parse_app_arg` to parse +*arg*. + + +— Method **myapp:configure** *configuration*, *name*, *arg* + +*Optional*. If this method is defined the `new` method is not ignored and not +required, and when *myapp* is configured using `config.app` this method is +called instead of instantiating *myapp* using `new`. The `configure` method is +called with the *configuration*, *name*, and *arg* given to `config.app`, and +is intended to be used to add arbitrary apps and links to *configuration* using +`config.app` and `config.link`. — Field **myapp.input** From 85f57e702875bf0b79c0c08cfa56b8c4e2004d99 Mon Sep 17 00:00:00 2001 From: Max Rottenkolber Date: Thu, 17 Nov 2016 16:56:08 +0100 Subject: [PATCH 3/5] core.app: add selftest for configure callback. --- src/core/app.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/core/app.lua b/src/core/app.lua index 50f05d991a..acd1619421 100644 --- a/src/core/app.lua +++ b/src/core/app.lua @@ -526,4 +526,11 @@ function selftest () assert(app_table.app3 == orig_app3) -- should be the same main({duration = 4, report = {showapps = true}}) assert(app_table.app3 ~= orig_app3) -- should be restarted + local c_macro, MacroApp = config.new(), {} + local args, got = {configuration=c_macro, name="macroTest", arg=42}, {} + function MacroApp:configure (c, name, arg) + got.configuration, got.name, got.arg = c, name, arg + end + config.app(c_macro, args.name, MacroApp, args.arg) + assert(lib.equeal(args, got), "configure callback broken") end From 02c077cf3d4f9fff6e1c3a4ffad0f651b31848fa Mon Sep 17 00:00:00 2001 From: Max Rottenkolber Date: Fri, 18 Nov 2016 12:01:43 +0100 Subject: [PATCH 4/5] core.app: fix typo in configure callback selftest. --- src/core/app.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/app.lua b/src/core/app.lua index acd1619421..a6f0c77b51 100644 --- a/src/core/app.lua +++ b/src/core/app.lua @@ -532,5 +532,5 @@ function selftest () got.configuration, got.name, got.arg = c, name, arg end config.app(c_macro, args.name, MacroApp, args.arg) - assert(lib.equeal(args, got), "configure callback broken") + assert(lib.equal(args, got), "configure callback broken") end From 73c76e761ac58b99dd3be37a6d2ea66420c528d5 Mon Sep 17 00:00:00 2001 From: Max Rottenkolber Date: Fri, 18 Nov 2016 12:10:38 +0100 Subject: [PATCH 5/5] core.app: minor fixes in app API documentation. --- src/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/README.md b/src/README.md index 33c3b94d29..86b3e4c07d 100644 --- a/src/README.md +++ b/src/README.md @@ -85,15 +85,15 @@ unimplemented are marked as "optional". — Method **myapp:new** *arg* -*Required*. Create an instance of the app with a given argument *arg*. The -`new` method must return an instance of the app. The handling of *arg* is up to +*Required*. Create an instance of *myapp* with a given argument *arg*. The +`new` method must return an instance of *myapp*. The handling of *arg* is up to the app but it is encouraged to use `core.config`'s `parse_app_arg` to parse *arg*. — Method **myapp:configure** *configuration*, *name*, *arg* -*Optional*. If this method is defined the `new` method is not ignored and not +*Optional*. If this method is defined the `new` method is ignored and not required, and when *myapp* is configured using `config.app` this method is called instead of instantiating *myapp* using `new`. The `configure` method is called with the *configuration*, *name*, and *arg* given to `config.app`, and