Add erlang binding (#54)
* add erlang support * add erlang support for windows * add erlang ci for linux and windows
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
{application, ruapu,
|
||||
[{description, "ruapu erlang/otp binding"},
|
||||
{vsn, "0.1.0"},
|
||||
{registered, []},
|
||||
{applications,
|
||||
[kernel,
|
||||
stdlib
|
||||
]},
|
||||
{env,[]},
|
||||
{modules, []},
|
||||
|
||||
{licenses, ["MIT"]},
|
||||
{links, []}
|
||||
]}.
|
||||
@@ -0,0 +1,32 @@
|
||||
-module(ruapu).
|
||||
-export([rua/0, supports/1]).
|
||||
|
||||
-ifdef(TEST).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-endif.
|
||||
|
||||
%% @doc
|
||||
%%
|
||||
%% Get a list of supported features.
|
||||
-spec rua() -> {ok, [string()]} | {error, string()}.
|
||||
rua() ->
|
||||
ruapu_nif:rua().
|
||||
|
||||
%% @doc
|
||||
%%
|
||||
%% Check if a feature is supported.
|
||||
-spec supports(atom() | string() | binary()) -> boolean().
|
||||
supports(ISA) ->
|
||||
ruapu_nif:supports(ISA).
|
||||
|
||||
-ifdef(EUNIT).
|
||||
rua_test() ->
|
||||
?assertMatch({ok, _}, rua()).
|
||||
|
||||
supports_test() ->
|
||||
?assert(supports(<<"binary_non_exists_feature">>) =:= false),
|
||||
?assert(supports("string_non_exists_feature") =:= false),
|
||||
?assert(supports(atom_non_exists_feature) =:= false),
|
||||
{ok, Features} = rua(),
|
||||
?assert(lists:all(fun(Feature) -> supports(Feature) end, Features)).
|
||||
-endif.
|
||||
@@ -0,0 +1,30 @@
|
||||
-module(ruapu_nif).
|
||||
-export([supports/1, rua/0]).
|
||||
|
||||
-on_load(init/0).
|
||||
|
||||
-define(APPNAME, ruapu).
|
||||
-define(LIBNAME, ruapu_nif).
|
||||
|
||||
init() ->
|
||||
SoName = case code:priv_dir(?APPNAME) of
|
||||
{error, bad_name} ->
|
||||
case filelib:is_dir(filename:join(["..", priv])) of
|
||||
true ->
|
||||
filename:join(["..", priv, ?LIBNAME]);
|
||||
_ ->
|
||||
filename:join([priv, ?LIBNAME])
|
||||
end;
|
||||
Dir ->
|
||||
filename:join(Dir, ?LIBNAME)
|
||||
end,
|
||||
erlang:load_nif(SoName, 0).
|
||||
|
||||
not_loaded(Line) ->
|
||||
erlang:nif_error({not_loaded, [{module, ?MODULE}, {line, Line}]}).
|
||||
|
||||
supports(_ISA) ->
|
||||
not_loaded(?LINE).
|
||||
|
||||
rua() ->
|
||||
not_loaded(?LINE).
|
||||
Reference in New Issue
Block a user