1
0
Fork 0
mirror of https://github.com/correl/rebar.git synced 2025-04-06 17:00:16 -09:00

Modernize basicnif template code

This commit is contained in:
Tuncer Ayaz 2011-07-17 18:38:33 +02:00
parent 4e0ab4065f
commit 734d30f96e

View file

@ -5,24 +5,30 @@
-on_load(init/0). -on_load(init/0).
-define(nif_stub, nif_stub_error(?LINE)).
nif_stub_error(Line) ->
erlang:nif_error({nif_not_loaded,module,?MODULE,line,Line}).
-ifdef(TEST). -ifdef(TEST).
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-endif. -endif.
init() -> init() ->
case code:priv_dir({{module}}) of PrivDir = case code:priv_dir(?MODULE) of
{error, bad_name} -> {error, bad_name} ->
SoName = filename:join("../priv", {{module}}); EbinDir = filename:dirname(code:which(?MODULE)),
Dir -> AppPath = filename:dirname(EbinDir),
SoName = filename:join(Dir, {{module}}) filename:join(AppPath, "priv");
end, Path ->
erlang:load_nif(SoName, 0). Path
end,
erlang:load_nif(filename:join(PrivDir, ?MODULE), 0).
new() -> new() ->
"NIF library not loaded". ?nif_stub.
myfunction(Ref) -> myfunction(Ref) ->
"NIF library not loaded". ?nif_stub.
%% =================================================================== %% ===================================================================
%% EUnit tests %% EUnit tests
@ -31,6 +37,6 @@ myfunction(Ref) ->
basic_test() -> basic_test() ->
{ok, Ref} = new(), {ok, Ref} = new(),
ok = myfunction(Ref). ?assertEqual(ok, myfunction(Ref)).
-endif. -endif.