mbed I/F binding for mruby
Dependents: mruby_mbed_web mirb_mbed
mbed-mruby
How to use
Class
include/mruby/class.h@1:8ccd1d494a4b, 2015-04-13 (annotated)
- Committer:
- mzta
- Date:
- Mon Apr 13 05:20:15 2015 +0000
- Revision:
- 1:8ccd1d494a4b
- Parent:
- 0:158c61bb030f
- code refactoring.; - add SPI, SPISlave, I2C class to mruby-mbed (Incomplete).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mzta | 0:158c61bb030f | 1 | /* |
mzta | 0:158c61bb030f | 2 | ** mruby/class.h - Class 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_CLASS_H |
mzta | 0:158c61bb030f | 8 | #define MRUBY_CLASS_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 | struct RClass { |
mzta | 0:158c61bb030f | 15 | MRB_OBJECT_HEADER; |
mzta | 0:158c61bb030f | 16 | struct iv_tbl *iv; |
mzta | 0:158c61bb030f | 17 | struct kh_mt *mt; |
mzta | 0:158c61bb030f | 18 | struct RClass *super; |
mzta | 0:158c61bb030f | 19 | }; |
mzta | 0:158c61bb030f | 20 | |
mzta | 0:158c61bb030f | 21 | #define mrb_class_ptr(v) ((struct RClass*)(mrb_ptr(v))) |
mzta | 0:158c61bb030f | 22 | #define RCLASS_SUPER(v) (((struct RClass*)(mrb_ptr(v)))->super) |
mzta | 0:158c61bb030f | 23 | #define RCLASS_IV_TBL(v) (((struct RClass*)(mrb_ptr(v)))->iv) |
mzta | 0:158c61bb030f | 24 | #define RCLASS_M_TBL(v) (((struct RClass*)(mrb_ptr(v)))->mt) |
mzta | 0:158c61bb030f | 25 | |
mzta | 0:158c61bb030f | 26 | static inline struct RClass* |
mzta | 0:158c61bb030f | 27 | mrb_class(mrb_state *mrb, mrb_value v) |
mzta | 0:158c61bb030f | 28 | { |
mzta | 0:158c61bb030f | 29 | switch (mrb_type(v)) { |
mzta | 0:158c61bb030f | 30 | case MRB_TT_FALSE: |
mzta | 0:158c61bb030f | 31 | if (mrb_fixnum(v)) |
mzta | 0:158c61bb030f | 32 | return mrb->false_class; |
mzta | 0:158c61bb030f | 33 | return mrb->nil_class; |
mzta | 0:158c61bb030f | 34 | case MRB_TT_TRUE: |
mzta | 0:158c61bb030f | 35 | return mrb->true_class; |
mzta | 0:158c61bb030f | 36 | case MRB_TT_SYMBOL: |
mzta | 0:158c61bb030f | 37 | return mrb->symbol_class; |
mzta | 0:158c61bb030f | 38 | case MRB_TT_FIXNUM: |
mzta | 0:158c61bb030f | 39 | return mrb->fixnum_class; |
mzta | 0:158c61bb030f | 40 | case MRB_TT_FLOAT: |
mzta | 0:158c61bb030f | 41 | return mrb->float_class; |
mzta | 0:158c61bb030f | 42 | case MRB_TT_CPTR: |
mzta | 0:158c61bb030f | 43 | return mrb->object_class; |
mzta | 0:158c61bb030f | 44 | case MRB_TT_ENV: |
mzta | 0:158c61bb030f | 45 | return NULL; |
mzta | 0:158c61bb030f | 46 | default: |
mzta | 0:158c61bb030f | 47 | return mrb_obj_ptr(v)->c; |
mzta | 0:158c61bb030f | 48 | } |
mzta | 0:158c61bb030f | 49 | } |
mzta | 0:158c61bb030f | 50 | |
mzta | 0:158c61bb030f | 51 | #define MRB_SET_INSTANCE_TT(c, tt) c->flags = ((c->flags & ~0xff) | (char)tt) |
mzta | 0:158c61bb030f | 52 | #define MRB_INSTANCE_TT(c) (enum mrb_vtype)(c->flags & 0xff) |
mzta | 0:158c61bb030f | 53 | |
mzta | 0:158c61bb030f | 54 | MRB_API struct RClass* mrb_define_class_id(mrb_state*, mrb_sym, struct RClass*); |
mzta | 0:158c61bb030f | 55 | MRB_API struct RClass* mrb_define_module_id(mrb_state*, mrb_sym); |
mzta | 0:158c61bb030f | 56 | MRB_API struct RClass *mrb_vm_define_class(mrb_state*, mrb_value, mrb_value, mrb_sym); |
mzta | 0:158c61bb030f | 57 | MRB_API struct RClass *mrb_vm_define_module(mrb_state*, mrb_value, mrb_sym); |
mzta | 0:158c61bb030f | 58 | MRB_API void mrb_define_method_vm(mrb_state*, struct RClass*, mrb_sym, mrb_value); |
mzta | 0:158c61bb030f | 59 | MRB_API void mrb_define_method_raw(mrb_state*, struct RClass*, mrb_sym, struct RProc *); |
mzta | 0:158c61bb030f | 60 | MRB_API void mrb_define_method_id(mrb_state *mrb, struct RClass *c, mrb_sym mid, mrb_func_t func, mrb_aspec aspec); |
mzta | 0:158c61bb030f | 61 | MRB_API void mrb_alias_method(mrb_state *mrb, struct RClass *c, mrb_sym a, mrb_sym b); |
mzta | 0:158c61bb030f | 62 | |
mzta | 0:158c61bb030f | 63 | MRB_API struct RClass *mrb_class_outer_module(mrb_state*, struct RClass *); |
mzta | 0:158c61bb030f | 64 | MRB_API struct RProc *mrb_method_search_vm(mrb_state*, struct RClass**, mrb_sym); |
mzta | 0:158c61bb030f | 65 | MRB_API struct RProc *mrb_method_search(mrb_state*, struct RClass*, mrb_sym); |
mzta | 0:158c61bb030f | 66 | |
mzta | 0:158c61bb030f | 67 | MRB_API struct RClass* mrb_class_real(struct RClass* cl); |
mzta | 0:158c61bb030f | 68 | |
mzta | 0:158c61bb030f | 69 | void mrb_gc_mark_mt(mrb_state*, struct RClass*); |
mzta | 0:158c61bb030f | 70 | size_t mrb_gc_mark_mt_size(mrb_state*, struct RClass*); |
mzta | 0:158c61bb030f | 71 | void mrb_gc_free_mt(mrb_state*, struct RClass*); |
mzta | 0:158c61bb030f | 72 | |
mzta | 0:158c61bb030f | 73 | #if defined(__cplusplus) |
mzta | 0:158c61bb030f | 74 | } /* extern "C" { */ |
mzta | 0:158c61bb030f | 75 | #endif |
mzta | 0:158c61bb030f | 76 | |
mzta | 0:158c61bb030f | 77 | #endif /* MRUBY_CLASS_H */ |
mzta | 0:158c61bb030f | 78 |