lua-users home
lua-l archive

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


Chain symbol "!"
It should expand as follow:

function_name!expression --> function_name(expression)
sin!x -> sin(x)
fn!function() end -> fn(function() end)
f1!f2!f3!f4 -> f1(f2)(f3)(f4)

example:
-- function scope: https://pastebin.com/8u4xfbYm
scope!function(auto,defer)
    f=auto(io.close){ io.open "test.txt" }
    defer!function() print "atexit" end
    print(f:read())
end

Or may be short function definition "@"
@ body end          --> function() body end
@() body end          --> function() body end
@(args) body end    --> function(args) body end

And add function call with out brackets as for strings and tables:
fn(1)               --> fn(1)
fn "text"           --> fn("text")
fn{ x=1, y=2 }      --> fn({ x=1, y=2 })
fn @ body end       --> fn(function() body end)
fn@(args) body end --> fn(function(args)) body end)

Example:
scope@(auto,defer)
    f=auto(io.close){ io.open "test.txt" }
    defer@ print "atexit" end
    print(f:read())
end