Skip to content

Commit b945de5

Browse files
committed
Fix eval() not returning some script results
Fix `eval()` not returning the resulting script string if the script consists of a `__statements__()` node with one child, which could be an expression that leads to a value. Example that is fixed by this change: `msg(eval(dyn('bind(\'shutdown\', null, null, @e, msg(123))')))`
1 parent 0f1c96c commit b945de5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/main/java/com/laytonsmith/core/functions/DataHandling.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
import com.laytonsmith.core.functions.ArrayHandling.array_push;
9494
import com.laytonsmith.core.functions.ArrayHandling.array_set;
9595
import com.laytonsmith.core.functions.Compiler.__autoconcat__;
96+
import com.laytonsmith.core.functions.Compiler.__statements__;
9697
import com.laytonsmith.core.functions.Compiler.__type_ref__;
9798
import com.laytonsmith.core.functions.Compiler.centry;
9899
import com.laytonsmith.core.natives.interfaces.Mixed;
@@ -3714,6 +3715,15 @@ public Mixed execs(Target t, Environment env, Script parent, ParseTree... nodes)
37143715
if(root == null) {
37153716
return new CString("", t);
37163717
}
3718+
3719+
// Unwrap single value in __statements__() and return its string value.
3720+
if(root.getChildren().size() == 1 && root.getChildAt(0).getData() instanceof CFunction
3721+
&& ((CFunction) root.getChildAt(0).getData()).getFunction().getName().equals(__statements__.NAME)
3722+
&& root.getChildAt(0).getChildren().size() == 1) {
3723+
return new CString(parent.seval(root.getChildAt(0).getChildAt(0), env).val(), t);
3724+
}
3725+
3726+
// Concat string values of all children and return the result.
37173727
StringBuilder b = new StringBuilder();
37183728
int count = 0;
37193729
for(ParseTree child : root.getChildren()) {

0 commit comments

Comments
 (0)