Created
July 28, 2017 10:27
-
-
Save mizzy/8e6e68c308fda235de9436fc5475f277 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mruby.h" | |
#include <stdlib.h> | |
static mrb_value mrb_rand(mrb_state *mrb, mrb_value recv) | |
{ | |
int n = rand(); | |
return mrb_fixnum_value(n); | |
} | |
static mrb_value mrb_srand(mrb_state *mrb, mrb_value recv) | |
{ | |
int n; | |
mrb_get_args(mrb, "i", &n); | |
srand(n); | |
return mrb_nil_value(); | |
} | |
void mrb_mruby_rand_gem_init(mrb_state *mrb) | |
{ | |
struct RClass *r = mrb_define_module(mrb, "Random"); | |
mrb_define_module_function(mrb, r, "rand", mrb_rand, MRB_ARGS_NONE()); | |
mrb_define_module_function(mrb, r, "srand", mrb_srand, MRB_ARGS_REQ(1)); | |
} | |
void mrb_mruby_rand_gem_final(mrb_state *mrb) | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment