Conversation
Implements multi-statement `${...}` expressions. The following works:
```
${a = 1; a}
${local a = 1; a}
```
but not (and should not):
```
${a = 1; a;}
${local a = 1; a;}
```
Also `return` works now:
```
${a = 1; return a}
${a = 1; return a;}
```
Also parenthesized expressions work:
```
${a = 1; local b = 2; (a + b)}
```
And anonymous function call works:
```
${(function()return 1;end)()}
```
And even global and local function definitions work:
```
${a = function(b)return 10*b;end; a(3)}
${a(5)}
${local b = function(c)return 10*a(c)end; b(3)}
```
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
Interpolation blocks split across multiple lines (e.g.,
`table\n.includes(...)`) failed because only the last separator was
tried as a split point. Now all `;` and `\n` separators are collected
and tried RTL until a valid parse is found.
Additionally, trailing semicolons (e.g. `${a(5);}`) caused implicit
return to be skipped because the last AST node was a `Semicolon` rather
than the preceding `FunctionCallStatement`. The return logic now skips
trailing semicolons to find the last statement.
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
|
What I don't understand is why this would work (haven't checked it myself, but you claim it does): What is the scope of The reason I'm asking is that I was toying with the idea of "page variables" specifically for these Lua expressions, so you could do things like this: Then when you change multiplier to something else, it would propagate, basically give you a type of spreadsheet-like behavior. Does this do that? Somehow? |
That's how it is supposed to work. The first assignment will return Note: not yet, it works like that but the values don't get updated instantly, you have "run over it" to get updated values, or do reload or something. Not sure, this is not my domain, you may know. I also think there may be some issues with ordering (and I am quite sure there are). If these things were fixed then it would be splendid. I dunno how myself atm. Many things and layers are involved. |
|
Right, so by default the behavior will indeed seem kind of random based on the ordering that CodeMirror decides on. To make what I envisision (page scope) work, when you live preview something, have to find all other lua directives on the page as well, and evaluate them in sequence (with a "page environment" as env, so not to leak into the global space lua global environemnt) up to the point where the currently live-previewing expression is being rendered... |
|
I agree with the "page-scope". |
- non-local writes stop at page boundary - reads chain to global Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
…hanges Signed-off-by: Matouš Jan Fialka <mjf@mjf.cz>
|
Not a solution. Just an illustration on what we can do with functions within a widget (you can see a more complete example here: https://github.com/Baudogit/silverbullet-libraries/blob/main/TCexport.md). But i didn't find how update instantly. |
@Baudogit Working on it. It will take it's time, sorry. The current solution is an ugly "hack" only. The part with multiline statements seems quite ok, the instant updating needs some more work and perhaps more changes elswhere. |
Implements multi-statement
${...}expressions. The following works:but not (and should not):
Also
returnworks now:Also parenthesized expressions work:
And anonymous function call works:
And even global and local function definitions work:
Multi-line works:
or (non-sensical, just to demostrate):