mruby/mruby — pull request #1507 by ktaobo (2013-09-20 10:11:17+00:00)
Title: Use self for the given proc in mrb_yield

When a block is called from C using `mrb_yield` function,
`self` is changed in the block.

I am trying to use mruby's block for callback, and call it when some event occurred.
But if I use `mrb_yield` to call the block, `self` is changed in the call.

Test code:
foo.rb:
```ruby
$block = nil
def register_callback(&block)
$block = block
end

class Foo
def initialize
register_callback do
self # (A)
end
end
end
foo = Foo.new()
```

main.c:
```c
#include "mruby.h"
#include "mruby/compile.h"
#include "mruby/variable.h"

static mrb_value trigger_callback(mrb_state *mrb) {
mrb_value block = mrb_gv_get(mrb, mrb_intern_cstr(mrb, "$block"));
mrb_value self = mrb_yield(mrb, block, mrb_nil_value());
//mrb_value self = mrb_funcall(mrb, block, "yield", 0); // (B)
return self;
}

int main() {
mrb_state* mrb = mrb_open();
FILE* fp = fopen("foo.rb", "r");
mrb_value foo = mrb_load_file(mrb, fp);
fclose(fp);

mrb_value self = trigger_callback(mrb);
if (mrb_obj_eq(mrb, self, foo)) {
puts("true");
} else {
puts("false");
}

mrb_close(mrb);
return 0;
}
```

I expect that `self` at code (A) is Foo instance,
but if I call the block using `mrb_yield`, `self` is changed to `main`.

If I use `mrb_funcall` instread of `mrb_yield`, `self` is Foo instance as expected.

This change fixes the problem.