Niffler.defnif

You're seeing just the macro defnif, go back to Niffler module for more information.
Link to this macro

defnif(name, inputs, outputs, list)

View Source (macro)

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 function
  • inputs - 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 or int64 - a signed 64-bit integer
  • uint64 - an unsigned 64-bit integer
  • double - 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>>)