Skip to content

Commit a1d1e1a

Browse files
committed
feat(playground): execute code pasted in url
1 parent 1009757 commit a1d1e1a

2 files changed

Lines changed: 65 additions & 2 deletions

File tree

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,44 @@ rayforce-wasm/
170170
└── examples/ # Usage examples
171171
```
172172

173+
## Zulip Code Playground Integration
174+
175+
The playground supports URL query parameters for integration with [Zulip's code playgrounds](https://zulip.com/help/code-blocks#code-playgrounds) feature.
176+
177+
### URL Format
178+
179+
```
180+
https://your-playground-url/?code=<URL-encoded-expression>
181+
```
182+
183+
### Setting up in Zulip
184+
185+
1. Go to **Organization settings****Code playgrounds**
186+
2. Add a new playground:
187+
- **Language**: `rayfall` (or `rayforce`, `lisp`)
188+
- **Name**: `RayforceDB Playground`
189+
- **URL template**: `https://rayforcedb.github.io/rayforce-wasm/?code={code}`
190+
191+
### Example
192+
193+
When a user writes a code block like:
194+
195+
````markdown
196+
```rayfall
197+
(sum (til 100))
198+
```
199+
````
200+
201+
Clicking the playground button will open the RayforceDB WASM playground and automatically execute the expression.
202+
203+
### Multi-line Code
204+
205+
The playground handles multi-line code by executing each line sequentially:
206+
207+
```
208+
https://playground-url/?code=(def%20x%2010)%0A(sum%20(til%20x))
209+
```
210+
173211
## Performance Notes
174212

175213
- Built with `-O3` and `-msimd128` for SIMD acceleration

examples/index.html

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,10 @@ <h2>Try these examples</h2>
727727

728728
input.disabled = false;
729729
input.focus();
730-
730+
731+
// Execute any code passed via URL (Zulip code playground)
732+
executeUrlCode();
733+
731734
} catch (err) {
732735
setStatus('error', 'Failed to load');
733736
log(`Error: ${err.message}`, 'error');
@@ -773,7 +776,29 @@ <h2>Try these examples</h2>
773776
}
774777
});
775778
});
776-
779+
780+
// Parse URL query parameters for Zulip code playground integration
781+
function getCodeFromUrl() {
782+
const params = new URLSearchParams(window.location.search);
783+
return params.get('code');
784+
}
785+
786+
// Execute code from URL after initialization
787+
function executeUrlCode() {
788+
const code = getCodeFromUrl();
789+
if (code && rayforce) {
790+
log('Executing code from URL...', 'system');
791+
// Handle multi-line code (newlines may be encoded)
792+
const lines = code.split('\n');
793+
for (const line of lines) {
794+
const trimmed = line.trim();
795+
if (trimmed) {
796+
evaluate(trimmed);
797+
}
798+
}
799+
}
800+
}
801+
777802
// Initialize
778803
initRayforce();
779804
</script>

0 commit comments

Comments
 (0)