3939
4040/**
4141 * @file mruby.h
42- * @brief Main header of mruby C API. Include this first.
4342 * @defgroup mruby MRuby C API
4443 * @{
4544 */
@@ -57,11 +56,13 @@ struct mrb_irep;
5756struct mrb_state ;
5857
5958/**
60- * Function pointer type of custom allocator used in mrb_open_allocf.
59+ * Function pointer type of custom allocator used in @ref mrb_open_allocf.
6160 *
6261 * The function pointing it must behave similarly as realloc except:
6362 * - If ptr is NULL it must allocate new space.
6463 * - If s is NULL, ptr must be freed.
64+ *
65+ * See @ref mrb_default_allocf for the default implementation.
6566 */
6667typedef void * (* mrb_allocf ) (struct mrb_state * mrb , void * , size_t , void * ud );
6768
@@ -205,18 +206,6 @@ typedef struct mrb_state {
205206 mrb_int atexit_stack_len ;
206207} mrb_state ;
207208
208- #if __STDC_VERSION__ >= 201112L
209- # define mrb_noreturn _Noreturn
210- #elif defined __GNUC__ && !defined __STRICT_ANSI__
211- # define mrb_noreturn __attribute__((noreturn))
212- # define mrb_deprecated __attribute__((deprecated))
213- #elif defined _MSC_VER
214- # define mrb_noreturn __declspec(noreturn)
215- # define mrb_deprecated __declspec(deprecated)
216- #else
217- # define mrb_noreturn
218- # define mrb_deprecated
219- #endif
220209
221210typedef mrb_value (* mrb_func_t )(mrb_state * mrb , mrb_value );
222211
@@ -278,8 +267,29 @@ MRB_API void mrb_define_module_function(mrb_state*, struct RClass*, const char*,
278267MRB_API void mrb_define_const (mrb_state * , struct RClass * , const char * name , mrb_value );
279268MRB_API void mrb_undef_method (mrb_state * , struct RClass * , const char * );
280269MRB_API void mrb_undef_class_method (mrb_state * , struct RClass * , const char * );
270+
271+ /**
272+ * Initialize a new object instace of c class.
273+ *
274+ * @param mrb
275+ * The current mruby state.
276+ * @param c
277+ * Reference to the class of the new object.
278+ * @param argc
279+ * Number of arguments in argv
280+ * @param argv
281+ * Array of @ref mrb_value "mrb_values" to initialize the object
282+ * @returns
283+ * The newly initialized object
284+ */
281285MRB_API mrb_value mrb_obj_new (mrb_state * mrb , struct RClass * c , mrb_int argc , const mrb_value * argv );
282- #define mrb_class_new_instance (mrb ,argc ,argv ,c ) mrb_obj_new(mrb,c,argc,argv)
286+
287+ /** See @ref mrb_obj_new */
288+ MRB_INLINE mrb_value mrb_class_new_instance (mrb_state * mrb , struct RClass * c , mrb_int argc , const mrb_value * argv )
289+ {
290+ return mrb_obj_new (mrb ,c ,argc ,argv );
291+ }
292+
283293MRB_API mrb_value mrb_instance_new (mrb_state * mrb , mrb_value cv );
284294MRB_API struct RClass * mrb_class_new (mrb_state * mrb , struct RClass * super );
285295MRB_API struct RClass * mrb_module_new (mrb_state * mrb );
@@ -464,19 +474,32 @@ char* mrb_locale_from_utf8(const char *p, size_t len);
464474 */
465475MRB_API mrb_state * mrb_open (void );
466476
467-
468477/**
469- * Create new mrb_state with custom allocator .
478+ * Create new mrb_state with custom allocators .
470479 *
480+ * @param f
481+ * Reference to the allocation function.
471482 * @param ud
472- * will be passed to custom allocator f. If user data isn't required just
473- * pass NULL. Function pointer f must satisfy requirements of its type.
483+ * User data will be passed to custom allocator f.
484+ * If user data isn't required just pass NULL.
485+ * @returns
486+ * Pointer to the newly created mrb_state.
487+ */
488+ MRB_API mrb_state * mrb_open_allocf (mrb_allocf f , void * ud );
489+
490+ /**
491+ * Create new mrb_state with just the MRuby core
474492 *
493+ * @param f
494+ * Reference to the allocation function.
495+ * Use mrb_default_allocf for the default
496+ * @param ud
497+ * User data will be passed to custom allocator f.
498+ * If user data isn't required just pass NULL.
475499 * @returns
476500 * Pointer to the newly created mrb_state.
477501 */
478- MRB_API mrb_state * mrb_open_allocf (mrb_allocf , void * ud );
479- MRB_API mrb_state * mrb_open_core (mrb_allocf , void * ud );
502+ MRB_API mrb_state * mrb_open_core (mrb_allocf f , void * ud );
480503
481504/**
482505 * Closes and frees a mrb_state.
@@ -486,6 +509,11 @@ MRB_API mrb_state* mrb_open_core(mrb_allocf, void *ud);
486509 */
487510MRB_API void mrb_close (mrb_state * mrb );
488511
512+ /**
513+ * The default allocation function.
514+ *
515+ * @ref mrb_allocf
516+ */
489517MRB_API void * mrb_default_allocf (mrb_state * , void * , size_t , void * );
490518
491519MRB_API mrb_value mrb_top_self (mrb_state * );
0 commit comments