mruby 3.3.0
mruby is the lightweight implementation of the Ruby language
Loading...
Searching...
No Matches
range.h
Go to the documentation of this file.
1
7#ifndef MRUBY_RANGE_H
8#define MRUBY_RANGE_H
9
10#include "common.h"
11
16
17#if defined(MRB_NAN_BOXING) && defined(MRB_64BIT) || defined(MRB_WORD_BOXING)
18# define MRB_RANGE_EMBED
19#endif
20
21#ifdef MRB_RANGE_EMBED
22struct RRange {
23 MRB_OBJECT_HEADER;
24 mrb_value beg;
25 mrb_value end;
26 mrb_bool excl;
27};
28# define mrb_gc_free_range(mrb, p) ((void)0)
29# define RANGE_BEG(p) ((p)->beg)
30# define RANGE_END(p) ((p)->end)
31#else
32typedef struct mrb_range_edges {
33 mrb_value beg;
34 mrb_value end;
36struct RRange {
37 MRB_OBJECT_HEADER;
38 mrb_range_edges *edges;
39 mrb_bool excl;
40};
41# define mrb_gc_free_range(mrb, p) mrb_free(mrb, (p)->edges)
42# define RANGE_BEG(p) ((p)->edges->beg)
43# define RANGE_END(p) ((p)->edges->end)
44#endif
45
46#define mrb_range_beg(mrb, r) RANGE_BEG(mrb_range_ptr(mrb, r))
47#define mrb_range_end(mrb, r) RANGE_END(mrb_range_ptr(mrb, r))
48#define mrb_range_excl_p(mrb, r) RANGE_EXCL(mrb_range_ptr(mrb, r))
49#define mrb_range_raw_ptr(r) ((struct RRange*)mrb_ptr(r))
50#define mrb_range_value(p) mrb_obj_value((void*)(p))
51#define RANGE_EXCL(p) ((p)->excl)
52
53MRB_API struct RRange* mrb_range_ptr(mrb_state *mrb, mrb_value range);
54
55/*
56 * Initializes a Range.
57 *
58 * If the third parameter is FALSE then it includes the last value in the range.
59 * If the third parameter is TRUE then it excludes the last value in the range.
60 *
61 * @param start the beginning value.
62 * @param end the ending value.
63 * @param exclude represents the inclusion or exclusion of the last value.
64 */
65MRB_API mrb_value mrb_range_new(mrb_state *mrb, mrb_value start, mrb_value end, mrb_bool exclude);
66
67enum mrb_range_beg_len {
68 MRB_RANGE_TYPE_MISMATCH = 0, /* (failure) not range */
69 MRB_RANGE_OK = 1, /* (success) range */
70 MRB_RANGE_OUT = 2 /* (failure) out of range */
71};
72
73MRB_API enum mrb_range_beg_len mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp, mrb_int len, mrb_bool trunc);
74
76
77#endif /* MRUBY_RANGE_H */
mruby Boolean.
mruby common platform definition"
#define MRB_END_DECL
End declarations in C mode.
Definition common.h:28
#define MRB_BEGIN_DECL
Start declarations in C mode.
Definition common.h:26
#define MRB_API
Declare a public mruby API function.
Definition common.h:79
Definition range.h:36
Range class.
Definition range.h:32
Definition mruby.h:256
Definition boxing_nan.h:40