Code
Execute code in an event.
SEL has built-in support for running blocks of code using the following syntax:
"my_code": =Code(```python
print ("Hello, world!")
```)
Note the following:
- The entire code block should be placed inside triple ` marks.
- The language of choice should follow the first ```.
While in experimental mode, rather than a return
statement, Code
events return values using a single print statement.
Supported languages: python
, php
, javascript
, typescript
, and ruby
.
PHP code should be wrapped in <?php
?>
inside the code block.
"my_php": =Code(```php
<?php
echo "Hello, world!";
?>
```)
Casting
If the printed object can be turned into a valid dictionary, number, list, or string, it will be. These objects may only contain literals (not executable code). If a printed object cannot be converted into a literal representation, it will simply return its string representation.
Libraries
In addition to each language's standard library, the following libraries may be imported.
Language | Libraries | Version |
---|---|---|
Python | Standard, plus requests , numpy , pillow | 3.12.0 |
JavaScript / TypeScript | Standard, plusfetch , JSON | Boa , TypeScript via wsc |
PHP | Standard-only | 8.2.6 |
Ruby | Standard-only | 3.3.0 |
Updated 3 months ago