diff options
| author | take_cheeze <[email protected]> | 2014-03-06 03:40:41 +0900 |
|---|---|---|
| committer | take_cheeze <[email protected]> | 2014-03-06 03:40:41 +0900 |
| commit | f8270ee59bfbeb46a267312e49a4d39a236f0e7e (patch) | |
| tree | 91df80ea347bad575bf41eb5408b3d796caa236d /mrbgems/mruby-proc-ext | |
| parent | b8625bbc5ec17fbe47387ec2041b7f6299fb4565 (diff) | |
| download | mruby-f8270ee59bfbeb46a267312e49a4d39a236f0e7e.tar.gz mruby-f8270ee59bfbeb46a267312e49a4d39a236f0e7e.zip | |
fix and add test for Proc#source_location
Diffstat (limited to 'mrbgems/mruby-proc-ext')
| -rw-r--r-- | mrbgems/mruby-proc-ext/src/proc.c | 12 | ||||
| -rw-r--r-- | mrbgems/mruby-proc-ext/test/proc.rb | 7 |
2 files changed, 14 insertions, 5 deletions
diff --git a/mrbgems/mruby-proc-ext/src/proc.c b/mrbgems/mruby-proc-ext/src/proc.c index 3bb0d3570..0bf1204f5 100644 --- a/mrbgems/mruby-proc-ext/src/proc.c +++ b/mrbgems/mruby-proc-ext/src/proc.c @@ -2,6 +2,7 @@ #include "mruby/proc.h" #include "mruby/array.h" #include "mruby/string.h" +#include "mruby/debug.h" static mrb_value mrb_proc_lambda(mrb_state *mrb, mrb_value self) @@ -20,13 +21,14 @@ mrb_proc_source_location(mrb_state *mrb, mrb_value self) } else { mrb_irep *irep = p->body.irep; - mrb_value filename = mrb_nil_value(); - mrb_value lines = mrb_nil_value(); + uint32_t line; + const char *filename; - if (irep->filename) filename = mrb_str_new_cstr(mrb, irep->filename); - if (irep->lines) lines = mrb_fixnum_value(*irep->lines); + filename = mrb_debug_get_filename(irep, 0); + line = mrb_debug_get_line(irep, 0); - return mrb_assoc_new(mrb, filename, lines); + return (!filename && line == -1)? mrb_nil_value() + : mrb_assoc_new(mrb, mrb_str_new_cstr(mrb, filename), mrb_fixnum_value(line)); } } diff --git a/mrbgems/mruby-proc-ext/test/proc.rb b/mrbgems/mruby-proc-ext/test/proc.rb index abbd7a9d9..ef8b7f31c 100644 --- a/mrbgems/mruby-proc-ext/test/proc.rb +++ b/mrbgems/mruby-proc-ext/test/proc.rb @@ -1,6 +1,13 @@ ## # Proc(Ext) Test +assert('Proc#source_location') do + loc = Proc.new {}.source_location + next true if loc.nil? + assert_equal loc[0][-7, 7], 'proc.rb' + assert_equal loc[1], 5 +end + assert('Proc#lambda?') do assert_true lambda{}.lambda? assert_true !Proc.new{}.lambda? |
