source: EcnlProtoTool/trunk/mruby-1.2.0/include/mruby/array.h@ 270

Last change on this file since 270 was 270, checked in by coas-nagasima, 7 years ago

mruby版ECNLプロトタイピング・ツールを追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-chdr
File size: 3.5 KB
Line 
1/*
2** mruby/array.h - Array class
3**
4** See Copyright Notice in mruby.h
5*/
6
7#ifndef MRUBY_ARRAY_H
8#define MRUBY_ARRAY_H
9
10#include "mruby/common.h"
11
12/*
13 * Array class
14 */
15MRB_BEGIN_DECL
16
17
18typedef struct mrb_shared_array {
19 int refcnt;
20 mrb_int len;
21 mrb_value *ptr;
22} mrb_shared_array;
23
24struct RArray {
25 MRB_OBJECT_HEADER;
26 mrb_int len;
27 union {
28 mrb_int capa;
29 mrb_shared_array *shared;
30 } aux;
31 mrb_value *ptr;
32};
33
34#define mrb_ary_ptr(v) ((struct RArray*)(mrb_ptr(v)))
35#define mrb_ary_value(p) mrb_obj_value((void*)(p))
36#define RARRAY(v) ((struct RArray*)(mrb_ptr(v)))
37
38#define RARRAY_LEN(a) (RARRAY(a)->len)
39#define RARRAY_PTR(a) ((const mrb_value*)RARRAY(a)->ptr)
40#define MRB_ARY_SHARED 256
41#define ARY_SHARED_P(a) ((a)->flags & MRB_ARY_SHARED)
42#define ARY_SET_SHARED_FLAG(a) ((a)->flags |= MRB_ARY_SHARED)
43#define ARY_UNSET_SHARED_FLAG(a) ((a)->flags &= ~MRB_ARY_SHARED)
44
45void mrb_ary_decref(mrb_state*, mrb_shared_array*);
46MRB_API void mrb_ary_modify(mrb_state*, struct RArray*);
47MRB_API mrb_value mrb_ary_new_capa(mrb_state*, mrb_int);
48
49/*
50 * Initializes a new array.
51 *
52 * Equivalent to:
53 *
54 * Array.new
55 *
56 * @param mrb The mruby state reference.
57 * @return The initialized array
58 */
59MRB_API mrb_value mrb_ary_new(mrb_state *mrb);
60
61MRB_API mrb_value mrb_ary_new_from_values(mrb_state *mrb, mrb_int size, const mrb_value *vals);
62MRB_API mrb_value mrb_assoc_new(mrb_state *mrb, mrb_value car, mrb_value cdr);
63MRB_API void mrb_ary_concat(mrb_state*, mrb_value, mrb_value);
64MRB_API mrb_value mrb_ary_splat(mrb_state*, mrb_value);
65
66/*
67 * Pushes value into array.
68 *
69 * Equivalent to:
70 *
71 * ary << value
72 *
73 * @param mrb The mruby state reference.
74 * @param ary The array in which the value will be pushed
75 * @param value The value to be pushed into array
76 */
77MRB_API void mrb_ary_push(mrb_state *mrb, mrb_value array, mrb_value value);
78
79/*
80 * Pops the last element from the array.
81 *
82 * Equivalent to:
83 *
84 * ary.pop
85 *
86 * @param mrb The mruby state reference.
87 * @param ary The array from which the value will be poped.
88 * @return The poped value.
89 */
90MRB_API mrb_value mrb_ary_pop(mrb_state *mrb, mrb_value ary);
91
92/*
93 * Returns a reference to an element of the array on the given index.
94 *
95 * Equivalent to:
96 *
97 * ary[n]
98 *
99 * @param mrb The mruby state reference.
100 * @param ary The target array.
101 * @param n The array index being referenced
102 * @return The referenced value.
103 */
104MRB_API mrb_value mrb_ary_ref(mrb_state *mrb, mrb_value ary, mrb_int n);
105
106/*
107 * Sets a value on an array at the given index
108 *
109 * Equivalent to:
110 *
111 * ary[n] = val
112 *
113 * @param mrb The mruby state reference.
114 * @param ary The target array.
115 * @param n The array index being referenced.
116 * @param val The value being setted.
117 */
118MRB_API void mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val);
119
120MRB_API void mrb_ary_replace(mrb_state *mrb, mrb_value a, mrb_value b);
121MRB_API mrb_value mrb_check_array_type(mrb_state *mrb, mrb_value self);
122MRB_API mrb_value mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item);
123MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset);
124MRB_API mrb_value mrb_ary_shift(mrb_state *mrb, mrb_value self);
125MRB_API mrb_value mrb_ary_clear(mrb_state *mrb, mrb_value self);
126MRB_API mrb_value mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep);
127MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int len);
128
129static inline mrb_int
130mrb_ary_len(mrb_state *mrb, mrb_value ary)
131{
132 (void)mrb;
133 mrb_assert(mrb_array_p(ary));
134 return RARRAY_LEN(ary);
135}
136
137MRB_END_DECL
138
139#endif /* MRUBY_ARRAY_H */
Note: See TracBrowser for help on using the repository browser.