diff options
| author | dearblue <[email protected]> | 2021-06-20 11:08:28 +0900 |
|---|---|---|
| committer | dearblue <[email protected]> | 2021-06-20 11:08:28 +0900 |
| commit | cc95e346fd9cc26bb6fc3fb7b1082d7d011ef664 (patch) | |
| tree | 63d154c95d0936ed7d22dd5294a6777a74b35d64 /include/mruby.h | |
| parent | f678620a436aa015f9252858aa00112256ab0668 (diff) | |
| download | mruby-cc95e346fd9cc26bb6fc3fb7b1082d7d011ef664.tar.gz mruby-cc95e346fd9cc26bb6fc3fb7b1082d7d011ef664.zip | |
Added `MRB_OBJ_ALLOC()` macro that does not require a cast
The `MRB_OBJ_ALLOC()` macro function returns a pointer of the type corresponding to the constant literal defined in `enum mrb_vtype`.
Diffstat (limited to 'include/mruby.h')
| -rw-r--r-- | include/mruby.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/include/mruby.h b/include/mruby.h index 02be8300f..93aab5672 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -1131,6 +1131,17 @@ MRB_API void *mrb_malloc_simple(mrb_state*, size_t); /* return NULL if no memor MRB_API struct RBasic *mrb_obj_alloc(mrb_state*, enum mrb_vtype, struct RClass*); MRB_API void mrb_free(mrb_state*, void*); +/** + * Allocates a Ruby object that matches the constant literal defined in + * `enum mrb_vtype` and returns a pointer to the corresponding C type. + * + * @param mrb The current mruby state + * @param tt The constant literal of `enum mrb_vtype` + * @param klass A Class object + * @return Reference to the newly created object + */ +#define MRB_OBJ_ALLOC(mrb, tt, klass) ((MRB_VTYPE_TYPEOF(tt)*)mrb_obj_alloc(mrb, tt, klass)) + MRB_API mrb_value mrb_str_new(mrb_state *mrb, const char *p, size_t len); /** |
