You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Dishara Wijewardana <dd...@gmail.com> on 2012/06/16 17:33:34 UTC

Velocity back end implementation which invokes script functions

Hi all,

May I know what is the API/methods used to call from Velocity classes to
call the defined methods/functions in a velocity script.
In  JSR 223 there is a class called Invocable. Appreciate any links to go
through and understand.

In case I have not made this clear, let me give a example code block in
JSR223 compliant implementation(i.e groovy.)

ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine
engine = factory.getEngineByName("groovy"); String script = "def adder(a,b)
{return a+b }"; engine.eval(script); *Invocable inv = (Invocable)
engine;*Object[] params = {
new Integer(5),new Integer(3) };
Object result = *inv.invokeFunction(**"adder"**, params)*;

which will be result in 8 .

Thanks

-- 
Thanks
/Dishara

Re: Velocity back end implementation which invokes script functions

Posted by Dishara Wijewardana <dd...@gmail.com>.
On Tue, Jun 19, 2012 at 4:01 PM, Claude Brisson <cl...@renegat.net> wrote:

> I'm not sure that there is a real interest in trying to implement the
> Invocable interface. It is an optional feature, I think we can leave it
> aside for now.
>
> OK, +1 for that .

>
>  Claude
>
> On Sat, 16 Jun 2012 21:03:34 +0530
> Dishara Wijewardana <dd...@gmail.com> wrote:
>
> > Hi all,
> >
> > May I know what is the API/methods used to call from Velocity classes
> > to call the defined methods/functions in a velocity script.
> > In  JSR 223 there is a class called Invocable. Appreciate any links
> > to go through and understand.
> >
> > In case I have not made this clear, let me give a example code block
> > in JSR223 compliant implementation(i.e groovy.)
> >
> > ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine
> > engine = factory.getEngineByName("groovy"); String script = "def
> > adder(a,b) {return a+b }"; engine.eval(script); *Invocable inv =
> > (Invocable) engine;*Object[] params = {
> > new Integer(5),new Integer(3) };
> > Object result = *inv.invokeFunction(**"adder"**, params)*;
> >
> > which will be result in 8 .
> >
> > Thanks
> >
>
>


-- 
Thanks
/Dishara

Re: Velocity back end implementation which invokes script functions

Posted by Claude Brisson <cl...@renegat.net>.
I'm not sure that there is a real interest in trying to implement the
Invocable interface. It is an optional feature, I think we can leave it
aside for now.


  Claude

On Sat, 16 Jun 2012 21:03:34 +0530
Dishara Wijewardana <dd...@gmail.com> wrote:

> Hi all,
> 
> May I know what is the API/methods used to call from Velocity classes
> to call the defined methods/functions in a velocity script.
> In  JSR 223 there is a class called Invocable. Appreciate any links
> to go through and understand.
> 
> In case I have not made this clear, let me give a example code block
> in JSR223 compliant implementation(i.e groovy.)
> 
> ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine
> engine = factory.getEngineByName("groovy"); String script = "def
> adder(a,b) {return a+b }"; engine.eval(script); *Invocable inv =
> (Invocable) engine;*Object[] params = {
> new Integer(5),new Integer(3) };
> Object result = *inv.invokeFunction(**"adder"**, params)*;
> 
> which will be result in 8 .
> 
> Thanks
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@velocity.apache.org
For additional commands, e-mail: dev-help@velocity.apache.org