mbed I/F binding for mruby

Dependents:   mruby_mbed_web mirb_mbed

mbed-mruby

How to use

Class

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?

UserRevisionLine numberNew contents of line
mzta 0:158c61bb030f 1 /*
mzta 0:158c61bb030f 2 ** mruby/hash.h - Hash 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_HASH_H
mzta 0:158c61bb030f 8 #define MRUBY_HASH_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 RHash {
mzta 0:158c61bb030f 15 MRB_OBJECT_HEADER;
mzta 0:158c61bb030f 16 struct iv_tbl *iv;
mzta 0:158c61bb030f 17 struct kh_ht *ht;
mzta 0:158c61bb030f 18 };
mzta 0:158c61bb030f 19
mzta 0:158c61bb030f 20 #define mrb_hash_ptr(v) ((struct RHash*)(mrb_ptr(v)))
mzta 0:158c61bb030f 21 #define mrb_hash_value(p) mrb_obj_value((void*)(p))
mzta 0:158c61bb030f 22
mzta 0:158c61bb030f 23 MRB_API mrb_value mrb_hash_new_capa(mrb_state*, int);
mzta 0:158c61bb030f 24 MRB_API mrb_value mrb_hash_new(mrb_state *mrb);
mzta 0:158c61bb030f 25
mzta 0:158c61bb030f 26 MRB_API void mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val);
mzta 0:158c61bb030f 27 MRB_API mrb_value mrb_hash_get(mrb_state *mrb, mrb_value hash, mrb_value key);
mzta 0:158c61bb030f 28 MRB_API mrb_value mrb_hash_fetch(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value def);
mzta 0:158c61bb030f 29 MRB_API mrb_value mrb_hash_delete_key(mrb_state *mrb, mrb_value hash, mrb_value key);
mzta 0:158c61bb030f 30 MRB_API mrb_value mrb_hash_keys(mrb_state *mrb, mrb_value hash);
mzta 0:158c61bb030f 31 MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash);
mzta 0:158c61bb030f 32 MRB_API mrb_value mrb_hash_empty_p(mrb_state *mrb, mrb_value self);
mzta 0:158c61bb030f 33 MRB_API mrb_value mrb_hash_clear(mrb_state *mrb, mrb_value hash);
mzta 0:158c61bb030f 34
mzta 0:158c61bb030f 35 /* RHASH_TBL allocates st_table if not available. */
mzta 0:158c61bb030f 36 #define RHASH(obj) ((struct RHash*)(mrb_ptr(obj)))
mzta 0:158c61bb030f 37 #define RHASH_TBL(h) (RHASH(h)->ht)
mzta 0:158c61bb030f 38 #define RHASH_IFNONE(h) mrb_iv_get(mrb, (h), mrb_intern_lit(mrb, "ifnone"))
mzta 0:158c61bb030f 39 #define RHASH_PROCDEFAULT(h) RHASH_IFNONE(h)
mzta 0:158c61bb030f 40 MRB_API struct kh_ht * mrb_hash_tbl(mrb_state *mrb, mrb_value hash);
mzta 0:158c61bb030f 41
mzta 0:158c61bb030f 42 #define MRB_HASH_PROC_DEFAULT 256
mzta 0:158c61bb030f 43 #define MRB_RHASH_PROCDEFAULT_P(h) (RHASH(h)->flags & MRB_HASH_PROC_DEFAULT)
mzta 0:158c61bb030f 44
mzta 0:158c61bb030f 45 /* GC functions */
mzta 0:158c61bb030f 46 void mrb_gc_mark_hash(mrb_state*, struct RHash*);
mzta 0:158c61bb030f 47 size_t mrb_gc_mark_hash_size(mrb_state*, struct RHash*);
mzta 0:158c61bb030f 48 void mrb_gc_free_hash(mrb_state*, struct RHash*);
mzta 0:158c61bb030f 49
mzta 0:158c61bb030f 50 #if defined(__cplusplus)
mzta 0:158c61bb030f 51 } /* extern "C" { */
mzta 0:158c61bb030f 52 #endif
mzta 0:158c61bb030f 53
mzta 0:158c61bb030f 54 #endif /* MRUBY_HASH_H */
mzta 0:158c61bb030f 55