lua-users home
lua-l archive

Re: (not) handling new programming idioms with grace

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


Hi,
On 18-07-2018 20:26, Sean Conner wrote:
It was thus said that the Great Dibyendu Majumdar once stated:
On 18 July 2018 at 17:19, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
We had something (scope-qualified locals) that seemed to be enough.
Now we have this list of problems:
- It does not create a new scope by itself;
- It is not visible enough;
- It still does not solve the problem for global variables;
- It cannot supress exceptions.
Perhaps something simpler could be done? Such as ask a function to be
called on scope exit (normally or via exception) - similar to defer
statement in Go?
Then user code can do what it likes in that function - responsibility
of Lua ends with invoking the function.
 It could be done now, although not automatically:
	function hoover(...)
	 for i = 1 , select('#',...) do
	 local obj = select(i,...)
	 local mt = getmetatable(obj)
	 if mt and mt.__gc then
	 mt.__gc(obj)
	 end
	 end
	end
	do
	 local expensive = foo_user_obj()
	 local cheap = {}
	 local medium = setmetatable({},{ __gc = function(o) end })
Could a "scope" arg for __gc solve "the immediate release resource"
problem?
ie:
local medium = setmetatable({},{
 __gc = function(o, scope)
 if scope == "local" then ... end
 end })
	 hoover(expensive,cheap,medium)
	end
 -spc (Must ... avoid ... proposing ... new ... metamethod ... )
--
Regards,
Hakki Dogusan

AltStyle によって変換されたページ (->オリジナル) /