Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
878fe38b
Commit
878fe38b
authored
Mar 01, 2013
by
mattn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gemify
parent
261efd8e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
10 deletions
+17
-10
build_config.rb
build_config.rb
+3
-0
mrbgems/mruby-struct/src/struct.c
mrbgems/mruby-struct/src/struct.c
+14
-10
No files found.
build_config.rb
View file @
878fe38b
...
...
@@ -17,6 +17,9 @@ MRuby::Build.new do |conf|
# Use standard Time class
conf
.
gem
'mrbgems/mruby-time'
# Use standard Struct class
conf
.
gem
'mrbgems/mruby-struct'
# Generate binaries
# conf.bins = %w(mrbc mruby mirb)
...
...
mrbgems/mruby-struct/src/struct.c
View file @
878fe38b
...
...
@@ -69,7 +69,7 @@ mrb_value
mrb_struct_members
(
mrb_state
*
mrb
,
mrb_value
s
)
{
mrb_value
members
=
mrb_struct_s_members
(
mrb
,
mrb_obj_value
(
mrb_obj_class
(
mrb
,
s
)));
if
(
mrb_type
(
s
)
==
MRB_TT_STRUCT
)
{
if
(
!
strcmp
(
mrb_class_name
(
mrb
,
mrb_obj_class
(
mrb
,
s
)),
"Struct"
)
)
{
if
(
RSTRUCT_LEN
(
s
)
!=
RARRAY_LEN
(
members
))
{
mrb_raisef
(
mrb
,
E_TYPE_ERROR
,
"struct size differs (%ld required %ld given)"
,
RARRAY_LEN
(
members
),
RSTRUCT_LEN
(
s
));
...
...
@@ -140,7 +140,7 @@ mrb_struct_getmember(mrb_state *mrb, mrb_value obj, mrb_sym id)
return
ptr
[
i
];
}
}
mrb_
name_error
(
mrb
,
id
,
"%s is not struct member"
,
mrb_sym2name
(
mrb
,
id
));
mrb_
raisef
(
mrb
,
E_NAME_ERROR
,
"%s is not struct member"
,
mrb_sym2name
(
mrb
,
id
));
return
mrb_nil_value
();
/* not reached */
}
...
...
@@ -219,7 +219,7 @@ mrb_struct_set(mrb_state *mrb, mrb_value obj, mrb_value val)
}
}
mrb_
name_error
(
mrb
,
mid
,
"`%s' is not a struct member"
,
mrb_
raisef
(
mrb
,
E_NAME_ERROR
,
"`%s' is not a struct member"
,
mrb_sym2name
(
mrb
,
mid
));
return
mrb_nil_value
();
/* not reached */
}
...
...
@@ -264,7 +264,7 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * k
name
=
mrb_str_to_str
(
mrb
,
name
);
id
=
mrb_to_id
(
mrb
,
name
);
if
(
!
mrb_is_const_id
(
id
))
{
mrb_
name_error
(
mrb
,
id
,
"identifier %s needs to be constant"
,
mrb_string_value_ptr
(
mrb
,
name
));
mrb_
raisef
(
mrb
,
E_NAME_ERROR
,
"identifier %s needs to be constant"
,
mrb_string_value_ptr
(
mrb
,
name
));
}
if
(
mrb_const_defined_at
(
mrb
,
klass
,
id
))
{
mrb_warn
(
"redefining constant Struct::%s"
,
mrb_string_value_ptr
(
mrb
,
name
));
...
...
@@ -272,7 +272,6 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * k
}
c
=
mrb_define_class_under
(
mrb
,
klass
,
RSTRING_PTR
(
name
),
klass
);
}
MRB_SET_INSTANCE_TT
(
c
,
MRB_TT_STRUCT
);
nstr
=
mrb_obj_value
(
c
);
mrb_iv_set
(
mrb
,
nstr
,
mrb_intern
(
mrb
,
"__members__"
),
members
);
...
...
@@ -552,7 +551,7 @@ mrb_struct_aref_id(mrb_state *mrb, mrb_value s, mrb_sym id)
return
ptr
[
i
];
}
}
mrb_
name_error
(
mrb
,
id
,
"no member '%s' in struct"
,
mrb_sym2name
(
mrb
,
id
));
mrb_
raisef
(
mrb
,
E_NAME_ERROR
,
"no member '%s' in struct"
,
mrb_sym2name
(
mrb
,
id
));
return
mrb_nil_value
();
/* not reached */
}
...
...
@@ -624,7 +623,7 @@ mrb_struct_aset_id(mrb_state *mrb, mrb_value s, mrb_sym id, mrb_value val)
return
val
;
}
}
mrb_
name_error
(
mrb
,
id
,
"no member '%s' in struct"
,
mrb_sym2name
(
mrb
,
id
));
mrb_
raisef
(
mrb
,
E_NAME_ERROR
,
"no member '%s' in struct"
,
mrb_sym2name
(
mrb
,
id
));
return
val
;
/* not reach */
}
...
...
@@ -703,7 +702,7 @@ mrb_struct_equal(mrb_state *mrb, mrb_value s)
mrb_get_args
(
mrb
,
"o"
,
&
s2
);
if
(
mrb_obj_equal
(
mrb
,
s
,
s2
))
return
mrb_true_value
();
if
(
mrb_type
(
s2
)
!=
MRB_TT_STRUCT
)
return
mrb_false_value
();
if
(
!
strcmp
(
mrb_class_name
(
mrb
,
mrb_obj_class
(
mrb
,
s
)),
"Struct"
)
)
return
mrb_false_value
();
if
(
mrb_obj_class
(
mrb
,
s
)
!=
mrb_obj_class
(
mrb
,
s2
))
return
mrb_false_value
();
if
(
RSTRUCT_LEN
(
s
)
!=
RSTRUCT_LEN
(
s2
))
{
mrb_bug
(
"inconsistent struct"
);
/* should never happen */
...
...
@@ -734,7 +733,7 @@ mrb_struct_eql(mrb_state *mrb, mrb_value s)
mrb_get_args
(
mrb
,
"o"
,
&
s2
);
if
(
mrb_obj_equal
(
mrb
,
s
,
s2
))
return
mrb_true_value
();
if
(
mrb_type
(
s2
)
!=
MRB_TT_STRUCT
)
return
mrb_false_value
();
if
(
strcmp
(
mrb_class_name
(
mrb
,
mrb_obj_class
(
mrb
,
s2
)),
"Struct"
)
)
return
mrb_false_value
();
if
(
mrb_obj_class
(
mrb
,
s
)
!=
mrb_obj_class
(
mrb
,
s2
))
return
mrb_false_value
();
if
(
RSTRUCT_LEN
(
s
)
!=
RSTRUCT_LEN
(
s2
))
{
mrb_bug
(
"inconsistent struct"
);
/* should never happen */
...
...
@@ -765,7 +764,7 @@ mrb_struct_eql(mrb_state *mrb, mrb_value s)
* <code>Symbol</code> (such as <code>:name</code>).
*/
void
mrb_
init_struct
(
mrb_state
*
mrb
)
mrb_
mruby_struct_gem_init
(
mrb_state
*
mrb
)
{
struct
RClass
*
st
;
st
=
mrb_define_class
(
mrb
,
"Struct"
,
mrb
->
object_class
);
...
...
@@ -783,3 +782,8 @@ mrb_init_struct(mrb_state *mrb)
mrb_define_method
(
mrb
,
st
,
"eql?"
,
mrb_struct_eql
,
ARGS_REQ
(
1
));
/* 15.2.18.4.12(x) */
}
void
mrb_mruby_struct_gem_final
(
mrb_state
*
mrb
)
{
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment