[erlang-questions] Loading code generated on the fly

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Sat Sep 27 22:54:10 CEST 2008


Robert Virding skrev:
> I am generating compiled erlang code on the fly without saving using 
> files (using LFE) and need to load the compiled binary into the system. 
> Now, I know how to do myself "by hand" but I would prefer to go through 
> the normal code loader to keep it all clean.
> 
> There is a call code:load_binary(Module, FileName, Binary) which seems 
> to do what I want, BUT there is this argument FileName. Now I don't 
> intend to save the module in a file unless I really have to as it seems 
> like a bit of unnecessary work to save it in a file just so I can load 
> it. What is the significance of the FileName argument and does it matter 
> what I set it to? Can I just call Module.beam and be done with?

I usually invent a path to signify that the module has been generated,
such as /lfe/generated/lfe.beam (or whatever).

That helps a bit when calling m() in the shell, or code:which(Module).

The FileName argument will have impact on these functions, as well
as e.g. code:lib_dir(Module).

This is what the 'code' man page says:

"Filename is only used by the code server to keep a record of from
which file the object code for Module comes. Accordingly, Filename
is not opened and read by the code server."

BR,
Ulf W



More information about the erlang-questions mailing list