瀏覽代碼

Modernize basicnif template code

pull/3/head
Tuncer Ayaz 14 年之前
父節點
當前提交
734d30f96e
共有 1 個文件被更改,包括 16 次插入10 次删除
  1. +16
    -10
      priv/templates/basicnif.erl

+ 16
- 10
priv/templates/basicnif.erl 查看文件

@ -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
{error, bad_name} ->
SoName = filename:join("../priv", {{module}});
Dir ->
SoName = filename:join(Dir, {{module}})
end,
erlang:load_nif(SoName, 0).
PrivDir = case code:priv_dir(?MODULE) of
{error, bad_name} ->
EbinDir = filename:dirname(code:which(?MODULE)),
AppPath = filename:dirname(EbinDir),
filename:join(AppPath, "priv");
Path ->
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.

Loading…
取消
儲存