From cf031025fd1b4b8da0fa9a33958556aa35c3db92 Mon Sep 17 00:00:00 2001 From: rxi Date: Sat, 8 Mar 2014 20:21:44 +0000 Subject: [PATCH] Added lume.lambda() --- lume.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lume.lua b/lume.lua index 1e209b4..fd278e1 100644 --- a/lume.lua +++ b/lume.lua @@ -212,6 +212,14 @@ function lume.time(fn, ...) end +function lume.lambda(str) + local args, body = str:match([[^([%w,_ ]-)%->(.-)$]]) + assert(args and body, "bad string lambda") + local t = { "return function(", args, ")\nreturn ", body, "\nend" } + return lume.dostring(table.concat(t)) +end + + function lume.serialize(x) local f = { string = function(v) return string.format("%q", v) end, number = tostring, boolean = tostring }