Header: mruby/array.h

Overview

Array class

Function Summary collapse

Define Summary

#define MRUBY_ARRAY_H
#define MRB_ARY_EMBED_LEN_MAX
#define mrb_ary_ptr
#define mrb_ary_value
#define RARRAY
#define MRB_ARY_EMBED_MASK
#define ARY_EMBED_P
#define ARY_UNSET_EMBED_FLAG
#define ARY_EMBED_LEN
#define ARY_SET_EMBED_LEN
#define ARY_EMBED_PTR
#define ARY_LEN
#define ARY_PTR
#define RARRAY_LEN
#define RARRAY_PTR
#define ARY_SET_LEN
#define ARY_CAPA
#define MRB_ARY_SHARED
#define ARY_SHARED_P
#define ARY_SET_SHARED_FLAG
#define ARY_UNSET_SHARED_FLAG

Function Details

void mrb_ary_modify(mrb_state* , struct RArray* )

mrb_value mrb_ary_new_capa(mrb_state* , mrb_int )

mrb_value mrb_ary_new(mrb_state * mrb)

Initializes a new array.

Equivalent to:

 Array.new

Parameters:

  • mrb

    The mruby state reference.

Returns:

  • The initialized array.

mrb_value mrb_ary_new_from_values(mrb_state * mrb, mrb_int size, const mrb_value * vals)

Initializes a new array with initial values

Equivalent to:

 Array[value1, value2, ...]

Parameters:

  • mrb

    The mruby state reference.

  • size

    The numer of values.

  • vals

    The actual values.

Returns:

  • The initialized array.

mrb_value mrb_assoc_new(mrb_state * mrb, mrb_value car, mrb_value cdr)

Initializes a new array with two initial values

Equivalent to:

 Array[car, cdr]

Parameters:

  • mrb

    The mruby state reference.

  • car

    The first value.

  • cdr

    The second value.

Returns:

  • The initialized array.

void mrb_ary_concat(mrb_state * mrb, mrb_value self, mrb_value other)

Concatenate two arrays. The target array will be modified

Equivalent to: ary.concat(other)

Parameters:

  • mrb

    The mruby state reference.

  • self

    The target array.

  • other

    The array that will be concatenated to self.

mrb_value mrb_ary_splat(mrb_state * mrb, mrb_value value)

Create an array from the input. It tries calling to_a on the value. If value does not respond to that, it creates a new array with just this value.

Parameters:

  • mrb

    The mruby state reference.

  • value

    The value to change into an array.

Returns:

  • An array representation of value.

void mrb_ary_push(mrb_state * mrb, mrb_value array, mrb_value value)

Pushes value into array.

Equivalent to:

 ary << value

Parameters:

  • mrb

    The mruby state reference.

  • ary

    The array in which the value will be pushed

  • value

    The value to be pushed into array

mrb_value mrb_ary_pop(mrb_state * mrb, mrb_value ary)

Pops the last element from the array.

Equivalent to:

 ary.pop

Parameters:

  • mrb

    The mruby state reference.

  • ary

    The array from which the value will be popped.

Returns:

  • The popped value.

mrb_value mrb_ary_ref(mrb_state * mrb, mrb_value ary, mrb_int n)

Returns a reference to an element of the array on the given index.

Equivalent to:

 ary[n]

Parameters:

  • mrb

    The mruby state reference.

  • ary

    The target array.

  • n

    The array index being referenced

Returns:

  • The referenced value.

void mrb_ary_set(mrb_state * mrb, mrb_value ary, mrb_int n, mrb_value val)

Sets a value on an array at the given index

Equivalent to:

 ary[n] = val

Parameters:

  • mrb

    The mruby state reference.

  • ary

    The target array.

  • n

    The array index being referenced.

  • val

    The value being setted.

void mrb_ary_replace(mrb_state * mrb, mrb_value self, mrb_value other)

Replace the array with another array

Equivalent to:

 ary.replace(other)

Parameters:

  • mrb

    The mruby state reference

  • self

    The target array.

  • other

    The array to replace it with.

mrb_value mrb_ensure_array_type(mrb_state * mrb, mrb_value self)

mrb_value mrb_check_array_type(mrb_state * mrb, mrb_value self)

mrb_value mrb_ary_unshift(mrb_state * mrb, mrb_value self, mrb_value item)

Unshift an element into the array

Equivalent to:

ary.unshift(item)

Parameters:

  • mrb

    The mruby state reference.

  • self

    The target array.

  • item

    The item to unshift.

mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset)

Get nth element in the array

Equivalent to:

ary[offset]

Parameters:

  • ary

    The target array.

  • offset

    The element position (negative counts from the tail).

mrb_value mrb_ary_splice(mrb_state * mrb, mrb_value self, mrb_int head, mrb_int len, mrb_value rpl)

Replace subsequence of an array.

Equivalent to:

 ary.shift

Parameters:

  • mrb

    The mruby state reference.

  • self

    The array from which the value will be shifted.

  • head

    Beginning position of a replacement subsequence.

  • len

    Length of a replacement subsequence.

  • rpl

    The array of replacement elements.

Returns:

  • The receiver array.

mrb_value mrb_ary_shift(mrb_state * mrb, mrb_value self)

Shifts the first element from the array.

Equivalent to:

 ary.shift

Parameters:

  • mrb

    The mruby state reference.

  • self

    The array from which the value will be shifted.

Returns:

  • The shifted value.

mrb_value mrb_ary_clear(mrb_state * mrb, mrb_value self)

Removes all elements from the array

Equivalent to:

 ary.clear

Parameters:

  • mrb

    The mruby state reference.

  • self

    The target array.

Returns:

  • self

mrb_value mrb_ary_join(mrb_state * mrb, mrb_value ary, mrb_value sep)

Join the array elements together in a string

Equivalent to:

 ary.join(sep="")

Parameters:

  • mrb

    The mruby state reference.

  • ary

    The target array

  • sep

    The separater, can be NULL

mrb_value mrb_ary_resize(mrb_state * mrb, mrb_value ary, mrb_int new_len)

Update the capacity of the array

Parameters:

  • mrb

    The mruby state reference.

  • ary

    The target array.

  • new_len

    The new capacity of the array