ruby - Is there a way to get the JRuby script in the StackTraceElements in JRuby StackTraces - Stack Overflow

I am using JRuby, but I am often calling scripts from other scripts, which means that when I have Stack

I am using JRuby, but I am often calling scripts from other scripts, which means that when I have StackTraces from the Java caller, not all the StackTraceElements are coming from the initial calling class.

For example, if I have the following code in Ruby:

public
  def compute()
    retur 10
  end

I have the following StackTraceElement:

  • declaringClass: RUBY
  • methodName: compute
  • fileName: <script>
  • lineNumber: 3

I would like to get somewhere the name of my script, is it possible to get it in JRuby?

I am creating the script by:

    RubyRuntimeAdapter adapter = JavaEmbedUtils.newRuntimeAdapter();
    IRubyObject io = adapter.eval(runtime, <scriptContent>);

I am using JRuby, but I am often calling scripts from other scripts, which means that when I have StackTraces from the Java caller, not all the StackTraceElements are coming from the initial calling class.

For example, if I have the following code in Ruby:

public
  def compute()
    retur 10
  end

I have the following StackTraceElement:

  • declaringClass: RUBY
  • methodName: compute
  • fileName: <script>
  • lineNumber: 3

I would like to get somewhere the name of my script, is it possible to get it in JRuby?

I am creating the script by:

    RubyRuntimeAdapter adapter = JavaEmbedUtils.newRuntimeAdapter();
    IRubyObject io = adapter.eval(runtime, <scriptContent>);
Share Improve this question edited Mar 12 at 8:36 Hervé Girod asked Mar 12 at 8:17 Hervé GirodHervé Girod 5694 silver badges21 bronze badges 2
  • 1 Wouldn't accessing the constant __FILE__ do what you want? Why do you need a StackTraceElement? – user1934428 Commented Mar 27 at 11:11
  • I created a framework which encapsulate the usage of scripts in Groovy, Ruby, Javascript or Python (with JRuby, Rhino, or Jython)? In this framework I allow the user to navigate in the StackTrace in the script – Hervé Girod Commented Apr 2 at 14:16
Add a comment  | 

1 Answer 1

Reset to default 1

I understood how to do it. Rather than:

IRubyObject io = adapter.eval(runtime, <scriptContent>);

I have to do:

JavaEmbedUtils.EvalUnit evalUnit = adapter.parse(runtime, <scriptContent>, <file name>, 1);
IRubyObject io = evalUnit.run();

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744764657a4592385.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信