mbed I/F binding for mruby

Dependents:   mruby_mbed_web mirb_mbed

mbed-mruby

How to use

Class

Committer:
mzta
Date:
Wed Mar 25 17:36:16 2015 +0000
Revision:
0:158c61bb030f
mirb_mbed initial commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mzta 0:158c61bb030f 1 /*
mzta 0:158c61bb030f 2 ** mruby/array.h - Array class
mzta 0:158c61bb030f 3 **
mzta 0:158c61bb030f 4 ** See Copyright Notice in mruby.h
mzta 0:158c61bb030f 5 */
mzta 0:158c61bb030f 6
mzta 0:158c61bb030f 7 #ifndef MRUBY_ARRAY_H
mzta 0:158c61bb030f 8 #define MRUBY_ARRAY_H
mzta 0:158c61bb030f 9
mzta 0:158c61bb030f 10 #if defined(__cplusplus)
mzta 0:158c61bb030f 11 extern "C" {
mzta 0:158c61bb030f 12 #endif
mzta 0:158c61bb030f 13
mzta 0:158c61bb030f 14 typedef struct mrb_shared_array {
mzta 0:158c61bb030f 15 int refcnt;
mzta 0:158c61bb030f 16 mrb_int len;
mzta 0:158c61bb030f 17 mrb_value *ptr;
mzta 0:158c61bb030f 18 } mrb_shared_array;
mzta 0:158c61bb030f 19
mzta 0:158c61bb030f 20 struct RArray {
mzta 0:158c61bb030f 21 MRB_OBJECT_HEADER;
mzta 0:158c61bb030f 22 mrb_int len;
mzta 0:158c61bb030f 23 union {
mzta 0:158c61bb030f 24 mrb_int capa;
mzta 0:158c61bb030f 25 mrb_shared_array *shared;
mzta 0:158c61bb030f 26 } aux;
mzta 0:158c61bb030f 27 mrb_value *ptr;
mzta 0:158c61bb030f 28 };
mzta 0:158c61bb030f 29
mzta 0:158c61bb030f 30 #define mrb_ary_ptr(v) ((struct RArray*)(mrb_ptr(v)))
mzta 0:158c61bb030f 31 #define mrb_ary_value(p) mrb_obj_value((void*)(p))
mzta 0:158c61bb030f 32 #define RARRAY(v) ((struct RArray*)(mrb_ptr(v)))
mzta 0:158c61bb030f 33
mzta 0:158c61bb030f 34 #define RARRAY_LEN(a) (RARRAY(a)->len)
mzta 0:158c61bb030f 35 #define RARRAY_PTR(a) ((const mrb_value*)RARRAY(a)->ptr)
mzta 0:158c61bb030f 36 #define MRB_ARY_SHARED 256
mzta 0:158c61bb030f 37 #define ARY_SHARED_P(a) ((a)->flags & MRB_ARY_SHARED)
mzta 0:158c61bb030f 38 #define ARY_SET_SHARED_FLAG(a) ((a)->flags |= MRB_ARY_SHARED)
mzta 0:158c61bb030f 39 #define ARY_UNSET_SHARED_FLAG(a) ((a)->flags &= ~MRB_ARY_SHARED)
mzta 0:158c61bb030f 40
mzta 0:158c61bb030f 41 void mrb_ary_decref(mrb_state*, mrb_shared_array*);
mzta 0:158c61bb030f 42 MRB_API void mrb_ary_modify(mrb_state*, struct RArray*);
mzta 0:158c61bb030f 43 MRB_API mrb_value mrb_ary_new_capa(mrb_state*, mrb_int);
mzta 0:158c61bb030f 44 MRB_API mrb_value mrb_ary_new(mrb_state *mrb);
mzta 0:158c61bb030f 45 MRB_API mrb_value mrb_ary_new_from_values(mrb_state *mrb, mrb_int size, const mrb_value *vals);
mzta 0:158c61bb030f 46 MRB_API mrb_value mrb_assoc_new(mrb_state *mrb, mrb_value car, mrb_value cdr);
mzta 0:158c61bb030f 47 MRB_API void mrb_ary_concat(mrb_state*, mrb_value, mrb_value);
mzta 0:158c61bb030f 48 MRB_API mrb_value mrb_ary_splat(mrb_state*, mrb_value);
mzta 0:158c61bb030f 49 MRB_API void mrb_ary_push(mrb_state*, mrb_value, mrb_value);
mzta 0:158c61bb030f 50 MRB_API mrb_value mrb_ary_pop(mrb_state *mrb, mrb_value ary);
mzta 0:158c61bb030f 51 MRB_API mrb_value mrb_ary_ref(mrb_state *mrb, mrb_value ary, mrb_int n);
mzta 0:158c61bb030f 52 MRB_API void mrb_ary_set(mrb_state *mrb, mrb_value ary, mrb_int n, mrb_value val);
mzta 0:158c61bb030f 53 MRB_API void mrb_ary_replace(mrb_state *mrb, mrb_value a, mrb_value b);
mzta 0:158c61bb030f 54 MRB_API mrb_value mrb_check_array_type(mrb_state *mrb, mrb_value self);
mzta 0:158c61bb030f 55 MRB_API mrb_value mrb_ary_unshift(mrb_state *mrb, mrb_value self, mrb_value item);
mzta 0:158c61bb030f 56 MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset);
mzta 0:158c61bb030f 57 MRB_API mrb_value mrb_ary_shift(mrb_state *mrb, mrb_value self);
mzta 0:158c61bb030f 58 MRB_API mrb_value mrb_ary_clear(mrb_state *mrb, mrb_value self);
mzta 0:158c61bb030f 59 MRB_API mrb_value mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep);
mzta 0:158c61bb030f 60 MRB_API mrb_value mrb_ary_resize(mrb_state *mrb, mrb_value ary, mrb_int len);
mzta 0:158c61bb030f 61
mzta 0:158c61bb030f 62 static inline mrb_int
mzta 0:158c61bb030f 63 mrb_ary_len(mrb_state *mrb, mrb_value ary)
mzta 0:158c61bb030f 64 {
mzta 0:158c61bb030f 65 (void)mrb;
mzta 0:158c61bb030f 66 mrb_assert(mrb_array_p(ary));
mzta 0:158c61bb030f 67 return RARRAY_LEN(ary);
mzta 0:158c61bb030f 68 }
mzta 0:158c61bb030f 69
mzta 0:158c61bb030f 70 #if defined(__cplusplus)
mzta 0:158c61bb030f 71 } /* extern "C" { */
mzta 0:158c61bb030f 72 #endif
mzta 0:158c61bb030f 73
mzta 0:158c61bb030f 74 #endif /* MRUBY_ARRAY_H */
mzta 0:158c61bb030f 75