Pants. Serializing the action stack is going to be tricky, since it's a pile of functions (and closures).

One fix is to write a language - based on lox or mal - and have the ui save instructions in those terms.

let r = rectangle(10, 10, 35, 60)
set r lineWidth 2
set r strokeStyle "green"
draw r

// useful for humans, not sure if would ever be generated
set globalStyle {lineWidth: 4, strokeStyle: "brown" }
for (let r = 10; r <= 50; r += 10)
  let c = circle(25, 25, r)
  draw c
done

I don't think we need a full on VM, but a parser to build an ast, and then a visitor to execute - jlox, but in JavaScript and maybe a little stripped down (but also with object literals).

Worth a try, I haven't been through jlox in a while.


(of course, if we don't need humans to be able to read/write it, mal is probably easier to code, maintain, and extend, but I've got a picture in my head of me messing about in a console and that feels easier in lox. Mental note: leave space for pluggable languages)


To remember your current position in the blog, this page must store some data in this browser.

Are you OK with that?