diff options
| author | Kouki Ooyatsu <[email protected]> | 2013-03-08 10:02:31 +0900 |
|---|---|---|
| committer | Kouki Ooyatsu <[email protected]> | 2013-03-08 10:05:41 +0900 |
| commit | 6c066302e2200f91847befd56b4ddbb555f41925 (patch) | |
| tree | e618b058791b4e1b868c48f00f575f0019be8823 /mrbgems/mruby-numeric-ext/src/numeric_ext.c | |
| parent | aa73a1068f2fd5cbff7e4623ab2036d360933ff9 (diff) | |
| download | mruby-6c066302e2200f91847befd56b4ddbb555f41925.tar.gz mruby-6c066302e2200f91847befd56b4ddbb555f41925.zip | |
add mrbgems/ext/mruby-numeric, and method: Integer#chr
Diffstat (limited to 'mrbgems/mruby-numeric-ext/src/numeric_ext.c')
| -rw-r--r-- | mrbgems/mruby-numeric-ext/src/numeric_ext.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/mrbgems/mruby-numeric-ext/src/numeric_ext.c b/mrbgems/mruby-numeric-ext/src/numeric_ext.c new file mode 100644 index 000000000..b2c0e7986 --- /dev/null +++ b/mrbgems/mruby-numeric-ext/src/numeric_ext.c @@ -0,0 +1,30 @@ +#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) +{ +} |
