summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-proc-ext/src/proc.c
diff options
context:
space:
mode:
authortake_cheeze <[email protected]>2014-03-06 03:40:41 +0900
committertake_cheeze <[email protected]>2014-03-06 03:40:41 +0900
commitf8270ee59bfbeb46a267312e49a4d39a236f0e7e (patch)
tree91df80ea347bad575bf41eb5408b3d796caa236d /mrbgems/mruby-proc-ext/src/proc.c
parentb8625bbc5ec17fbe47387ec2041b7f6299fb4565 (diff)
downloadmruby-f8270ee59bfbeb46a267312e49a4d39a236f0e7e.tar.gz
mruby-f8270ee59bfbeb46a267312e49a4d39a236f0e7e.zip
fix and add test for Proc#source_location
Diffstat (limited to 'mrbgems/mruby-proc-ext/src/proc.c')
-rw-r--r--mrbgems/mruby-proc-ext/src/proc.c12
1 files changed, 7 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));
}
}