Erts/Otp onLoad

Tony Rogvall tony@REDACTED
Wed May 19 08:23:24 CEST 2004


Hello list!

I have a small suggestion for new functionality in the Erlang/Erts 
[Otp] system.
I would like to see that a call to a function called M:onLoad() (or 
something) was
made by the runtime system when a module M that exports such a function 
was loaded
and before any other code was executed (not a requirement).

Ideally the M:onLoad function [in a new version of M] should be called 
before the new version
of M was "registered". In the current state of the Erlang system this 
is not possible since only
the latest version of a module M will be accessible for remote calls.

Typical use will be to have modules to register functionality when 
loaded, think of
plug and play or plugins etc. (linux kernel drivers also have  this)

possibly a function M:unLoad could be called when the module M is 
unloaded
(garbage collected) or replaced with a newer version.


Having Module as separate objects (wanted feature) then:

	{ok, Bin} = file:read_file("M.beam"),
	Mid = binary_to_term(Bin),
	catch apply(Mid, onLoad, []),          %% note call to unregistered 
module!
	register_module(m, Mid).



Regards

/Tony






More information about the erlang-questions mailing list