[erlang-questions] Including function in configuration file

Code Wiget codewiget95@REDACTED
Mon Jul 9 21:16:56 CEST 2018


So, for the ssl options such as:
{reuse_session, fun()} {next_protocols_advertised, [binary()]}

{user_lookup_fun, {fun(), term()}}, {psk_identity, string()}, {srp_identity, {string(), string()}}

You have to manually set the configuration parameters, and cannot set them in a configuration file?


On Jul 9, 2018, 3:15 PM -0400, Roger Lipscombe <roger@REDACTED>, wrote:
> No. The '#Fun<stuff>' isn't really a thing; it's just how the function
> is printed in the shell.
>
> If you want to reference a function in a config file, it needs to be a
> real function, and you need to reference it by name. If you don't know
> which module it's implemented in, you'll need to specify that in your
> config file as well. Something like this:
>
> [
> {my_app,
> [
> {my_magic_func, {the_module, func_name}}
> ]}
> ].
>
> Then, in your code that reads the configuration value, you need to
> explicitly invoke the function with erlang:apply...
>
> {ok, {Module, Func}} = application:get_env(my_app, my_magic_func),
> erlang:apply(Module, Func, [Arg1, Arg2]) % calls
> the_module:func_name(Arg1, Arg2)
>
>
>
> On 9 July 2018 at 19:57, Code Wiget <codewiget95@REDACTED> wrote:
> > Hi,
> >
> > Say I want to include a function as an environment variable
> >
> > I can do this:
> >  application:set_env(App, Key, NewValue).
> >
> > Is there any way to do this from a .config file? Such as:
> >  [{my_app, [ {my_fun, #Fun<my_app.12.39472874>}]}]
> >
> > — this gives a compile error.
> >
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
> >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180709/217a9015/attachment.htm>


More information about the erlang-questions mailing list