Re: Short form for defining a function (Was: try-catch ...)
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Short form for defining a function (Was: try-catch ...)
- From: Jonne Ransijn <yoyoyonny@...>
- Date: Wed, 1 Jun 2016 09:25:48 +0200
Something like
function fn(s)
local args, body = s:match "^%s(%b())(.+)$"
return (loadstring or load)("return function "..args.." return " ..body.." end")
end
print (fn "(a, b) a + b" (1, 2)) -- 3
Would work too, no need to overload operators.