lua-lambda
Takes a string, returns a function for quick function definition.
Usage
The lambda format is as follows:
l"(args) expr"
Example:
local add_one = l"(x) x+1"
print(add_one(5)) --> 6
Why?
Because Lua needs more atomic modules which add functionality without creating a huge library. This module is supposed to be dead-simple to grab and start using in your project without adding anything extra. One of Lua's strengths is minimalism, and I think that it's ecosystem would do well to mirror that.
Would not recommend
This mod hacks syntactic sugar for "lambda functions" into Lua by simply loading and caching strings containing Lua code via the (global!)
l
function.Unfortunately, the way this is done has too many drawbacks to be viable:
l
comes from (and why it should be used).Just bite the bullet and instead of
l"(...) ..."
, writefunction(...) return ... end
.If you can't take Lua not having enough syntactic sugar for you anymore, find an established Lua preprocessor that works for you and roll with that.
Barely A Line
As a "mod", it's barely providing any functionality at all. Lua has a built in function called
loadstring
that does this exact thing. A quick peek under the hood, and that is, in fact, all you're doing. You're also caching the calls, which is helpful for performance, but overall, loadstring is heavy, and if you're using it in your projects, you're probably doing something wrong in the first place. Who is this for?