Re: Loading .java Files
"David Lee" <[email protected]> Sun, 26 Jun 2011 11:11:45 -0400
| Newsgroups | gmane.comp.java.beanshell.user |
|---|---|
| Message-ID | <[email protected]> |
> It is similar to java but it is not identical to java.
> Using a Java IDE is useful but if it thinks your editing
> beanshell code it
> will give you false information.
Hm, this I do not understand.
------------
BSH has java-incompatible syntax. A IDE that is expecting java will
produce errors when given bsh code that doesn't conform to java.
For example a method with no class. Or using the {} notation to access a
Hash or bsh iterators, typeless variables, closers and anything else in bsh
which isnt java.
========================
Cool feature! But it seem that this does not work, when the bsh-.script is
in a class
Runnable r =(Runnable)interpreter.getInterface(Runnable.class);
r.run();
=============
It "works" exactly how its supposed to work, just not how *you* want it to
work.
See above notes about how bsh is not java.
======================================
In the moment I help me out be removing "... class ... {" and the last "}"
from the script before I load it into the interpreter. Not that elegant ;)
Thank you!
P.S. Is bsh still under development?
================================================
bsh is what it is. If you believe that is 'Not that elegant' that's an
opinion.
But realize that bsh was specifically designed to be a scripting language,
not java.
Thus its syntax is intentionally simplier. It has a feature of allowing
some subset of java syntax,
but thats not the full intent.
Its not that you have to remove "class { ... }" to get something to "work"
but rather what bsh requires for the language and API it supplies is not
java, it doesn't need the "class" ...
That is 'elegant' or 'inelegant' depending on your opinion or expectations.
You can have both worlds by exposing a global method that calls your class
method.
This is a very common thing. Keep 'pure java' code in a seperate file (in
fact it can be compiled into your app),
then expose the *bare minimum* as bsh code.
eg.
foo.java
===========
class Foo {
void bar() { do somethign ; }
};
===========
foo.bsh
============
bar() {
new Foo().bar();
}
=================
now you can call "bar" directly from BSHMethod.invoke
And no, the original bsh is no longer in development, but 'beanshell2' was
forked and is in development by another set of authors.
----------------------------------------
David A. Lee
[email protected]
http://www.xmlsh.org
------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2