aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/edit_mod.erl
blob: ae5be54445cf3b9f40739bad341a2b88330f182a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
%%%----------------------------------------------------------------------
%%% File    : edit_mod.erl
%%% Author  : Luke Gorrie <luke@bluetail.com>
%%% Purpose : Module loader
%%% Created : 28 Apr 2001 by Luke Gorrie <luke@bluetail.com>
%%%----------------------------------------------------------------------

-module(edit_mod).
-author('luke@bluetail.com').

-export([init/0, require/1, load/1]).

init() ->
    ets:new(?MODULE, [set, named_table, public]),
    ok.

require(Mod) ->
    case ets:lookup(?MODULE, Mod) of
	[] ->		% not initialised
	    case load(Mod) of
		ok ->
		    ok;
		{error, Reason} ->
		    {error, Reason}
	    end;
	[_] ->		% already initialised
	    ok
    end.

load(Mod) ->
    case catch Mod:mod_init() of
	ok ->
	    ets:insert(?MODULE, {Mod}),
	    ok;
	{'EXIT', {undef, _}} ->
	    {error, {missing, Mod, mod_init, 0}};
	{error, Reason} ->
	    {error, Reason};
	Unexpected ->
	    {error, {unexpected, Unexpected}}
    end.