JRuby, JSR 223 & Lua

Hi JRuby users,

I’m testing/benchmarking the scripting possibilities jruby offers to
ruby programmers through the java JSR 223 interface. I’m using JRuby
1.6.6 in Ruby 1.9 mode.

Everything works fine for javascript and jruby engines, but I’m unable
to make it work for Lua, with the JNLUA library. I always get the
error:

NativeException: java.lang.UnsatisfiedLinkError: no jnlua52 in 

java.library.path
(root) at jsr223.rb:12

The code I’m using is the following:

require 'java'
require 'benchmark'

require './jnlua-1.0.2.jar'

input = 10
many = 10

mgr = javax.script.ScriptEngineManager.new
js_engine = mgr.getEngineByName("javascript")
jruby_engine = mgr.getEngineByName("jruby")
lua_engine = mgr.getEngineByName("lua")

Benchmark.bm do |show|

  show.report("javascript:") {
    many.times do
      script = "  function factorial(n) {
                if (n == 0) {
                    return 1;
                }
                return n * factorial(n - 1);
            }
            factorial(#{input})"
      js_engine.eval(script)
    end
  }

  show.report("lua       :") {
    many.times do
      script = "  function factorial(n)
              if n == 0 then
                return 1
              else
                return n * factorial(n - 1)
              end
            end
            factorial(#{input})"
      lua_engine.eval(script)
    end
  }

  show.report("jruby:     ") {
    many.times do
      script = "  def factorial(n)
                if n == 0
                    1
                else
                    n * factorial(n - 1)
                end
            end
            factorial(#{input})"
      jruby_engine.eval(script)
    end
  }

  show.report("ruby:      ") {
    many.times do
      script = "  def factorial(n)
                if n == 0
                    1
                else
                    n * factorial(n - 1)
                end
            end
            factorial(#{input})"
      eval(script)
    end
  }

end

I’ve tried launching the script in different ways, like:

jruby -J-Djava.library.path=./ jsr223.rb

… but no luck.

Any idea what happens here?

Thanks!

Well, this isn’t a JRuby issue, but it looks like the JSR223 binding
for Lua (which appears to use a native library) can’t find the
extension. Check that java.library.path contains a path to that
library, etc.

  • Charlie

On Mon, Feb 20, 2012 at 2:34 PM, Philippe L.