From 15ac3edc19fff718ae0b3511c448fcd0076f34de Mon Sep 17 00:00:00 2001 From: gnembon Date: Sun, 3 May 2020 23:10:09 -0300 Subject: [PATCH] clarifications around 'str' --- docs/scarpet/language/SystemFunctions.md | 13 ++++++++++--- src/main/java/carpet/script/Expression.java | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/scarpet/language/SystemFunctions.md b/docs/scarpet/language/SystemFunctions.md index e25b48ba..611057d2 100644 --- a/docs/scarpet/language/SystemFunctions.md +++ b/docs/scarpet/language/SystemFunctions.md @@ -46,15 +46,22 @@ number('3bar') => null number('2')+number('2') => 4 -### `str(expr, params? ... ), str(expr, param_list)` +### `str(expr)`,`str(expr, params? ... )`, `str(expr, param_list)` -Returns a formatted string representing expression. Accepts formatting style accepted by `String.format`. -Supported types (with `"%?"` syntax): +If called with one argument, returns string representation of such value. + +Otherwise, returns a formatted string representing the expression. Arguments for formatting can either be provided as + each consecutive parameter, or as a list which then would be the only extra parameter. To format one list argument + , you can use `str(list)`, or `str('foo %s', l(list))`. + +Accepts formatting style accepted by `String.format`. +Supported types (with `"%"` syntax): * `d`, `o`, `x`: integers, octal, hex * `a`, `e`, `f`, `g`: floats * `b`: booleans * `s`: strings +* `%%`: '%' character
 str(null) => null
diff --git a/src/main/java/carpet/script/Expression.java b/src/main/java/carpet/script/Expression.java
index daf0a4cf..6d5174c5 100644
--- a/src/main/java/carpet/script/Expression.java
+++ b/src/main/java/carpet/script/Expression.java
@@ -1575,7 +1575,7 @@ public class Expression
             if (lv.size() == 1)
                 return new StringValue(format);
             int argIndex = 1;
-            if (lv.get(1) instanceof ListValue)
+            if (lv.get(1) instanceof ListValue && lv.size() == 2)
             {
                 lv = ((ListValue) lv.get(1)).getItems();
                 argIndex = 0;