[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Question on <close>
- From: DarkWiiPlayer <darkwiiplayer@...>
- Date: Sat, 16 May 2020 09:16:40 +0200
to-close-variables are always constant, so that alone is a reason why
this would just complicate things. Also consider that not all values are
immediately stored into variables; what happens when a value with a
__close() metamethod is returned from a function? Will it get closed the
next time it gets assigned to a variable? if so, it'd be incredibly easy
to break things, for example if some line like `return new_whatever()`
gets turned into `local temp = new_whatever(); if foo(temp) then return
temp else do_something_else() end`. Suddenly the value gets closed
before it's returned and the user gets a closed file, closed socket or
whatever and nobody knows why the code doesn't work anymore.
I don't really like the `<close>` syntax myself, but it's a reasonable
compromise of readability and predictability so beyond maybe changing
the `<>` to something else based on my subjective sense of aesthetics,
there's not much I'd change about how this works.
On 16/05/2020 05:13, Andrea wrote:
> The existence of __close() metamethod (not nil) should make the
> attribute <close> redundant
>
> When a variable holds a value which has a metatable where __close is
> not nil then when the variable goes out of scope that value is closed
>
> That would make the postfix attribute <close> redundant
>
> But I am sure I am missing something. Can someone clarify why there is
> the need for <close>?
>
> Andrea
> --
> Andrea Vitali
>
>
>
>
>
>
>
> _______________________________________________
> lua-l mailing list -- lua-l@lists.lua.org
> To unsubscribe send an email to lua-l-leave@lists.lua.org
Attachment:
signature.asc
Description: OpenPGP digital signature
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org