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
cec28739
Commit
cec28739
authored
Mar 08, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #968 from kouki-o-iij/pr-mrbgem-numeric-ext
add mrbgems/ext/mruby-numeric, and method: Integer#chr
parents
c881a6a2
d3ff90f5
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
0 deletions
+47
-0
build_config.rb
build_config.rb
+3
-0
mrbgems/mruby-numeric-ext/mrbgem.rake
mrbgems/mruby-numeric-ext/mrbgem.rake
+4
-0
mrbgems/mruby-numeric-ext/src/numeric_ext.c
mrbgems/mruby-numeric-ext/src/numeric_ext.c
+30
-0
mrbgems/mruby-numeric-ext/test/numeric.rb
mrbgems/mruby-numeric-ext/test/numeric.rb
+10
-0
No files found.
build_config.rb
View file @
cec28739
...
@@ -26,6 +26,9 @@ MRuby::Build.new do |conf|
...
@@ -26,6 +26,9 @@ MRuby::Build.new do |conf|
# Use extensional String class
# Use extensional String class
conf
.
gem
'mrbgems/mruby-string-ext'
conf
.
gem
'mrbgems/mruby-string-ext'
# Use extensional Numeric class
conf
.
gem
'mrbgems/mruby-numeric-ext'
# Generate binaries
# Generate binaries
# conf.bins = %w(mrbc mruby mirb)
# conf.bins = %w(mrbc mruby mirb)
...
...
mrbgems/mruby-numeric-ext/mrbgem.rake
0 → 100644
View file @
cec28739
MRuby
::
Gem
::
Specification
.
new
(
'mruby-numeric-ext'
)
do
|
spec
|
spec
.
license
=
'MIT'
spec
.
authors
=
'mruby developers'
end
mrbgems/mruby-numeric-ext/src/numeric_ext.c
0 → 100644
View file @
cec28739
#include "mruby.h"
#include "mruby/numeric.h"
static
mrb_value
mrb_int_chr
(
mrb_state
*
mrb
,
mrb_value
x
)
{
mrb_int
chr
;
char
c
;
chr
=
mrb_fixnum
(
x
);
if
(
chr
>=
(
1
<<
CHAR_BIT
))
{
mrb_raisef
(
mrb
,
E_RANGE_ERROR
,
"%ld out of char range"
,
chr
);
}
c
=
(
char
)
chr
;
return
mrb_str_new
(
mrb
,
&
c
,
1
);
}
void
mrb_mruby_numeric_ext_gem_init
(
mrb_state
*
mrb
)
{
struct
RClass
*
i
=
mrb_class_get
(
mrb
,
"Integer"
);
mrb_define_method
(
mrb
,
i
,
"chr"
,
mrb_int_chr
,
ARGS_NONE
());
}
void
mrb_mruby_numeric_ext_gem_final
(
mrb_state
*
mrb
)
{
}
mrbgems/mruby-numeric-ext/test/numeric.rb
0 → 100644
View file @
cec28739
##
# Numeric(Ext) Test
assert
(
'Integer#chr'
)
do
assert_equal
(
65
.
chr
,
"A"
)
assert_equal
(
0x42
.
chr
,
"B"
)
# multibyte encoding (not support yet)
assert_raise
(
RangeError
)
{
12345
.
chr
}
end
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