lua-users home
lua-l archive

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


Hi,

On 12.07.2019 12:36, Lorenzo Donati wrote:
On 06/07/2019 17:58, Andrew Starks wrote:
[snip]

I almost feel that /there has to be a better way/ and the current way doesn't feel quite right.

For example, the fact that a /variable/ is marked, but /an object/ is "closed" (using its metamethod) is something smelly. The whole point of RAII is to make very explicit the connection between a resource and the code that handle its release and the time this code is run.
The current Lua 5.4 mechanism is not so explicit, IMO.


Seconded.

This "variable-value" thing already existed, but it becomes confusing.
IMHO solution should not touch "value/class" metatable.

Maybe something like following is better?
local a = ..
a.__on_scope_exit = function .. end

(Although I'm still thinking that similar to setmetatable, there maybe
setattribute function for variables)


For that matters, I'm beginning to feel a sort of "defer..end" block could be a better, more general, more explicit, solution.

I love Lua ability to keep the code clean (and clear) in common use cases (although it has its dark corners, e.g. the general for loop syntax - maybe it's me, but I keep forgetting what are those pesky three parameters after "in" keyword <ugh>). I'd like to stay that way.

Cheers!

-- Lorenzo