[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Another option for closing variables
- From: Sergey Kovalev <kovserg33@...>
- Date: Mon, 15 Jul 2019 12:46:51 +0300
I found the way to do it in lua without preprocessing. But only in 5.4.
There is 4-th parameter in for loop introduced in lua 5.4 so
now it look like:
require "scope54" --
https://raw.githubusercontent.com/kov-serg/lua-aux/master/scope54.lua
for auto,defer in scope() do
defer(function() print"defer" end)
local f=auto(io.close){ io.open "scope54.lua"}
print(f:read())
end
I think this is enough readable and looks nice.
вт, 9 июл. 2019 г. в 02:54, Coda Highland <chighland@gmail.com>:
>
> Well YEAH, of course you can do it if you add a preprocessing phase. That's cheating. :P It's not really Lua anymore if you do that.
>
> /s/ Adam