Interesting things about the Lua interpreter (2020)
I&#x27;d love to see upvalues diagrammed as they are represented in memory.<p>It sounds like the stack is perhaps a Stack&lt;Frame pointer¹&gt;, where each Frame contains the locals for that stack frame; then a coroutine just needs to keep a pointer to the stack frame it is closing over. (And then, Frame does too, recursively, incase there is more than one scope being closed over.)<p>This would be extremely similar to … most any other language … and makes me wonder why Lua gives them such a unique name. It has been hard to really comprehend the Lua spec, when I&#x27;ve tried to understand that facet of it.<p>(I&#x27;d also argue that Lua isn&#x27;t as simple as it is made out to be: primitives behave wildly different from objects, there&#x27;s the 1-based indexing, multiple-return is pretty much unique to Lua (vs. returning a tuple, which other languages such as Python, Rust, and sort-of JS, go for; I think that&#x27;s conceptually simpler).)<p>¹and note &quot;pointer&quot; here might really be &quot;GC ref&quot;, to permit these to be GC&#x27;d as necessary, as closures can keep stuff alive far longer than normal.