I was right. You can use a mesh as a general clip. Render the stuff to an image. Then define the mrsh to cover the region you want to see, and it clips the image to the mesh.
img = image(100,100)
for i = 1,100 do
for j = 1,100 do
img:set(
i,
j,
color(math.floor(i*2.55),0,math.floor(j*2.55),255)
)
end
end
setContext(img)
strokeWidth(5)
stroke(0, 255, 27, 255)
noFill()
line(1,1,100,100)
line(1,100,100,1)
stroke(255, 0, 251, 255)
line(50,1,50,100)
stroke(255, 242, 0, 255)
line(1,50,50,1)
line(50,1,100,50)
rect(30,30,40,40)
tex = mesh()
tex.texture = img
local v = {}
local t = {}
local s = 10
for i = 1,360,s do
table.insert(v,vec2(50*math.cos(math.rad(i)), 50 *math.sin(math.rad(i))))
table.insert(v,vec2(50*math.cos(math.rad(i-s)), 50 *math.sin(math.rad(i-s))))
table.insert(v,vec2(0,0))
table.insert(t,vec2(.5 + .5*math.cos(math.rad(i)), .5 - .5*math.sin(math.rad(i))))
table.insert(t,vec2(.5 + .5*math.cos(math.rad(i-s)), .5 - .5 *math.sin(math.rad(i-s))))
table.insert(t,vec2(0.5,0.5))
end
tex.vertices = v
tex.texCoords = t
That lot goes in setup. Then draw the mesh in the draw routine.