feat: add mondough package to run strudel via mondo

This commit is contained in:
Felix Roos 2025-03-16 10:49:18 +01:00
parent 11196fb1e6
commit fae59a6bcd
No known key found for this signature in database
8 changed files with 221 additions and 5 deletions

View file

@ -0,0 +1,35 @@
import { strudelScope, reify, fast, slow, isControlName } from '@strudel/core';
import { MondoRunner } from '../mondo/mondo.mjs';
let runner = new MondoRunner(strudelScope, { pipepost: true });
//strudelScope.plain = reify;
strudelScope.plain = (v) => {
// console.log('plain', v);
return reify(v);
// return v;
};
// strudelScope.number = (n) => n;
strudelScope.number = reify;
strudelScope.call = (fn, args, name) => {
const [pat, ...rest] = args;
if (!['seq', 'cat', 'stack'].includes(name)) {
args = [...rest, pat];
}
// console.log('call', name, ...flipped);
return fn(...args);
};
strudelScope['*'] = fast;
strudelScope['/'] = slow;
export function mondo(code, offset = 0) {
if (Array.isArray(code)) {
code = code.join('');
}
const pat = runner.run(code, { pipepost: true });
return pat;
}