Added lume.lambda()

This commit is contained in:
rxi 2014-03-08 20:21:44 +00:00
parent 4db5a6b683
commit cf031025fd

View File

@ -212,6 +212,14 @@ function lume.time(fn, ...)
end 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) function lume.serialize(x)
local f = { string = function(v) return string.format("%q", v) end, local f = { string = function(v) return string.format("%q", v) end,
number = tostring, boolean = tostring } number = tostring, boolean = tostring }