lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

I'm going to stick my neck out and propose that we can attack this from another angle.  (And I will admit from the start that this is not backed up by either code or a deep understanding of the mechanisms I'm proposing to leverage - someone else can make this work or shoot it down.)

We already have a mechanism that catches all exit paths from a function - xpcall().  And it has a way to run code - the message handler.

So what happens if we build on "do..end" to create "" (I don't like "with" and this note might be clearer if I don't use "with") that is (mostly?) syntactic sugar that transforms
into something like
	local chunk = compile CHUNK replacing return... with error( {MAGIC=_ENV,RETURN={...}} )  and error(e,lvl) with error({MAGIC=_ENV,ERROR={e,lvl})
	local finalizer = function(_ENV) FINALIZER end
	local fwrapper = function(e)
		if e.ERROR then error(e.ERROR.e, e.ERROR.lvl) else return e.RETURN end	-- unscrambling e.RETURN to .. left as an exercise for the reader
	local status, e = xpcall(CHUNK, fwrapper)
	if status then error(e) else return e end
Does this approach offer anything?