Mojoler.Nif (mojoler v0.1.0)

Copy Markdown View Source

Shared path and load bookkeeping.

:erlang.load_nif/2 must run inside the module named by the NIF entry. This module builds that path and records a successful load. It does not call :erlang.load_nif/2.

Summary

Types

File name of a built library, including the .so suffix OTP appends.

Functions

Returns whether basename was marked loaded in this VM.

Records that stem <> ".so" has been loaded in this VM.

Returns the load path for priv/native/<stem>.

Types

library()

@type library() :: String.t()

File name of a built library, including the .so suffix OTP appends.

Examples

"libpoc.so"

Functions

loaded?(basename)

@spec loaded?(library()) :: boolean()

Returns whether basename was marked loaded in this VM.

basename includes the .so suffix. An unknown name is false. There is no optional argument.

Examples

iex> Mojoler.Nif.loaded?("not-a-library.so")
false

mark!(stem)

@spec mark!(String.t()) :: :ok

Records that stem <> ".so" has been loaded in this VM.

stem is the file name without .so. The compiler reads this mark and will not replace a library this VM has already mapped.

Returns

:ok.

Examples

iex> Mojoler.Nif.mark!("doctest-mark")
:ok
iex> Mojoler.Nif.loaded?("doctest-mark.so")
true

path(stem)

@spec path(String.t()) :: charlist()

Returns the load path for priv/native/<stem>.

stem is the file name without .so. OTP appends .so on Darwin and Linux. There is no optional argument.

Returns

A charlist. :erlang.load_nif/2 accepts that form.

Examples

iex> path = Mojoler.Nif.path("libpoc")
iex> List.ends_with?(path, ~c"libpoc")
true