lua-users home
lua-l archive

Re: Another option for closing variables

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


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

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