summaryrefslogtreecommitdiffhomepage
path: root/README.md
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-08-29 15:02:31 +0200
committerJo-Philipp Wich <jo@mein.io>2022-08-29 15:02:31 +0200
commit344fa9e69da43ecdc4d8f7768d85d42639352405 (patch)
tree156657bbf8ceb57d7b9af8a6a9f92d829263e2ee /README.md
parent89452b20e5073feb28b294a707342ef144f4b5f0 (diff)
lib: extend render() to support function values
Extend the `render()` function to accept a function value as first argument, which allows running arbitrary ucode functions and capturing their output. This is especially useful in conjunction with `loadfile()` or `loadstring()` to dynamically compile templates and rendering their output into a string. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'README.md')
-rw-r--r--README.md17
1 files changed, 12 insertions, 5 deletions
diff --git a/README.md b/README.md
index f09c71d..fba3177 100644
--- a/README.md
+++ b/README.md
@@ -1254,11 +1254,18 @@ an invalid value was passed, otherwise `true`.
Raise an exception with the given `message` parameter if the value in `cond`
is not truish. When `message` is omitted, the default value is `Assertion failed`.
-#### 6.56. `render(path[, scope])`
-
-Like `include()` but capture output of included file as string and return it.
-
-See `include()` for details on scoping.
+#### 6.56. `render(path_or_func[, scope_or_fnarg1 [, fnarg2 [, ...]]])`
+
+When invoked with a string value as first argument, the function acts like
+like `include()` but captures the output of the included file as string and
+returns the captured contents. The second argument is treated as scope. See
+`include()` for details on scoping.
+
+When invoked with a function value as first argument, `render()` calls the
+given function and passes all subsequent arguments to it. Any output
+(through print(), template text instructions and the like) produced by the
+called function is captured and returned as string. The return value of the
+called function is discarded.
#### 6.57. `regexp(source[, flags])`