[erlang-questions] Including function in configuration file

Code Wiget codewiget95@REDACTED
Mon Jul 9 23:06:28 CEST 2018


Hi Greg,

I sent this earlier, but it must not have gone through to everyone. I am trying to use special ssl options, for example:

{reuse_session, fun()} {next_protocols_advertised, [binary()]}
And
{user_lookup_fun, {fun(), term()}}, {psk_identity, string()}, {srp_identity, {string(), string()}}

Which require functions as input. This means that I can’t use a configuration file. Other members have suggested that I iterate over my environment variables and replace the “fun()” with a function at run time, rather than using a .config file. I think this is the most straightforward approach.

On Jul 9, 2018, 5:04 PM -0400, Grzegorz Junka <list1@REDACTED>, wrote:
>
> On 09/07/2018 18:57, Code Wiget 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.
> >
>
> If you defined a function in the config how would you verify if it's correct? You will need to compile it first. In Erlang you can compile any arbitrary file directly in your application, see this for an example:
> https://github.com/yoonka/migresia/blob/master/src/migresia_migrations.erl#L193
>
> So, theoretically, you could define a function as a string or binary in your config, then in the application write this to a file, compile into a binary (i.e. without writing the compiled module to a file) and then load directly from that binary and execute. But that sounds a bit weird and it's probably not what you need. Maybe you can just tell us what are you trying to accomplish?
>
> Best
> Greg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20180709/4d686229/attachment.htm>


More information about the erlang-questions mailing list