Niffler.defnif
You're seeing just the macro
defnif
, go back to Niffler module for more information.
Defines a new nif member method. To use defnif() import Niffler into
your module with use Niffler
.
defnif takes three parameters and a c-fragment function body:
name
- an atom, the name of the to be defined nif functioninputs
- a keyword list of the format[name: type]
outputs
- a keyword list of the format[name: type]
The inputs
and outputs
keyword lists take atom() as names and types.
The parameter names can be freely choosen* the currently supported
types are:
int
orint64
- a signed 64-bit integeruint64
- an unsigned 64-bit integerdouble
- a double (floating point number)binary
- an Elixir binary/string
defmodule Example do
use Niffler
defnif :count_zeros, [str: :binary], [ret: :int] do
"""
while($str.size--) {
if (*$str.data++ == 0) $ret++;
}
"""
end
end
{:ok, [2]} = Example.count_zeros(<<0,1,0>>)