This library is similar to my nashorn and python libs, but allows you to use ruby from b4j.
The library has the same format as the other two
it needs #AdditionJars: path/to/your/jRuby.jar
If you want to call a sub in your b4j app - you need to add some code to both the ruby script and b4j app
Ignore the rubyLibs function at present, it does nothing.
You need to download jRuby ( I am using ver 9.1.8.0)
The library has the same format as the other two
it needs #AdditionJars: path/to/your/jRuby.jar
B4X:
' in globals
Dim jr As jInvokeRuby
...
jr.InitInvocable("some/path/to/your/ruby/file.rb")
'or
jr.InitInvocable(aStringContainingTheScript)
...
jr.Invoke("theFunction",array(the,list,of,parameters)) ie def test(a,b,c,d)
or
jr.Invoke("theFunction",null) ' no args ie def test()
If you want to call a sub in your b4j app - you need to add some code to both the ruby script and b4j app
B4X:
' for b4j app
...
Dim s As String = Me
s = s.Replace("class ","")
jr.Invoke("setB4J",Array(s)) ' this sets a global variable in the ruby script
'call it before you call functions in the b4j app
...
' for the ruby script at start of script
require "java"
@b4j = ""
...
' and add this function somewhere in the script
def setB4J(a)
@b4j = JavaUtilities.get_proxy_class(a)
end
' now you can call public subs in current class with
def test2()
@b4j._externalcall("hello from jruby") ' calls Sub externalCall(s As String)
' note the _ before the lowercase name
end
'or access global variables
def test3()
@b4j._yourglobalvariable = "hello" ' etc
end
Ignore the rubyLibs function at present, it does nothing.
You need to download jRuby ( I am using ver 9.1.8.0)
Attachments
Last edited: