Esempio n. 1
0
File: random.c Progetto: ASnow/mruby
static mrb_value
mrb_random_rand(mrb_state *mrb, mrb_value self)
{
  mrb_value max;
  mt_state *t = DATA_GET_PTR(mrb, self, &mt_state_type, mt_state);

  max = get_opt(mrb);
  mrb_random_rand_seed(mrb, t);
  return mrb_random_mt_rand(mrb, t, max);
}
Esempio n. 2
0
static mt_state *mrb_mt_get_context(mrb_state *mrb,  mrb_value self)
{
  mt_state *t;
  mrb_value context;

  context = mrb_iv_get(mrb, self, mrb_intern2(mrb, MT_STATE_KEY, MT_STATE_KEY_CSTR_LEN));
  t = DATA_GET_PTR(mrb, context, &mt_state_type, mt_state);

  return t;
}
Esempio n. 3
0
File: random.c Progetto: ASnow/mruby
static mrb_value
mrb_random_srand(mrb_state *mrb, mrb_value self)
{
  mrb_value seed;
  mrb_value old_seed;
  mt_state *t = DATA_GET_PTR(mrb, self, &mt_state_type, mt_state);

  seed = get_opt(mrb);
  seed = mrb_random_mt_srand(mrb, t, seed);
  old_seed = t->has_seed? mrb_fixnum_value(t->seed) : mrb_nil_value();
  if (mrb_nil_p(seed)) {
    t->has_seed = FALSE;
  }
  else {
    mrb_assert(mrb_fixnum_p(seed));
    t->has_seed = TRUE;
    t->seed = mrb_fixnum(seed);
  }

  return old_seed;
}
Esempio n. 4
0
File: random.c Progetto: ASnow/mruby
static mt_state *
get_random_state(mrb_state *mrb)
{
  mrb_value random_val = get_random(mrb);
  return DATA_GET_PTR(mrb, random_val, &mt_state_type, mt_state);
}
Esempio n. 5
0
mrb_value mrb_simple_i(mrb_state *mrb, mrb_value self) {
  simple_context *simple;
  simple = DATA_GET_PTR(mrb, self, &mrb_simple_ctx_type, simple_context);
  
  return mrb_fixnum_value(simple->i);
}
Esempio n. 6
0
mrb_value mrb_simple_f(mrb_state *mrb, mrb_value self) {
  simple_context *simple;
  simple = DATA_GET_PTR(mrb, self, &mrb_simple_ctx_type, simple_context);
  
  return mrb_float_value(mrb, simple->f);
}