mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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`.
This commit is contained in:
@@ -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);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user