mbed I/F binding for mruby

Dependents:   mruby_mbed_web mirb_mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers numeric_ext.c Source File

numeric_ext.c

00001 #include <limits.h>
00002 #include "mruby.h"
00003 
00004 static mrb_value
00005 mrb_int_chr(mrb_state *mrb, mrb_value x)
00006 {
00007   mrb_int chr;
00008   char c;
00009 
00010   chr = mrb_fixnum(x);
00011   if (chr >= (1 << CHAR_BIT)) {
00012     mrb_raisef(mrb, E_RANGE_ERROR, "%S out of char range", x);
00013   }
00014   c = (char)chr;
00015 
00016   return mrb_str_new(mrb, &c, 1);
00017 }
00018 
00019 void
00020 mrb_mruby_numeric_ext_gem_init(mrb_state* mrb)
00021 {
00022   struct RClass *i = mrb_class_get(mrb, "Integer");
00023 
00024   mrb_define_method(mrb, i, "chr", mrb_int_chr, MRB_ARGS_NONE());
00025 }
00026 
00027 void
00028 mrb_mruby_numeric_ext_gem_final(mrb_state* mrb)
00029 {
00030 }
00031