It is not by chance that Lua avoids too many syntactical constructs.
They are hard to be represented in the C API.
If "with" is syntax sugar on top of scoped vars then a representation in the C API isn't needed.
The benefits of "with" syntax are related to readability: 1) it's clear by code structure that a resource is open, and 2) named variables can be elided in many cases, e.g.:
with my_lock:scoped() do ... end
Proposed pseudocode for "with":
Awithstatement like
withexp_1, ···,exp_ndoblockend
is equivalent to the code:
do
local scoped var_1, ···, var_n =exp_1, ···, exp_n
block
end
where var_iare invisible.
A with ...as statement like
withexp_1, ···,exp_n as var_1, ..., var_ndoblockend