You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+11-3Lines changed: 11 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -418,19 +418,27 @@ panic(err)
418
418
```
419
419
420
420
### ⚠️ Unsafe
421
-
It's possible to add native code directly to the output by using the *unsafe*-builtin. However, this should be avoided if possible as it can introduce unwanted side-effects. The builtin's first argument must be a string literal which contains the executable code. All other arguments can be of type *bool*, *int* or *string*. The transpiler parses the string literal and replaces all placeholders (e.g. {0}) with the corresponding positional argument. Then the code is added to the output. E.g.
421
+
It's possible to add native code directly to the output by using the *unsafe*-builtin. However, this should be avoided if possible as it can introduce unwanted side-effects. The builtin's first argument must be a string literal which contains the executable code. All other arguments can be of type *bool*, *int* or *string*. The transpiler parses the string literal and replaces all placeholders (e.g. {0}) with the corresponding positional argument at transpile time.
422
+
423
+
To pass data into the native code, placeholders with either only the positional number (e.g. "{0}") or "i:" followed by the positional number (e.g. "{i:0}") should be used.
424
+
425
+
To get data out of the native code, placeholders with "o:" followed by the positional number must be used. **IMPORTANT**: The passed expression must be a variable.
426
+
427
+
In the following example, the variable *file* is passed as input to the native Batch code, while the variable *date* is passed as output argument. After the execution, *date* holds the value evaluated by the native code.
422
428
423
429
```golang
424
430
file:="test.tsh"
431
+
vardatestring
425
432
426
-
unsafe(`for %%U in ({0}) do (@echo %%~tU)`, file)
433
+
unsafe(`for %%U in ({i:0}) do (set "{o:1}=%%~tU")`, file, date)
0 commit comments