Last active
January 6, 2021 01:58
-
-
Save haileys/adce2b812c728aa22032d247debdf45e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <mruby/compile.h> | |
#include <mruby/string.h> | |
#include <stdio.h> | |
mrb_state* mrb; | |
void p(mrb_value value) { | |
printf("--> %s\n", mrb_str_to_cstr(mrb, mrb_inspect(mrb, value))); | |
} | |
int main() { | |
mrb = mrb_open(); | |
mrb_value fiber_class = mrb_obj_value(mrb_class_get(mrb, "Fiber")); | |
mrb_value proc = mrb_load_string(mrb, "proc { |a| a + 1 }"); | |
mrb_value fiber = mrb_funcall_with_block(mrb, fiber_class, mrb_intern_cstr(mrb, "new"), 0, NULL, proc); | |
p(fiber); | |
mrb_value start_arg = mrb_fixnum_value(123); | |
mrb_value retn = mrb_fiber_resume(mrb, fiber, 1, &start_arg); | |
p(retn); | |
} | |
// Expected output: | |
// | |
// --> #<Fiber:0x55ce69b1fd90> | |
// --> 124 | |
// Actual output: | |
// | |
// --> #<Fiber:0x55ce69b1fd90> | |
// --> undefined method '+' (NoMethodError) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment