Re: [ANN] Lua 5.4.0 (alpha) now available
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: [ANN] Lua 5.4.0 (alpha) now available
- From: Francisco Olarte <folarte@...>
- Date: 2019年6月21日 20:07:52 +0200
On Thu, Jun 20, 2019 at 9:18 PM Soni "They/Them" L. <fakedme@gmail.com> wrote:
>
>
>
> On 2019年06月20日 4:06 p.m., Hugo Musso Gualandi wrote:
> local <with> foo = bar --> calls bar's __enter metamethod?
> end --> calls bar's __exit metamethod?
>
> this also has the benefit of handling nested scopes as well, I guess?
I think it's not need and has several problems. 1st, bar can be an
expression, and in my normal use cases it will be, normally tings like
file.open("whatever") or similar.
Also, __enter__ functionality can be easily made by things like
self-returning method, and it makes the code more explicit and easier
to read, i.e. things like "local <toclose> p = ref_counter:ref() (
where in my use case, ref_counter:ref incrementes self:ref_count,
ref_counter:unref decrements it and calls self:no_refs() if it goes to
zero, and __close calls unref )
Also, Lua has nested scopes IIRC, that's what do-end is for, it's even
documented as useful to control variable scope.
Francisco Olarte.
>