Commit ad2e6d0c authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #2204 from take-cheeze/kernel_fail

Implement Kernel.fail and Kernel#fail .
parents 14e5c373 2fca5f33
...@@ -21,6 +21,9 @@ void mrb_print_backtrace(mrb_state *mrb); ...@@ -21,6 +21,9 @@ void mrb_print_backtrace(mrb_state *mrb);
mrb_value mrb_exc_backtrace(mrb_state *mrb, mrb_value exc); mrb_value mrb_exc_backtrace(mrb_state *mrb, mrb_value exc);
mrb_value mrb_get_backtrace(mrb_state *mrb); mrb_value mrb_get_backtrace(mrb_state *mrb);
/* declaration for fail method */
mrb_value mrb_f_raise(mrb_state*, mrb_value);
#if defined(__cplusplus) #if defined(__cplusplus)
} /* extern "C" { */ } /* extern "C" { */
#endif #endif
......
...@@ -64,4 +64,7 @@ MRuby::GemBox.new do |conf| ...@@ -64,4 +64,7 @@ MRuby::GemBox.new do |conf|
# Generate mruby command # Generate mruby command
conf.gem :core => "mruby-bin-mruby" conf.gem :core => "mruby-bin-mruby"
# Use extensional Kernel module
conf.gem :core => "mruby-kernel-ext"
end end
MRuby::Gem::Specification.new('mruby-kernel-ext') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = 'extensional Kernel module'
end
#include <mruby.h>
#include <mruby/error.h>
void
mrb_mruby_kernel_ext_gem_init(mrb_state *mrb)
{
struct RClass *krn = mrb->kernel_module;
mrb_define_module_function(mrb, krn, "fail", mrb_f_raise, MRB_ARGS_NONE());
}
void
mrb_mruby_kernel_ext_gem_final(mrb_state *mrb)
{
}
assert('Kernel.fail, Kernel#fail') do
assert_raise(RuntimeError) { fail }
assert_raise(RuntimeError) { Kernel.fail }
end
...@@ -924,7 +924,7 @@ mrb_obj_public_methods(mrb_state *mrb, mrb_value self) ...@@ -924,7 +924,7 @@ mrb_obj_public_methods(mrb_state *mrb, mrb_value self)
* raise "Failed to create socket" * raise "Failed to create socket"
* raise ArgumentError, "No parameters", caller * raise ArgumentError, "No parameters", caller
*/ */
static mrb_value mrb_value
mrb_f_raise(mrb_state *mrb, mrb_value self) mrb_f_raise(mrb_state *mrb, mrb_value self)
{ {
mrb_value a[2], exc; mrb_value a[2], exc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment