String sum = "function sum(int a,int b){\n" +
" return a+b;\n" +
"};\n";
runner.addMacro("bbb", sum);
runner.addFunctionOfServiceMethod("add", new BindObjectMethod(), "add",
new Class[] { Integer.class, Integer.class }, null);
DefaultContext<String, Object> context = new DefaultContext<String, Object>();
// context.put("a", 1);
// context.put("b", 2);
String express = "add(1,2);bbb;sum(1,22)";
Object r = runner.execute(express, context, null, true, false);
System.out.println(r);
@Test
public void testFunction2() throws Exception {
ExpressRunner runner = new ExpressRunner();
String[] args = {"123","456"};
String exp = "String a = args[0];";
DefaultContext<String, Object> context = new DefaultContext<String, Object>();
context.put("args", args);
Object result = runner.execute(exp,context,null,false,true);
System.out.println(result);
}
@Test
public void testFunction2() throws Exception {
ExpressRunner runner = new ExpressRunner();
String[] args = {"123","456"};
String exp = "a = args[0];";
DefaultContext<String, Object> context = new DefaultContext<String, Object>();
context.put("args", args);
Object result = runner.execute(exp,context,null,false,true);
System.out.println(result);
}