-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
691c36d
commit 2b24551
Showing
4 changed files
with
169 additions
and
53 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
require 'mkmf' | ||
|
||
$CFLAGS += " -DRUBY_19" if RUBY_VERSION =~ /1.9/ | ||
|
||
extension_name = "raise_awareness" | ||
dir_config(extension_name) | ||
create_makefile(extension_name) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,52 @@ | ||
#include "ruby.h" | ||
|
||
static VALUE rb_mRaiseAwareness; | ||
static VALUE argv[1]; | ||
|
||
#ifdef RUBY_19 | ||
|
||
void | ||
raise_awareness_hook(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass) | ||
{ | ||
VALUE binding = rb_funcall(self, rb_intern("binding"), 0, NULL); | ||
rb_funcall(data, rb_intern("rescue"), 2, rb_errinfo(), binding); | ||
VALUE binding = rb_funcall(rb_mKernel, rb_intern("binding"), 0, NULL); | ||
rb_funcall(rb_mRaiseAwareness, rb_intern("rescue"), 2, rb_errinfo(), binding); | ||
} | ||
|
||
VALUE | ||
raise_awareness_start(VALUE self) | ||
{ | ||
rb_add_event_hook(raise_awareness_hook, RUBY_EVENT_RAISE, rb_mRaiseAwareness); | ||
} | ||
|
||
#else | ||
|
||
#include "node.h" | ||
|
||
void | ||
raise_awareness_hook(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass) | ||
{ | ||
VALUE binding = rb_funcall(rb_mKernel, rb_intern("binding"), 0, NULL); | ||
rb_funcall(rb_mRaiseAwareness, rb_intern("rescue"), 2, ruby_errinfo, binding); | ||
} | ||
|
||
VALUE | ||
raise_awareness_start(VALUE self) | ||
{ | ||
rb_add_event_hook(raise_awareness_hook, RUBY_EVENT_RAISE); | ||
} | ||
|
||
#endif | ||
|
||
VALUE | ||
raise_awareness_stop(VALUE self) | ||
{ | ||
rb_remove_event_hook(raise_awareness_hook); | ||
return Qnil; | ||
} | ||
|
||
void | ||
Init_raise_awareness() | ||
{ | ||
rb_mRaiseAwareness = rb_define_module("RaiseAwareness"); | ||
rb_add_event_hook(raise_awareness_hook, RUBY_EVENT_RAISE, rb_mRaiseAwareness); | ||
rb_define_singleton_method(rb_mRaiseAwareness, "start", raise_awareness_start, 0); | ||
rb_define_singleton_method(rb_mRaiseAwareness, "stop", raise_awareness_start, 0); | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.pryrepl; | ||
|
||
import org.jruby.runtime.builtin.IRubyObject; | ||
import org.jruby.runtime.EventHook; | ||
import org.jruby.runtime.RubyEvent; | ||
import org.jruby.runtime.ThreadContext; | ||
import org.jruby.RubyException; | ||
import org.jruby.RubyBinding; | ||
import org.jruby.RubyProc; | ||
|
||
public class RaiseAwarenessEventHook extends EventHook { | ||
|
||
private RubyProc proc; | ||
|
||
public RaiseAwarenessEventHook(RubyProc proc) { | ||
super(); | ||
this.proc = proc; | ||
} | ||
|
||
public boolean isInterestedInEvent(RubyEvent event) { | ||
return event.getName().equals(RubyEvent.RAISE.getName()); | ||
} | ||
|
||
public void eventHandler(ThreadContext context, String eventName, String file, int line, String name, IRubyObject type) { | ||
RubyBinding binding = RubyBinding.newBinding(context.runtime, context.currentBinding()); | ||
RubyException exception = (RubyException)context.runtime.getGlobalVariables().get("$!"); | ||
proc.call(context, new IRubyObject[] {exception, binding}); | ||
} | ||
} |