Skip to content

Commit 3e6e32c

Browse files
committed
Describe more Lua FAQ: template escaping and empty query results
Related issue #1343 and PR #1359
1 parent 57c4317 commit 3e6e32c

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

website/Space Lua.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ A new syntax introduced with Space Lua is the `${lua expression}` syntax that yo
5757

5858
For example: 10 + 2 = ${adder(10, 2)} (Alt-click, or select to see the expression) is using the just defined `adder` function to this rather impressive calculation.
5959

60+
Note that you can have the text {lua expression} in your page and it won't be evaluated. So writing `${"$"}{lua expression}` can be used to “delay” evaluation by one pass, for example to escape expressions in templated content.
61+
6062
## Queries
6163
Space Lua has a feature called [[Space Lua/Lua Integrated Query]], which integrate SQL-like queries into Lua. Here’s a small example querying the last 3 modifies pages:
6264

@@ -127,10 +129,17 @@ There's a magic `_CTX` global variable available from which you can access usefu
127129
# Lua implementation notes
128130
Space Lua is intended to be a more or less complete implementation of [Lua 5.4](https://www.lua.org/manual/5.4/). However, a few features are (still) missing:
129131

130-
* `goto` and labels (not planned, goto considered harmful)
131-
* coroutines (not planned, not useful in the SilverBullet context)
132-
* _ENV (planned)
133-
* Full metatable support (only partial now, planned)
132+
## Differences
133+
* empty table `{}` tests false, while in [Lua 5.4](https://www.lua.org/manual/5.4/manual.html#3.3.4) "All values different from **nil** nad **false** test true". However this has a really nice interaction with empty [[Space Lua/Lua Integrated Query|query]] results
134+
135+
## Planned
136+
* _ENV
137+
* Full [metatable](https://www.lua.org/manual/5.4/manual.html#2.4) support (only partial now)
138+
* Complete [[API/string]] API (some patterns in `gmatch` don’t work correctly)
139+
140+
## Not planned
141+
* `goto` and labels (goto considered harmful)
142+
* coroutines (not useful in the SilverBullet context)
134143
* Hexadecimal numeric constants with a fractional part, or binary exponents (not supported by JavaScript number parser either)
135144

136145
# Frequently Asked Questions

website/Space Lua/Lua Integrated Query.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ ${query[[
2828
limit 3
2929
]]}
3030

31+
Due to SilverBullet’s [[Space Lua#Differences|handling of empty tables]] you can easily write a message to show when results are empty:
32+
33+
${query[[
34+
from p = index.tag "page"
35+
limit 0
36+
]] or "No results"}
37+
3138
# Clauses
3239
Here are the clauses that are currently supported:
3340

0 commit comments

Comments
 (0)