Changeset 331 for EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/array.h
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-1.3.0
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/array.h
r321 r331 8 8 #define MRUBY_ARRAY_H 9 9 10 #include " mruby/common.h"10 #include "common.h" 11 11 12 12 /* … … 55 55 * 56 56 * @param mrb The mruby state reference. 57 * @return The initialized array 57 * @return The initialized array. 58 58 */ 59 59 MRB_API mrb_value mrb_ary_new(mrb_state *mrb); 60 60 61 /* 62 * Initializes a new array with initial values 63 * 64 * Equivalent to: 65 * 66 * Array[value1, value2, ...] 67 * 68 * @param mrb The mruby state reference. 69 * @param size The numer of values. 70 * @param vals The actual values. 71 * @return The initialized array. 72 */ 61 73 MRB_API mrb_value mrb_ary_new_from_values(mrb_state *mrb, mrb_int size, const mrb_value *vals); 74 75 /* 76 * Initializes a new array with two initial values 77 * 78 * Equivalent to: 79 * 80 * Array[car, cdr] 81 * 82 * @param mrb The mruby state reference. 83 * @param car The first value. 84 * @param cdr The second value. 85 * @return The initialized array. 86 */ 62 87 MRB_API mrb_value mrb_assoc_new(mrb_state *mrb, mrb_value car, mrb_value cdr); 63 MRB_API void mrb_ary_concat(mrb_state*, mrb_value, mrb_value); 64 MRB_API mrb_value mrb_ary_splat(mrb_state*, mrb_value); 88 89 /* 90 * Concatenate two arrays. The target array will be modified 91 * 92 * Equivalent to: 93 * ary.concat(other) 94 * 95 * @param mrb The mruby state reference. 96 * @param self The target array. 97 * @param other The array that will be concatenated to self. 98 */ 99 MRB_API void mrb_ary_concat(mrb_state *mrb, mrb_value self, mrb_value other); 100 101 /* 102 * Create an array from the input. It tries calling to_a on the 103 * value. If value does not respond to that, it creates a new 104 * array with just this value. 105 * 106 * @param mrb The mruby state reference. 107 * @param value The value to change into an array. 108 * @return An array representation of value. 109 */ 110 MRB_API mrb_value mrb_ary_splat(mrb_state *mrb, mrb_value value); 65 111 66 112 /* … … 85 131 * 86 132 * @param mrb The mruby state reference. 87 * @param ary The array from which the value will be pop ed.88 * @return The pop ed value.133 * @param ary The array from which the value will be popped. 134 * @return The popped value. 89 135 */ 90 136 MRB_API mrb_value mrb_ary_pop(mrb_state *mrb, mrb_value ary); … … 118 164 MRB_API void mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val); 119 165 120 MRB_API void mrb_ary_replace(mrb_state *mrb, mrb_value a, mrb_value b); 166 /* 167 * Replace the array with another array 168 * 169 * Equivalent to: 170 * 171 * ary.replace(other) 172 * 173 * @param mrb The mruby state reference 174 * @param self The target array. 175 * @param other The array to replace it with. 176 */ 177 MRB_API void mrb_ary_replace(mrb_state *mrb, mrb_value self, mrb_value other); 121 178 MRB_API mrb_value mrb_check_array_type(mrb_state *mrb, mrb_value self); 179 180 /* 181 * Unshift an element into an array 182 * 183 * Equivalent to: 184 * 185 * ary.unshift(item) 186 * 187 * @param mrb The mruby state reference. 188 * @param self The target array. 189 * @param item The item to unshift. 190 */ 122 191 MRB_API mrb_value mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item); 123 192 MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset); 193 194 /* 195 * Shifts the first element from the array. 196 * 197 * Equivalent to: 198 * 199 * ary.shift 200 * 201 * @param mrb The mruby state reference. 202 * @param self The array from which the value will be shifted. 203 * @return The shifted value. 204 */ 124 205 MRB_API mrb_value mrb_ary_shift(mrb_state *mrb, mrb_value self); 206 207 /* 208 * Removes all elements from this array 209 * 210 * Equivalent to: 211 * 212 * ary.clear 213 * 214 * @param mrb The mruby state reference. 215 * @param self The target array. 216 * @return self 217 */ 125 218 MRB_API mrb_value mrb_ary_clear(mrb_state *mrb, mrb_value self); 219 220 /* 221 * Join the array elements together in a string 222 * 223 * Equivalent to: 224 * 225 * ary.join(sep="") 226 * 227 * @param mrb The mruby state reference. 228 * @param ary The target array 229 * @param sep The separater, can be NULL 230 */ 126 231 MRB_API mrb_value mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep); 127 MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int len); 232 233 /* 234 * Update the capacity of the array 235 * 236 * @param mrb The mruby state reference. 237 * @param ary The target array. 238 * @param new_len The new capacity of the array 239 */ 240 MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int new_len); 128 241 129 242 static inline mrb_int … … 135 248 } 136 249 250 static inline mrb_value 251 ary_elt(mrb_value ary, mrb_int offset) 252 { 253 if (offset < 0 || RARRAY_LEN(ary) <= offset) { 254 return mrb_nil_value(); 255 } 256 return RARRAY_PTR(ary)[offset]; 257 } 258 137 259 MRB_END_DECL 138 260
Note:
See TracChangeset
for help on using the changeset viewer.