1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-28 00:59:31 +00:00

Add "function return" and "scoped function return" injections, allow children for return lines

This commit is contained in:
Étienne Fildadut 2022-01-16 15:32:59 +01:00
parent b60f53df01
commit 933e8fb0ee
7 changed files with 131 additions and 72 deletions

View file

@ -281,15 +281,6 @@ Checkpoints always have the following variable defined in its namespace by defau
Tagged with a red color and blink.
```
#### Lines that can't have children:
* `:`: variable declaration. Followed by an [identifier](#identifiers) (with eventually an [alias](#aliases)), a `=` and an [expression](#expressions). Defines a variable with a default value and this identifier in the current [namespace]("identifiers"). The expression is not evaluated instantly, but the first time the variable is used.
```
:foo = 42
:bar : alias = 12
```
* `@`: return line. Can be followed by an [expression](#expressions); otherwise nil expression is assumed. Exit the current function and returns the expression's value.
```
@ -299,6 +290,23 @@ $ hey
{hey} = 5
```
If this line has children, they will be ran _after_ evaluating the returned expression but _before_ exiting the current function. If the children return a value, it is used instead.
```
(Returns 0 and print 5)
$ fn
:i=0
@i
~ i:=5
{i}
(Returns 3)
$ g
@0
@3
```
Please note that Anselme will discard returns values sent from within a choice block. Returns inside choice block still have the expected behaviour of stopping the execution of the choice block.
This is the case because choice blocks are not ran right as they are read, but only at the next event flush (i.e. empty line). This means that if there is no flush in the function itself, the choice will be ran *after* the function has already been executed and returning a value at this point makes no sense:
@ -315,7 +323,15 @@ $ f
Yes.
(Choice block is actually ran right before the "Yes" line, when the choice event is flushed.)
```
#### Lines that can't have children:
* `:`: variable declaration. Followed by an [identifier](#identifiers) (with eventually an [alias](#aliases)), a `=` and an [expression](#expressions). Defines a variable with a default value and this identifier in the current [namespace]("identifiers"). The expression is not evaluated instantly, but the first time the variable is used.
```
:foo = 42
:bar : alias = 12
```
* empty line: flush the event buffer, i.e., if there are any pending lines of text or choices, send them to your game. See [Event buffer](#event-buffer). This line always keep the same identation as the last non-empty line, so you don't need to put invisible whitespace on an empty-looking line. Is also automatically added at the end of a file.