How to import a js script in an other script ???

19 views
Skip to first unread message

Livio Saracino

unread,
Nov 19, 2016, 9:33:02 AM11/19/16
to Icy imaging
Hello ! 
would be possible import/include a script in an other script ?

for example would be helpfull writing some functions in a script and then use them in an other script.
Thanks in advance !!

Osvaldo Fuica

unread,
Nov 21, 2016, 12:00:25 PM11/21/16
to Icy imaging
Hello Livio, 

You could use ScriptEngineManager, is an entity that is defined inside of javax package. I let you an example for you.

Invoker javascript script; (Use it in the ScriptEditor window inside Icy)

importClass(javax.script.ScriptEngineManager)

importClass(java.io.BufferedReader)

importClass(java.io.FileReader)


mgr = new ScriptEngineManager()

jsEngine = mgr.getEngineByName("JavaScript")

br = new BufferedReader(new FileReader("/tmp/test.js"))

var line = ""

var allLines = ""

while( (line = br.readLine()) != null ) {

  allLines += line + "\n"

}

jsEngine.eval(allLines)



So, for this example I have put test.js in my /tmp/ system folder:

test.js file:

print ('Hello')
print ('World')

Output:

Hello

World


This can help you to get your needs done, but I think that Icy could in the future give you a more easy interface to get this working easy.

If you would like to broad your knowledge in the javascript world, you could visit this url:


Cheers.

Osvaldo
Reply all
Reply to author
Forward
0 new messages