diff options
| author | Yukihiro Matz Matsumoto <[email protected]> | 2013-03-09 00:39:45 +0900 |
|---|---|---|
| committer | Yukihiro Matz Matsumoto <[email protected]> | 2013-03-09 00:39:45 +0900 |
| commit | b783311ec442d4b27f67ecb287c413cac36df147 (patch) | |
| tree | 8f90cb67e53f2b949cd62b515dce981806f6a2e9 /mrbgems/mruby-numeric-ext/src/numeric_ext.c | |
| parent | 318ad9c802d010b398a9683407716b5c7ef32b00 (diff) | |
| parent | 3c5bf780e4a3dcd2e73edd2475140ce0c2a46268 (diff) | |
| download | mruby-b783311ec442d4b27f67ecb287c413cac36df147.tar.gz mruby-b783311ec442d4b27f67ecb287c413cac36df147.zip | |
Merge branch 'master' of github.com:mruby/mruby
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) +{ +} |
