Mojoler.Dsl.Box (mojoler v0.1.0)

Copy Markdown View Source

A generated resource whose step function is native/examples/box_user.mojo.

open/0 returns an opaque reference. The native object holds one signed integer, starting at 0. That field is not visible to Elixir.

Summary

Types

Opaque box handle. Inspects as a reference. The running total is native state.

Functions

Adds delta to the box and returns the new total.

Loads priv/native/libdsl_box.so.

Opens a box whose total is 0.

Types

box()

@type box() :: reference()

Opaque box handle. Inspects as a reference. The running total is native state.

Functions

bump(box, delta)

@spec bump(box(), integer()) :: integer()

Adds delta to the box and returns the new total.

box is a handle from open/0. delta is a signed integer. There is no optional argument. The native step is value + delta.

Raises

  • ArgumentError when box is not a box from this module, or delta is not an integer

Examples

iex> box = Mojoler.Dsl.Box.open()
iex> Mojoler.Dsl.Box.bump(box, 20)
20
iex> Mojoler.Dsl.Box.bump(box, 22)
42
iex> Mojoler.Dsl.Box.bump(:nope, 1)
** (ArgumentError) argument error

load_nif()

@spec load_nif() :: :ok | {:error, term()}

Loads priv/native/libdsl_box.so.

A second call returns {:error, {:reload, charlist}}.

Examples

iex> Mojoler.Dsl.Box.load_nif()
{:error, {:reload, ~c"NIF library already loaded (reload disallowed since OTP 20)."}}

open()

@spec open() :: box()

Opens a box whose total is 0.

Returns

A box/0.

Examples

iex> box = Mojoler.Dsl.Box.open()
iex> is_reference(box)
true