|
|
||
|
Am 26.09.2018 um 17:46 schrieb Scott Morgan:
On 14/09/2018 20:57, Jim wrote:
Some sugar maybe but something along the lines of:
if item = find_something() then
item:do_stuff()
end
With `item` being local to the if scope, and not polluting the wider
block. So effectively it translates to this
begin
local item = find_something()
if item then
item:do_stuff()
end
end
Could probably do with it in while loops too.
Seems to flow with the for loop syntax, so not that wild an idea :)
Scott
Hmmm.To me this is to close to the = vs == discussion in Languages like C, JavaScript, etc.
It is for a reason that in Lua an assignment is not legal in an expression. What about: when( find_something() ):do_stuff()with when() being a function that returns the parameter or a table with a do_stuff method without effect?
local function when( this ) return this or { do_stuff = function() end } end
For arbitrary do_stuff()s metatable's __index is your friend...
--
Oliver