diff --git a/groovy/src/main/groovy/org/jline/groovy/Utils.groovy b/groovy/src/main/groovy/org/jline/groovy/Utils.groovy index 1ccb27335..ea5dfff76 100644 --- a/groovy/src/main/groovy/org/jline/groovy/Utils.groovy +++ b/groovy/src/main/groovy/org/jline/groovy/Utils.groovy @@ -20,7 +20,7 @@ public class Utils { private Utils() {} static String toString(Object object) { - object ? object.toString() : 'null' + object != null ? object.toString() : 'null' } static Object toObject(String json) { @@ -29,7 +29,7 @@ public class Utils { } static Map toMap(Object object) { - object ? object.properties : null + object != null ? object.properties : null } static String toJson(Object object) { diff --git a/groovy/src/main/java/org/jline/script/GroovyEngine.java b/groovy/src/main/java/org/jline/script/GroovyEngine.java index 15e1ae723..9d99c9976 100644 --- a/groovy/src/main/java/org/jline/script/GroovyEngine.java +++ b/groovy/src/main/java/org/jline/script/GroovyEngine.java @@ -18,6 +18,7 @@ import org.jline.reader.ScriptEngine; import groovy.lang.Binding; +import groovy.lang.Closure; import groovy.lang.GroovyShell; import groovy.lang.Script; @@ -165,6 +166,14 @@ public Object execute(String statement) throws Exception { return out; } + @Override + public Object execute(Object closure, Object... args) { + if (!(closure instanceof Closure)) { + throw new IllegalArgumentException(); + } + return ((Closure)closure).call(args); + } + @Override public String getEngineName() { return this.getClass().getSimpleName(); diff --git a/reader/src/main/java/org/jline/reader/ScriptEngine.java b/reader/src/main/java/org/jline/reader/ScriptEngine.java index 675d8dd88..41e446629 100644 --- a/reader/src/main/java/org/jline/reader/ScriptEngine.java +++ b/reader/src/main/java/org/jline/reader/ScriptEngine.java @@ -157,4 +157,13 @@ default Object execute(File script) throws Exception { */ Object execute(File script, Object[] args) throws Exception; + /** + * Executes scriptEngine closure + * @param closure + * @param args + * @return + * @throws Exception + */ + Object execute(Object closure, Object... args); + }