Sha256: f7f5eed280b02a552752408f8f698f5fe802563d7ef77ccd94f677a854abd484

Contents?: true

Size: 536 Bytes

Versions: 4

Compression:

Stored size: 536 Bytes

Contents

#include <limits.h>
#include "mruby.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, "%S out of char range", x);
  }
  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, MRB_ARGS_NONE());
}

void
mrb_mruby_numeric_ext_gem_final(mrb_state* mrb)
{
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
webruby-0.9.3 modules/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c
webruby-0.9.2 modules/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c
webruby-0.9.1 modules/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c
webruby-0.2.7 modules/mruby/mrbgems/mruby-numeric-ext/src/numeric_ext.c