Groonga 3.0.9 Source Code Document
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
groonga
vendor
mruby-eeac4be
mrbgems
mruby-proc-ext
src
proc.c
Go to the documentation of this file.
1
#include "
mruby.h
"
2
#include "
mruby/proc.h
"
3
#include "
mruby/array.h
"
4
#include "
mruby/string.h
"
5
6
static
mrb_value
7
mrb_proc_lambda(
mrb_state
*mrb,
mrb_value
self
)
8
{
9
struct
RProc
*p =
mrb_proc_ptr
(
self
);
10
return
mrb_bool_value(
MRB_PROC_STRICT_P
(p));
11
}
12
13
static
mrb_value
14
mrb_proc_source_location(
mrb_state
*mrb,
mrb_value
self
)
15
{
16
struct
RProc
*p =
mrb_proc_ptr
(
self
);
17
18
if
(
MRB_PROC_CFUNC_P
(p)) {
19
return
mrb_nil_value();
20
}
21
else
{
22
mrb_irep
*
irep
= p->
body
.
irep
;
23
mrb_value
filename = mrb_nil_value();
24
mrb_value
lines = mrb_nil_value();
25
26
if
(irep->
filename
) filename =
mrb_str_new_cstr
(mrb, irep->
filename
);
27
if
(irep->
lines
) lines = mrb_fixnum_value(*irep->
lines
);
28
29
return
mrb_assoc_new
(mrb, filename, lines);
30
}
31
}
32
33
static
mrb_value
34
mrb_proc_inspect(
mrb_state
*mrb,
mrb_value
self
)
35
{
36
struct
RProc
*p =
mrb_proc_ptr
(
self
);
37
mrb_value
str =
mrb_str_new_cstr
(mrb,
"#<Proc:"
);
38
mrb_str_concat
(mrb, str,
mrb_ptr_to_str
(mrb,
mrb_cptr
(
self
)));
39
40
if
(!
MRB_PROC_CFUNC_P
(p)) {
41
mrb_irep
*irep = p->
body
.
irep
;
42
mrb_str_cat_cstr
(mrb, str,
"@"
);
43
44
if
(irep->
filename
) {
45
mrb_str_cat_cstr
(mrb, str, irep->
filename
);
46
}
47
else
{
48
mrb_str_cat_cstr
(mrb, str,
"-"
);
49
}
50
mrb_str_cat_cstr
(mrb, str,
":"
);
51
52
if
(irep->
lines
) {
53
mrb_str_append
(mrb, str, mrb_fixnum_value(*irep->
lines
));
54
}
55
else
{
56
mrb_str_cat_cstr
(mrb, str,
"-"
);
57
}
58
}
59
60
if
(
MRB_PROC_STRICT_P
(p)) {
61
mrb_str_cat_cstr
(mrb, str,
" (lambda)"
);
62
}
63
64
mrb_str_cat_cstr
(mrb, str,
">"
);
65
return
str;
66
}
67
68
static
mrb_value
69
mrb_kernel_proc(
mrb_state
*mrb,
mrb_value
self
)
70
{
71
mrb_value
blk;
72
73
mrb_get_args
(mrb,
"&"
, &blk);
74
if
(
mrb_nil_p
(blk)) {
75
mrb_raise
(mrb,
E_ARGUMENT_ERROR
,
"tried to create Proc object without a block"
);
76
}
77
78
return
blk;
79
}
80
81
void
82
mrb_mruby_proc_ext_gem_init
(
mrb_state
* mrb)
83
{
84
struct
RClass
*p = mrb->
proc_class
;
85
mrb_define_method
(mrb, p,
"lambda?"
, mrb_proc_lambda,
MRB_ARGS_NONE
());
86
mrb_define_method
(mrb, p,
"source_location"
, mrb_proc_source_location,
MRB_ARGS_NONE
());
87
mrb_define_method
(mrb, p,
"to_s"
, mrb_proc_inspect,
MRB_ARGS_NONE
());
88
mrb_define_method
(mrb, p,
"inspect"
, mrb_proc_inspect,
MRB_ARGS_NONE
());
89
90
mrb_define_class_method
(mrb, mrb->
kernel_module
,
"proc"
, mrb_kernel_proc,
MRB_ARGS_NONE
());
91
mrb_define_method
(mrb, mrb->
kernel_module
,
"proc"
, mrb_kernel_proc,
MRB_ARGS_NONE
());
92
}
93
94
void
95
mrb_mruby_proc_ext_gem_final
(
mrb_state
* mrb)
96
{
97
}
Generated on Sun Nov 10 2013 09:49:04 for Groonga 3.0.9 Source Code Document by
1.8.1.2