[erlang-questions] Including function in configuration file

Raimo Niskanen raimo+erlang-questions@REDACTED
Tue Jul 24 16:37:11 CEST 2018


On Mon, Jul 09, 2018 at 08:50:14PM +0100, Roger Lipscombe wrote:
> On 9 July 2018 at 20:16, Code Wiget <codewiget95@REDACTED> wrote:
> > 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?
> 
> Yes, but you _can_ come up with some other way to specify them in the
> configuration file, and then convert that to an actual function before
> you pass it to SSL options.
> 
> We have something like this in our code:
> 
> convert_ssl_opt({verify_opts, VerifyOpts}, Acc) ->
>     Opt = {verify_fun, {fun do_verify/3, VerifyOpts}},
>     [Opt | Acc];
> 
> ...which converts our invented 'verify_opts' into the required
> 'verify_fun', by using a do_verify function in the module that does
> the conversion.

I think that for this option it actuall works write an inline fun as in:
    Opt =
      {verify_fun,
       {fun (A, B, C) -> result end,
	VerifyOpts}}

(If this works) it creates a shell fun that is calls a precompiled fun in
the shell module that feeds the abstract code to the interpreter, so it is
much slower than a compiled fun.  But I think it works and suppose we will
not remove this (mis)feature.

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list