ScriptModule - bugfixes

Sven Reimers has found a major bug in the NetBeans scripting module. The script engines were not initialize when you open a script console; so when you entered any command, the script engine will choke. I've fixed the problem. Thanks Sven.

While was using the jython script engine to test the console and I found a few problems with jython

  • The jython engine does not honour the classloader in the ScriptEngineManager. The ScriptEngineManager allows you to associate a classloader when you are instantiating it. The idea is to be able to load and create script engines dynamically. I can get a reference to Jython's script engine but when I tried to execute a statement, print(“hello world”), I got a class not found exception on PyRunnable. I was pretty sure that PyRunnable was in the URLClassloader's path that I passed to ScriptEngineManager. Another Sun colleague, Sundar has told me the workaround but I completely forgot about it. It is not enough to have the jython's Jars in the classloader, you have to explicitly set the classloader to the current thread's context classloader.

  • I could not redirect jython's output to the console. There is a method in the ScriptContext call setWriter that allows you to redirect the engine's output to wherever you like. Again, jython is not honouring this. So the output is displayed to System.out. For those who are using the console, I suggest you write a globals.py file; stick this under console directory. In globals.py redirect all output to Console.println(). Console is an exported object. See the help for more details

  • The jython engine comes with a set of Python libraries. You can find this under jython_home/lib/python. I do not know Python to test out the environment, so if you are testing, please let me know how this is resolved. I know that you have to set python.path. But currently this is not set, so what is the default?

Okay, the NBMs are available here (ScriptEngine) and here (Windoows). The source is available here. Once I've got a reasonably working version, I'll upload this to http://scripting.dev.java.net site.

Comments:

Thanks for the fast response. Perhaps just a small hint - increment the version in the nbm's so anybody can easily upgrade. regarding the console - maybe the terminalemulator (NetBeans library) could help you improve it further.

Posted by Sven Reimers on July 21, 2006 at 06:55 AM SGT #

Sorry to come back to you once more with another problem. I have difficulties getting multiline statement to work such as for loops. I am still trying to figure out more details...

Posted by Sven Reimers on July 21, 2006 at 07:11 AM SGT #

Regarding python.path: you can access it from jython interpreter via

import sys
print sys.path
sys.path.append('maybePath')

hope this helps.

Posted by Sven Reimers on July 21, 2006 at 07:17 AM SGT #

Sven, the console I have currently is very simple. It does not support any continuation character. Everytime you hit enter, the console sends the line to the interpreter. Perhaps I could add \\ or _ to indicated continuation. Can you help me with trying to add a globals.py to the python console. I did some initial test and I'm seeing some really wired behaviour in the jython interpreter which I'm not seeing in rhino. Thanks.

Posted by chuk on July 22, 2006 at 05:11 AM SGT #

Post a Comment:
Comments are closed for this entry.
About

Random thought at random intervals

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today