I'd like to make a JS wrapper around the repl of another language.
For example:
let a = otherLang`10`let b = otherLang`{ c = 11; d = 12; }`;console.log(b.c) // 11
let a = otherLang`10`let b = otherLang`{ c = 11; d = 12; }`;console.log(b.c) // 11
I can spawn a repl in a subprocess, keep it open and hook into the stdin/out/err of it. Then the idea would be to do something like the following:
otherLang`{ c = 11; d = 12; }`// roughly becomeschild.stdin.write(` print(json(listAttrNames( { c = 11; d = 12; } ))) print(${endUuid})`)while (1) { child.stdout.read() // until endUuid}
otherLang`{ c = 11; d = 12; }`// roughly becomeschild.stdin.write(` print(json(listAttrNames( { c = 11; d = 12; } ))) print(${endUuid})`)while (1) { child.stdout.read() // until endUuid}
The problem is something like that^ needs to run inside of a getter for
console.log(b.a)
console.log(b.a)
to work. E.g. no async.
I can do some incredibly hacky work, like funneling stdout to a file and then sync-reading (.seek()) the file over and over. But surely there's a better way.